I have VSCode with the extension remote-ssh installed. I connect to a remote host by username and IdentityFile.
To access certain files on the remote host, I have to switch users using su <user>. But when I switch users, I can only access the file in the terminal and not in the file explorer and therefore I'm unable to use the graphical editor of VSCode to edit my files.
You can modify your config file like this:
Host remote
....
RemoteCommand su otherUser
according to https://github.com/microsoft/vscode-remote-release/issues/690#issuecomment-993857961
but remember to manually add
"remote.SSH.useLocalServer": true,
"remote.SSH.enableRemoteCommand": true,
to your VSCode settings.json file,
and remember to test the command su otherUser in ssh terminal and make sure it doesn't ask for a password (which will not work with RemoteCommand)
For me, I use RemoteCommand sudo su otherUser and disable sudo password for my ssh user.
Took me a while to search answers and configure, now it works perfectly.
If you have any other questions, go to the issue and read the thread.
Related
I usually connect to remote computers through VS Code SSH. The settings (IP of the remote computer and public and private key pairs are properly set). The strange thing that is happening is that I can open any folder in the remote computer, but not the folder where the project is located (for example, I can also open the parent folder of the project).
It was working properly for years and now it has this type of problem.
Here, I report the output terminal:
[21:03:16.164] "remote.SSH.serverInstallPath": {}
[21:03:16.168] SSH Resolver called for host: PC000
[21:03:16.168] Setting up SSH remote "PC000"
[21:03:16.173] Using commit id "6261075646f044b98968d5000324gdhsdsjdd3b" and quality "stable" for server
[21:03:16.177] Install and start server if needed
[21:03:16.182] Checking ssh with "ssh -V"
[21:03:16.261] > OpenSSH_for_Wind
[21:03:16.262] > ows_8.1p1, LibreSSL 3.0.2
[21:03:16.273] Running script with connection command: ssh -T -D 64484 "PC000" bash
[21:03:16.275] Terminal shell path: C:\Windows\System32\cmd.exe
And after a while, it returns the timeout error.
I am putting the passphrase which it is requesting, then it is not able to connect to the folder.
Do anyone have some ideas?
I tried to open other folders with VS Code SSH connection and they are propery opened. I browsed with the command window to to the folder of the project and everything seem fine.
Did you try this option? "remote.SSH.useLocalServer": false, for more details, you can have a look the discussion here
Setting the terminal.integrated.inheritEnv option to true solved the problem
I have a weird problem and don't really know where it's coming from. I have machine A, B and C. I want to connect my VSCode to machine C with the remote-ssh extension for vscode, here's my config:
# Jump box
Host jump-box
HostName machineB
User myuser
# Target machine
Host target-box
HostName machineC
User myuser
ProxyCommand ssh -q -W %h:%p jump-box
The machine C is a weird server used by a lot of people, when I try to connect, the connection to machine B is fine but then, the extension tries to ssh -D -T some5XXXXport machineC bash from B.
The last command passes fine, and I have tested it manually, however the bash at the end makes it run the root bash or something, because I lose my home directory and get an admin one.
So in consequence, the extension fails because it tries to mkdir /some/admin/home/.vscode-server/bin/somecommithash: Permission Denied. My ~doesn't belong to me anymore when the ssh command is bash.
Any ideas how to overwrite or even hack the command?
Do you know why when you ssh address bash it breaks everything?
I also don't think the B->C ssh connection is picking any ~/.bash_profile, ~/.bashrc nor ~/.profile from machine C, perhaps because ~ points to another home.
Solved it. Added all what I need directly in the extension.js.
I was trying to connect my VSCode to remote machine using remote-ssh plugin. I added the host name, port and user in the .ssh config file. The problem I had was that there was no password prompt appeared hence I couldn't enter my password and the VSCode remote-ssh connection failed. I tested the connection using ssh in a terminal and it worked, which means there was no problem with the connection itself. Thanks!
Try to edit settings.json file. Add:
"remote.SSH.showLoginTerminal": true,
"remote.SSH.useLocalServer": false,
"remote.SSH.configFile": <path_to_ssh_config>
I have a remote ssh server on which I want to do remote developement.
My public key is added to the authorized keys on the server and my private key is passphrase protected.
I added the remote host as described here using ssh user#host -i ~/.ssh/key
But whenever I try to open a new VSCode window on the remote host it fails and I see in the log that the connection timed out, which is expected because I don't get asked for my private-key passphrase.
I read this post on remote development using ssh and I searched on google but couldn't find any hints to what I could do to enable/enter ssh-key passphrase while connecting to remote host.
I know I can connect to the remote using a non-passphrase-protected key but I'm not asking for that, I want to know if it's possible to connect to a remote host from VSCode using a passphrase protected key.
If your key is not the default one, that means you need a ~/.ssh/config entry in which you specify your SSH connection parameters:
Host myserver
Hostname host
User user
IdentityFile ~/.ssh/key
The Visual Studio Code Remote Development will automatically read the config file, and when you ask for opening an SSH session, you will see "myserver" entry: if you select it, the SSH session opened will use ~/.ssh/key, the right private key.
Then, as long as your ssh-agent is enabled, and you have entered at least once your passphrase (through a manual ssh myserver), VSCode will use the same agent to get the passphrase when it will need it.
This is what solved it for me, your issue could be different.
In VScode, choose command: Remote-SSH: Open SSH Configuration File...
Choose the location that is offered to you (or create a config file without extension to desired location), for example:
C:\Users\[USER_NAME]\.ssh\config. Make sure you have appropriate permissions.
Prepare you configuration file, for example
Host Custom_Name
HostName example.server.com
User your_user_name
IdentityFile C:\Users\[USER_NAME]\Documents\MobaXterm\home\.ssh\id_rsa
(or wherever you have the private key)
Finally add a custom path to your configuration file. This is what I lacked for long time
{
// add custom configuration file path
"remote.SSH.configFile": "C:\\Users\\[USER_NAME]\\.ssh\\config",
// Other settings
// omit comma after *config"* if that is your last setting
}
Now it should ask for passphrase as opposed to password.
P.S. Here is a lot of useful information with the setup, especially with the keys that I have omitted for brevity.
I'm using Visual Studio Code on Windows 7, along with Microsoft's Remote SSH extension. I added new remote host, and saved configuration in ssh_config file.
When I open that file, everything looks ok, both User and Host values. However, when extension asks me for a password, I can see that it doesn't use myuser#myremotehost.com , values that are written in ssh_config files, instead it uses proper host but it also uses my windows username instead of the username I set in ssh_config file.
Any solutions to that?
I found that including the username in the Host definition of the .ssh config file fixed it for me.
Edit the contents of C:/Users/me/.ssh/config
from:
Host bar
User foo
HostName bar
ForwardAgent yes
to:
Host foo#bar
User foo
HostName bar
ForwardAgent yes
I had the same problem, and what fixed it for me was disabling remote.SSH.useLocalServer in VS Code's settings.
Source: https://github.com/microsoft/vscode-remote-release/issues/2512
Edit: fix link.
I found the problem. When using Command Palette and running Remote-SSH: Connect to host, you can add your host, and then save it for future use. Now, when saving config, it will ask you which file do you want to save your configuration to, and I was presented with 2 options:
ssh_config(which is in ProgramData)
config(which is in Windows/Users/MYUSER/.ssh/)
Now, I first tried latter, but it couldn't find the file, so I went with former, ie ssh_config. That's why I had this problem.
To fix it, I went to Windows/Users/MYUSER/.ssh/ and created a blank file there. After that, I added new host, saved it to newly created config file, and, voila, everything works as expected.
I tried the following steps as I use Windows 10:
Install the Windows OpenSSH Client
Install the Windows OpenSSH Server
Run the VS Code as Administrator
and it works.
what I have done was this:
1- Add new host : ssh user_name#IP_Adrress
2- Select connect to host and it worked like a charm