Visual Studio Code Remote SSH uses Windows username instead of username in ssh_config - visual-studio-code

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

Related

Connect to Host with VSCode using the private key

I want to connect to a remote server, I know the username and hostname, and I also have the private_key.pem file. How can I connect to this virtual machine using VSCode?
I get this error with the solutions on the internet, and that's reasonable because I have not imported this private_key.pem file anywhere, and I do not know how.
Permission denied (publickey)
Thanks for your help.
I use windows, but the remote machine is ubuntu.
Thanks for asking the question.
You can add private key in ssh Open Configuration File of visual studios.
Please follow the below steps:
Open Vscode
Press F1 and search for Remote-SSH: Open Configuration File
Edit the file for adding new server and private
Host name-of-ssh-host-here
User your-user-name-on-host
HostName host-fqdn-or-ip-goes-here
IdentityFile C:\path\to\my\id_rsa.
IdentityFile specify the path of private file.For windows use double slash.
Please find the reference at https://code.visualstudio.com/docs/remote/ssh#_getting-started

bash: powershell: command not found

For a node project I will have to work on a remote server and for that I will use filzilla for file transfer and ssh for console.
I use Visual Studio Code, I installed a remote ssh extension,
I did the hostname and user configurations as well as secretkey,
because before that I had another error The process tried to write to a nonexistent pipe ,
which I finally solved but now after I start ssh and log in with the password in cmd from Visual Studio Code, I get this error bash: powershell: command not found.
I tried one day to search the internet for that error.
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration?WT.mc_id=-blog-scottha
https://learn.microsoft.com/en-us/windows/wsl/troubleshooting
I've talked to people who have more experience but within the time limit my advice could be, but I still couldn't solve the error, either it's something from windows or ssh or I don't know.
You are the first time I try to do this in general I used heroku or aws that had some facilities.
I changed host machine in the settings JSON file windows to linux
When you got the option to Select Linux, Windows or Mac did you make sure that you know exactly the type of server you are connecting to. Bcs if you choose the wrong one this error gets thrown.

VS Code ask for password repeatedly when opening different folder on same host

I have connected to a remote Ubuntu host from Windows using VS Code and using it for remote development. Often times I open different code repositories in VS Code but every time I have to open a different folder despite having the connection established the VS Code ask for password.
It seems that once we are commented to a remote host then successive opening of different folder from same host should not prompt for password.
Is there any setting I am missing or should do to resolve this or save password.
I'm assuming you're connecting to an ssh remote.
There are two ways to authenticate an ssh connection, via password and via public/private key. When using the latter you don't need to enter the password each time.
To use the public/private keys here's what you have to do:
You first need a pair (public/private) of ssh keys. On windows you can use ssh-keygen to generate them for you and put them in the default ssh config folder ( ~/.ssh/)
You then have to configure the remote server to allow your ssh key, you can do this in two ways:
with the ssh-copy-id command if available (I think on windows it's not there, but you can try)
by manually add your public key (~/.ssh/id_rsa.pub) to the.ssh/authorized_keys file on the host machine
Here's a link to know more about passwordless logins via ssh: https://www.redhat.com/sysadmin/passwordless-ssh
Open git bash on Windows
cd .ssh
ssh-copy-id -i id_ed25519.pub your-username#your-server

How to set a remote connection to a Vagrant container using "Visual Studio Code Remote - SSH"?

I'm exploring the new set extensions called VSCode Remote Pack and I want to connect to a Vagrant container using the Remote Container extension. Using a Windows 10 OS, how could I do that?
I tried the extension but it requests me to have Docker installed, what I suppose from that is that it only works for Docker containers. But I wonder if somebody have already managed to connect to a Vagrant box.
This are the docs from the extension: https://code.visualstudio.com/docs/remote/containers
VS Code Remote containers currently only support Docker (its implementation executes docker commands). Please open a feature request if you would like to see other tools supported.
As an alternative, you could try using Remote SSH to connect to vagrant containers. That should work but will require some extra container setup
Sorry for updating this so late.
The solution was pretty simple, as #MnZrk commented, what it needs to be done for setting up the connection is the following:
Run vagrant ssh-config > some-file.txt. This will generate a file with the configuration to run using SSH. Here an example of that file:
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Users/User/project/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
ForwardX11 yes
Notice that the host name is default, you could rename it to whatever you want so you could identify it more easily.
Copy the content of some-file.txt inside your SSH configuration file. This file could be edit directly from vscode by pressing F1 and writing Remote-SSH: Open Configuration File..., then you select the file you use for ssh configuration. After that file opens, just copy the content of some-file.txt there.
Finally, just press again F1 and type Remote-SSH: Connect to Host..., choose the connection with the host name default or the want you wrote in the first step, and that's all.

Connect Eclipse RSE with remote Linux server using public key attained from Amazon ec2

I want a easy way to save, copy and edit files on a remote server. I'm using Eclipse as an IDE, what could be better for these tasks than RSE(Remote System Exlporer) plugin for Eclipse. The thing is that I dont know how to make a connection using a public key. I have file that I downloaded from my Amazon account, *.pem. But I don't see any forms or inputs for this, when I try to connect to my remote Linux server. It is just User-id and password. I also tried to open the public key using the system's text editor and copy everything to my password field, but it didn't worked. Pls help me
this was baking my noodle for a while too. you put the keys in a folder not in the RSE config but in the whole of eclipse
check this: http://siteadmin.gforge.inria.fr/eclipse-ssh.html
Not mentioned (at least in explicitly) is the fact that RSE (and for what I've seen, Eclipse in general) only seems to work with 1024 bit keys https://bugs.eclipse.org/bugs/show_bug.cgi?id=404714
I also had issues, because my privatekey was 2048, but I added a new key to authorized hosts and then I could connect.
I added my local computer's ~/.ssh/id_rsa.pub to the remote /home/ec2-user/.ssh/authorized_keys.
Then just set the user to connect in RSE to ec2-user when connecting.
Someone asked for root login. It works too: update /root/.ssh/authorized_keys, and edit /etc/ssh/sshd_config to allow root login:
#PermitRootLogin forced-commands-only
PubkeyAuthentication yes
Then reload the sshd daemon: service sshd restart