I've already setup the ssh key, but VSCode keeps asking for password
Solution 1
It was a problem with the config file.
The VSCode needs the "absolute" path.
In case of MacOS, ssh-copy-id
seems to only copy the absolute path relative to the user.
In other words, it omits "/Users/username
" before "/.ssh
".
Adding "/Users/username
" in the IdentityFile
attribute in .ssh/config
solved the problem.
Solution 2
Check if this microsoft/vscode-remote-release
issue 2518 applies:
You should be able to get out of this state by deleting the file (on the remote server side, as sudo root) in the log,
/home/#####/.vscode-server/bin/78a4c91400152c0f27ba4d363eb56d2835f9903a/vscode-remote-lock.#####.78a4c91400152c0f27ba4d363eb56d2835f9903a
(withunlink
) or running the command "Kill VS Code Server on Host..."If it happens again, you might try setting
remote.SSH.useFlock
.
The exact command to run in the command palette (View->Command Palette) is:
Remote-SSH: Kill VS Code Server on Host...
Also:
In my case, deleting entire
~/.vscode-server
directory after connecting to the container through ssh using terminal worked.
(Deleting only~/.vscode-server/bin
did not work.)
The OP sukrama confirms in the comments having solved the issue
It was a problem with ssh key path in config file.
Solution 3
Here's a quick and handy fix: You do not have to delete the entire .vscode-server folder each time! The problem seems to be a file named 'vscode-remote-lock...'. It can be located inside a folder in ~/.vscode-server/bin/ . That file gets created at each ssh login through vscode. Run the following script on the remote host. It deletes that file whenever it is created:
while true
do
if ls /home/<your-username>/.vscode-server/bin/*/vscode-remote-lock.<your-username>.* 1> /dev/null 2>&1; then
find /home/<your-username>/.vscode-server/bin/*/ -name vscode-remote-lock.<your-username>.* -delete
echo "Killed the troublemaker! ^_^"
fi
done
The file names and the folder names may differ from machine to machine. So find the names on your machine and paste them in the script. Then run the script and you're good to go.
Solution 4
VSCode in my Windows machine was asking for password even with my key correctly configured (it works from the terminal).
My problem was that VSCode was choosing a wrong user. I was using a host configured in my ssh config file, and VSCode was setting the user as DOMAIN\user
instead of user
. I solved it configuring the correct user in my .ssh/config file:
Host dados
HostName vrt1234
User xxxxx
Solution 5
I had to use UseKeychain yes
in my ~/.ssh/config
file.
The config file looks like this:
Host server.tld
HostName server.tld
User user
UseKeychain yes
IdentityFile ~/.ssh/key
You have to enter ssh-add -K ~/.ssh/key
to add your passphrase to KeyChain first.
sukrama
Updated on July 09, 2022Comments
-
sukrama almost 2 years
I'm using a macbook(MacOS) to connect to a remote Ubuntu server. I copied the public ssh key to the server using
ssh-copy-id
and checked that the ssh key works on the terminal. When I dossh [email protected]
, connection is made without asking for password). However, when I try to connect to the server through Visual Studio Code, VSCode keeps asking for password. Is there a way to fix this?Thanks in advance!
-
sukrama over 3 yearsI tried deleting ~/.vscode-server and reinstalling .vscode-server (by opening the remote server on VSCode again). It did not work :( Thanks for the answer though.
-
VonC over 3 years@sukrama OK. How about the other suggestions on that issue?
remote.SSH.useFlock
, ` Kill VS Code Server on Host...`, ... -
sukrama over 3 years'Kill VS Code Server on Host' did not work. Also, setting remote.SSH.useFlock made the situation worse (VSCode kept asking for password without connecting to server).
-
VonC over 3 years@sukrama Is your key passphrase-protected?
-
sukrama over 3 yearsNo it's not passphrase-protected. I did solve this problem though. It was a problem with ssh key path in config file.
-
VonC over 3 years@sukrama Great! Well done. I have updated the answer accordingly.
-
Jsl over 3 yearsI had the same problem on Windows and the solution was related to this: superuser.com/questions/1296024/…
-
Taaam about 2 yearsI had a non-standard key name on Mac OS. Running
ssh-add /path/to/private/key
on the local machine fixed it.