19

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?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Milos
  • 981
  • 3
  • 16
  • 41
  • Perhaps your `ssh.exe` is not compatible, see a list of compatible clients and how to install them [here](https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client) – Cr4xy Feb 06 '20 at 22:21

6 Answers6

36

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
Claywalker0929
  • 476
  • 4
  • 4
4

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.

Eleanor Holley
  • 691
  • 1
  • 7
  • 27
  • 1
    Are you sure this is the correct source link? It does not say anything about use of the local server. – bers Feb 19 '21 at 05:08
  • Hm... You're right about that. It's been a year, and I'm not sure whether I pasted the wrong link or if there was comment that got deleted or something. I'll have to search around a little and find a better link. – Eleanor Holley Feb 19 '21 at 16:31
3

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.

Milos
  • 981
  • 3
  • 16
  • 41
  • 2
    I'm having the same problem and I added the config info to the ProgramData location as you mentioned. I have a blank config file under my USER directory too. It still tries to use my Username. Not sure wtf is going on. Any additional steps you had to take here? – Craigfoo Oct 29 '19 at 16:14
  • Remove remote configuration from ssh_config file in ProgramData, and copy it to c:\Users\YOURUSERNAME\.ssh\config file – Milos Oct 31 '19 at 18:50
0

I tried the following steps as I use Windows 10:

  1. Install the Windows OpenSSH Client
  2. Install the Windows OpenSSH Server
  3. Run the VS Code as Administrator

and it works.

AleXelton
  • 767
  • 5
  • 27
chienkan
  • 67
  • 1
  • 5
0

The accepted answer will work. But for those that are like me, and use the right-click menu from the task bar in windows to open up either a recently used workspace or a pinned workspace, then you'll need to make sure to connect fresh instead, then remove your pinned workspace if you had one and add the new one back.

I have no idea why VSCode does this, but it makes having the username argument in the config file kind of useless.

Hope this helps.

KyleDev
  • 11
  • 1
  • 5
-2

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

Amir
  • 625
  • 1
  • 11
  • 26