000
000

Reputation: 1021

VS Code Remote SSH Connection not working

Im trying to setup vscode with the remote developement extensions on a second pc. While it works on my main one it doesnt on the second one. Tried reinstalling vscode, extensions and using older versions but nothing works.

When trying to connect it cancels after chosing the os. So I cant even type in the password. I set it up in the exact same way as with the other pc.

Any ideas?

[20:32:53.595] [email protected]
[20:32:53.595] win32 x64
[20:32:53.596] SSH Resolver called for "ssh-remote+ssh.blabla", attempt 1
[20:32:53.597] SSH Resolver called for host: ssh.blabla
[20:32:53.597] Setting up SSH remote "ssh.blabla"
[20:32:53.610] Using commit id "58bb7b2331731bf72587010e943852e13e6fd3cf" and quality "stable" for server
[20:32:53.612] Install and start server if needed
[20:32:54.639] Checking ssh with "ssh -V"
[20:32:54.686] > OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5

[20:32:54.691] Running script with connection command: ssh -T -D 52819 ssh.blabla bash
[20:32:54.694] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[20:32:54.758] >
]0;C:\WINDOWS\System32\cmd.exe
[20:32:54.758] Got some output, clearing connection timeout
[20:32:54.785] >
[20:32:55.045] > root@blabla's password: 
[20:32:55.045] Showing password prompt
[20:32:57.596] "install" terminal command done
[20:32:57.597] Install terminal quit with output: root@blabla's password: 
[20:32:57.597] Received install output: root@blabla's password: 
[20:32:57.598] Stopped parsing output early. Remaining text: root@blabla's password:
[20:32:57.598] Failed to parse remote port from server output
[20:32:57.603] Resolver error: Error: 
    at Function.Create (c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:1:130564)
    at Object.t.handleInstallOutput (c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:1:127671)
    at I (c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:106775)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:104774
    at async Object.t.withShowDetailsEvent (c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:109845)
    at async Object.t.resolve (c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:107960)
    at async c:\Users\Manuel.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:141955
[20:32:57.606] ------




