code tunnel -h doesn't list options and doesn't open a tunnel to WSL - visual-studio-code

I'm following the guide
and I am noticing that code tunnel -h in a ubuntu terminal window just launches the code UI.
Using the command palette to get the URI results in a tunnel to my Windows version of VSCode rather than the WSL:ubuntu (which is the one I care about)
How do I fix this?

It appears that, for now, you need to manually install the CLI in WSL in order for it to work. The downloads can be found here. Since you are on Windows, I would recommend the x64 CLI download. When you extract the tar.gz file, you will get a file named code. I would recommend moving it to your home directory for ease. To open the tunnel, run ./code tunnel (from wherever you put the code file) to force the new CLI. If you use code tunnel it will still use the Windows version.
Source: https://github.com/microsoft/vscode/issues/171196

Related

Open remote folder in local VSCode like "code ."in WSL2

Is it possible to use $ code . in remote server ssh session just like I do in WSL when I want to open current working directory in remote host in local VSCode?
ADDENDUM:
In local WSL, I can issue $ code . and that would open the current directory in VSCode which is installed on Windows 10.
I am trying to get the same behavior in another remote Linux which I have connected to remotely through ssh. So when I am on that remote machine and issue $ code . it would open that directory in VSCode installed on local window.
I don't imagine this would be simple to do but I certainly share your desire to want to be able to do it.
Problem
Here's an explanation of why it doesn't work, and a hint at why it's probably quite a difficult thing to setup:
The way code . works from WSL (or PowerShell) is by launching VS Code in the given directory (passed as the first argument as the dot).
When you run code from WSL it uses wslpath to convert the path to the Windows accessible one, and the WSL magic executes code.exe (which is, after all, a Windows binary and not a Linux one) in Windows with the WSL path (\\wsl$...);
Theory
In order for this to work you need to achieve three things:
Work out which remote you're connected to, and be able to pass that information to vscode
Execute code.exe on your local machine, but from your remote terminal
Ideas
A couple of ideas you could play with if you wanted to try and implement it:
A script on your remote could output a vscode:// URL for you to click (or find a way to get your client to auto-load it).
You might be able to use a forwarded port in your SSH session to contact something on your PC (perhaps custom made, or maybe with Windows RDP or a telnet/ssh server perhaps?)
Perhaps mount a local directory as part of your SSH connection (I don't know all the edges of SSH but it does a lot of cool stuff! SCP might help?) and be able to execute/trigger things?
Just some musings! It's not something I need enough to put any effort into it, but I came across your question looking for something else and found it interesting. Hope that's helpful to anybody, any thoughts/feedback is welcome!

Is it possible to open VSCode from Windows terminal while SSH'ed into a virtual machine?

I'm working on some tutorials and trying to do something, but no idea if it can be done. I am using windows terminal in Windows 10. I have an Ubuntu virtual machine running.
I'd like to:
Open Windows terminal
SSH into the Linux Virtual Machine
Type in the code . command and have it open a version of VS Code on my Windows PC that is working on the folder in the Ubuntu VM.
I tried install code locally and on the command line in the other machine, but it doesn't work. I am sure there are other ways to do this but wanted to explain how I was doing it to show I at least tried something. Thanks for your help.
It's not quite as easy as the code . technique you get with the Remote - WSL extension, but Microsoft also provides a Remote - SSH extension that can be used to directly access the remote machine (without requiring WSL in-the-middle).
Once the Remote - SSH extension is installed in VSCode (and it may have already been installed in an extension pack with the WSL extension), and you have installed an OpenSSH client in Windows, there are several ways to access files on the remote host through SSH:
From the Command Palette (Ctrl+Shift+P), type Remote SSH to filter on those commands. From Connect to Host, you can add a new configuration, etc.
From the Activity Bar on the left, select the Remote Explorer icon, then in the dropdown at the top, select SSH Targets. You can add hosts here through the + icon.
There's a direct shortcut to Open a Remote Window at the far left of the status bar. This will give you similar filter options on the Command Palette as above.
Once a host is configured, you can browse it just as (well, almost) if it were local, open files, edit, etc. The one thing you can't do (as far as I'm aware) is any type of sudo/su editing on files that you don't have permissions to directly.
Full details in the VSCode docs here.

