errorous
errorous

Reputation: 1071

Visual Studio Code Remote SSH uses Windows username instead of username in ssh_config

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 [email protected] , 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?

Upvotes: 25

Views: 25429

Answers (6)

KyleDev
KyleDev

Reputation: 31

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.

Upvotes: 0

Amir
Amir

Reputation: 643

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

Upvotes: -3

Eleanor Holley
Eleanor Holley

Reputation: 798

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.

Upvotes: 4

Claywalker0929
Claywalker0929

Reputation: 546

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

Upvotes: 43

chienkan
chienkan

Reputation: 75

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.

Upvotes: -1

errorous
errorous

Reputation: 1071

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.

Upvotes: 3

Related Questions