[20:32:59.376] Password dialog canceled
[20:32:59.376] "install" terminal command canceled```

Upvotes: 91

Views: 336301

Answers (26)

Mike Casan Ballester
Mike Casan Ballester

Reputation: 1770

As suggested by the previous answers, it may come from a wrong port. In VSCode, I had to add port 22 in my .ssh config file. For example,

Host 54.1.1.1.1
HostName 54.1.1.1.1
User mynameis
AddKeysToAgent yes
UseKeychain yes
IdentityFile "C:/Users/TEST/.ssh/id_rsa"
Port 22

NB: If you use another port, please modify accordingly.

Upvotes: 1

Sabito
Sabito

Reputation: 5085

You can try turning off Local Server Download inside the user settings.

  1. Press F1
  2. Type "Open user settings"
  3. Search "Local Server Download" and turn it off and close the settings
  4. Retry connecting

Upvotes: 1

Juxing mao
Juxing mao

Reputation: 1

The problem I encountered is that vscode remote ssh requires repeatedly entering the password, but it cannot connect correctly.

The solution is to remove the ssh prefix from the entered ssh address. e.g.

ssh [email protected] --error

[email protected] --ok

Upvotes: 0

  1. Kill and uninstall the VS Code Server on your remote host. This is done via Strg + Shift + P, then selecting "Remote-SSH: Kill VS Code Server on Host", "Uninstall VS Code Server from Host".
  2. Clear your SSH configuration: Strg + Shift + P + Remote-SSH: Open SSH Configuration File.
  3. In your User Settings in the Extensions section, enable the option Remote.SSH: Lockfiles In Tmp

Upvotes: 3

Sachin Sharma
Sachin Sharma

Reputation: 89

There could be multiple causes for this. In my case TCP Forwarding was disable in remote Rocky Linux 8 SSH Host.

debug1: server_request_direct_tcpip: originator 127.0.0.1 port 59196, target 127.0.0.1 port 41455 refused local port forward: originator 127.0.0.1 port 59196, target 127.0.0.1 port 41455

Changing AllowTcpForwarding no to yes in /etc/ssh/sshd_config and restart sshd resolve the problem.

-Sachin

Upvotes: 0

Chiang Lucca
Chiang Lucca

Reputation: 21

In my case, it seems that the ~ directory is full so that I cannot connect through vscode but can connect through CLI. So I recommend to change the server install path according to How to change vscode-server directory.

Upvotes: 1

meupul
meupul

Reputation: 85

I tried below steps in host terminal and issue was resolved.

cd .vscode-server/bin/

cd b3e4e68a0bc097f0ae7907b217c1119af9e03435/ (this folder name can be different for you)

tar -zxvf vscode-server.tar.gz

mv vscode-server-linux-x64/* .

rm -rf vscode-server-linux-x64/ vscode-server.tar.gz

touch 0

Upvotes: 2

Jeph
Jeph

Reputation: 21

Stumbled upon this situation today. Switching to Pre-Release Version for my Remote-SSH extension worked.

Upvotes: 1

Thảo Dương
Thảo Dương

Reputation: 359

On the remote server, you run this command below. After that, the VScode window should be reloaded and you connect to the remote via SSH again.

rm -rf $HOME/.vscode-server

Upvotes: 5

John Cena
John Cena

Reputation: 11

I had this exact same issue. Nothing seemed to work (uninstall extension, uninstall VSCode, delete a bunch of cache folders, etc). SSH through terminal was working, but not on VSCode.

After working a bit on the terminal I got an error for no empty space, so deleting a bunch of files on the server was the solution for me, it was nothing related to VSCode.

Upvotes: 1

Stéphane Perras
Stéphane Perras

Reputation: 71

For me the issue was that ~/.bashrc on my remote server contained an erroneous 'exit' that was supposed to execute only during non-interactive sessions, to avoid terminal output during scp commands.

I had implemented that solution successfully on another server though. Not sure why it broke the second one. Both are CentOS 7, but different patch levels.

Removed the exit statement and now remote-ssh works great.

# .bashrc
# ...
if [[ $- == *i* ]]
then
    :
else
    exit # <--- Culprit
fi
# Other stuff useful only for interactive shells.

I had found this solution here: https://unix.stackexchange.com/questions/26676/how-to-check-if-a-shell-is-login-interactive-batch but now starting to doubt it?

Upvotes: 0

JERMY
JERMY

Reputation: 11

The previous answers may not be sufficient if your SSH host server lacks SSD capacity.

If you have tried all the above solutions and they have not worked for you, check if your host server has enough capacity to accommodate ./vscode-server. In my case, after deleting large files from my server, I was able to effectively use SSH.

Upvotes: 1

Raphael Fernandes
Raphael Fernandes

Reputation: 861

For me, turned out it was a issue with the .pem file

After testing all solutions above, I figured out the .shh/config file was using IdentityFile without the complete path. So, I added the complete path on the config file such as:

Host your-alias
  HostName ec2-xx-yy-zz.compute-1.amazonaws.com
  IdentityFile C:\Users\your-user\folder\ec2-pem-file.pem
  User ubuntu

When prompting the error "Could not establish connection", I checked on the log (VS Code Output tab) the "no such identity" message just before the "[20:32:57.603] Resolver error: Error: " message.

Upvotes: 0

Karlik_B
Karlik_B

Reputation: 309

In my case (Rocky9 minimal install) the "tar" utility was not installed. After I installed tar (dnf install tar) it starts working. The error message produces by installer is quite misleading.

Upvotes: 1

Charles Bisbee
Charles Bisbee

Reputation: 391

I had previously tried to get vs code working on the remote machine. I deleted both the home/.vscode-server AND the .vscode directories. These dirs were NOT deleted by uninstalling vs code on the remote machine

This also might help. I set the debug level by adding "logLevel DEBUG3" on the .ssh config file in VSCode

The logs are were very hard for me to find and are not named as the terminal output says they are (long hex string .log). I finally found it them in C:\Users<user>\AppData\Roaming\Code\logs they can be found by using command Developer:Open logs folder. There you will find subfolders named windowx. Under the window where the error occurred (you just have to look in by time) find exthot/output_logging_xxxxx/remote - ssh.log.

Upvotes: 0

M&#225;rio Prada
M&#225;rio Prada

Reputation: 2168

In my case I needed to remove arm_64bit=1 from config.txt (/boot/config.txt).

Upvotes: 0

To add what @cagriyonca mentioned, delete the ip that is in the file located in Windows in:

C:\Users\<YourUsername>\.ssh\known_hosts

This worked for me

Upvotes: 6

Mohamed Allal
Mohamed Allal

Reputation: 20930

Depending on the system you are in, when you first try to connect, a vscode-server will be set up and configured on your server.

In linux that can be in /Home/<user>/.vscode-server

If you are on windows, check what that is.

The first solution is to try the extension command: Remote-SSH: kill VS Code Server on Host

Open the command pallet (CTRL + SHIFT + P or COMMAND + SHIFT + P (mac) ).

And type Remote kill :

enter image description here

Then try to connect again! (That will kill the server on the host! Which will make it start again on the next try)

If that doesn't work, and things are still failing:

Delete, rm

Then a good solution that can work is: to connect to your server through terminal (vscode terminal, gnome-terminal, whatever). Then go and remove /Home/<user>/.vscode-server

Try to connect after that. At the attempt the server will be re-installed completely anew, chances are it will work. (I did that and it worked for me, so whatever that was going wrong on the vscode-server: just start all over)

But again: you will lose things, config, meta data, etc. (because you start anew).

Update:

As stated by @natevw in the comments:

I found that removing only the .vscode-server/bin subfolder helped straighten things out and afaict kept my data/settings.

Removing only vscode-server/bin seems to work well, and the config, metadata, etc. remains untouched.

Upvotes: 130

Srijith Sreekumar
Srijith Sreekumar

Reputation: 51

Issue: while trying to ssh connect to Linux(remote machine) using vscode.

Solution: remove/delete the bin folder inside .vscode-server and then reconnect to the remote machine

In remote server:

remote_name:~$ rm -rf ~/.vscode-server/bin

*reconnect to remote machine* 

Upvotes: 5

I ran into the same issue, it got fixed when I updated the path of the IdentityFile from 'ssh_key' to '~/.ssh/ssh_key' (the entire path I mean) so that the VS code could recognize it.

Upvotes: 0

Peg-Noobi
Peg-Noobi

Reputation: 21

It turns out that my fish was a obstacle for vscode server.

Then I tried

chsh -s /bin/bash

And works fine.

Upvotes: 2

ocampeau
ocampeau

Reputation: 317

In case all the above fails, here's how I fixed my issue.

First, I was able to SSH into my remote server (Ubuntu 22.04, Raspberry Pi 4, arm64) using a simple bash terminal. So I logged in using my terminal (macOS), and I went to

cd $HOME/.vscode-server/bin/WHATEVER-HASH-YOU-HAVE/

In this directory, there is a file named server.sh. I tried running this script, and I got the following error:

./node: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory

The issue was clear: there was a missing shared library on my system. Either Node.js now requires that or the new version of the SSH-Remote extension; I don't know. I did not spent the time to dig into those specifics.

But to fix that, I simply did:

sudo apt-get install libatomic1

That installed the missing shared library.

After that, I delete $HOME/.vscode-server:

rm -rf $HOME/.vscode-server

and tried again connecting using VSCode. It worked!

Hope this can help someone like me, for whom all other options failed.

Upvotes: 8

Sreekant Shenoy
Sreekant Shenoy

Reputation: 1640

One way worked for me is, by adding this line in the vscode settings (JSON) file.

"remote.SSH.useLocalServer": false

VSCode settings

Upvotes: 32

Creeki
Creeki

Reputation: 304

I met the same problem. After I did these steps, it works:

on the remote server:

rm -rf ~/.vscode-server  
rm -rf ~/.vscode

On the local VS code:

reinstall remote-ssh

Upvotes: 21

Andres Aya
Andres Aya

Reputation: 74

I worked adding \\ in the path of the .config

I share the steps

  • Go to .config settings

  • select configuration

  • add double \\

Upvotes: 0

ElevenZ
ElevenZ

Reputation: 431

I downgrade Remote-SSH plugin to 0.51.0, rm -rf $HOME/.vscode-server on the remote machine. Connect again, VSCode will download and install a new .vscode-server. Then upgrade Remote-SSH plugin, everything works.

Upvotes: 31

Related Questions