Vscode (code.exe) command line arguments to immediately open a remote workspace folder over SSH

If I want to open a workspace on a regular local folder under C:\ I can just execute the command:
code.exe C:\the-local-workspace-folder
Is there any equivalent command for opening remote SSH workspaces?
I want to be able to use my keyboard launcher to open them, rather than needing to open them the fiddly way in the internal menus inside vscode.
So I need a regular system command to be able to do this.
I've looked through the command line arguments here: https://code.visualstudio.com/docs/editor/command-line - but can't find anything about remote workspaces at all.
I've also tried commands like:
code.exe username#hostname.example.com:/workspace-folder
code.exe username#hostname.example.com/workspace-folder
...but they don't work for this.
This looks like a recent fix, according to the issue tracking here. I've tested with my own settings, and this works:
"C:\Users\myusername\AppData\Local\Programs\Microsoft VS Code\Code.exe" \
--remote ssh-remote+myubuntumachine /home/myusername/myprojectdirectory
The myubuntumachine should be the name given in the Host myubuntumachine in the SSH config file on CTRL+SHIFT+P/Remote SSH: Open Configuration File...
(Actually, on my machine I don't have the machine name, but some sort of hash value, although either works.)
VSCode 1.63 (Nov. 2021) adds the option -n (issue 137529), to make sure a new window is opened for remote CLI:
The following options got added to the remote CLI:
-n to open a new window of the same remote as the current window
-n --remote=wsl+ubuntu to open a new window of a different remote
-n --remote=local to open a new local window
To get started, you need to:
Install an OpenSSH compatible SSH client if one is not already present.
Install Visual Studio Code or Visual Studio Code Insiders.
Install the Remote Development extension pack.
Read more : https://code.visualstudio.com/docs/remote/ssh
Installations extension :
code.exe --install-extension ms-vscode-remote.remote-ssh
Follow the step-by-step tutorial or if you have a simple SSH host setup, connect to it as follows:
Press F1 and run the Remote-SSH: Open SSH Host... command. Enter
your user and host/IP in the following format in the input box that
appears and press enter: user#host-or-ip or
user#domain#host-or-ip If prompted, enter your password (but we suggest setting up key based authentication). After you are connected,
use File > Open Folder to open a folder on the host.
You can press F1 to bring up the Command Palette and type in Remote-SSH for a full list of available commands.
command list
You can change the location by launching VS Code with the --extensions-dir command-line option.
Where are extensions installed?#
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:
Windows %USERPROFILE%.vscode\extensions
Linux ~/.vscode/extensions
macOS ~/.vscode/extensions
To run remote ssh and open the folder in command-line :
code.exe --remote ssh-remote+root#server.com <your-directory>

How do I open files on server in a text editor from the command line?

I'm sorry if this seems like beyond a beginner question, but I mean this seriously. I'm moving around my ubuntu server via the command line, trying to open a file called 'authorized_keys'. I tried: root#ubuntu: open -a atom authorized_keys only to learn this open -a command does not work in this ubuntu environment. I can download the files to my machine via sftp and open them, but is that the only way? Besides using nano/vim?
The tutorial I'm watching on deployment shows this guy using MobaXTerm, a windows product that allows both sftp and the command line to be present. So he is just clicking on the files on his server and they are opening. However, I am on mac, and only using the command line. Thanks for any help. I am also not sure If I tagged this question properly, feel free to move it.
Just read all of this and realized that I it would make sense if downloading and reuploading the file via sftp would be the only way.

Is there an Atom package for a SSH client on a tab?

I am using GitHub´s Atom text editor.
I installed Atom on my Windows 10 computer. I edit code and sync it to a remote Ubuntu Server using Atom´s remote-sync package. This is being done via SSH.
I am developing a Django project and most of the times I need to restart Apache so that the Python code gets compiled in the remote server.
I want to know if there is a package that I can use to access remotely to my linux server via SSH and run bash commands. Preferably one that can be loaded on a tab.
I tried term, term2, term3, terminal but all of them are not working. I get errors on pty.js when trying to install.
One way to accomplish this is to use shellinabox and use a web view package to access the webpage.