Connecting to remote linux server with VSCode through WSL - File location issue? - visual-studio-code

When attempting to use VS Code / WSL to remote into a linux server hosted as a Digital Ocean droplet, we're getting this error:
[17:38:24.258] Log Level: 2
[17:38:24.260] remote-ssh#0.63.0
[17:38:24.260] win32 x64
[17:38:24.262] SSH Resolver called for "ssh-remote+100.100.10.100", attempt 1
[17:38:24.263] "remote.SSH.useLocalServer": false
[17:38:24.263] "remote.SSH.showLoginTerminal": false
[17:38:24.263] "remote.SSH.remotePlatform": {"$remote_server_name":"linux"}
[17:38:24.264] "remote.SSH.sshPath": undefined
[17:38:24.264] "remote.SSH.sshConfigurationFile": undefined
[17:38:24.264] "remote.SSH.useFlock": true
[17:38:24.265] "remote.SSH.lockfilesInTmp": false
[17:38:24.265] "remote.SSH.localServerDownload": auto
[17:38:24.265] "remote.SSH.remoteServerListenOnSocket": false
[17:38:24.265] "remote.SSH.showLoginTerminal": false
[17:38:24.266] SSH Resolver called for host: 100.100.10.100
[17:38:24.266] Setting up SSH remote "100.100.10.100"
[17:38:24.278] Using commit id "ea3859d4ba2f3e577a159bc91e3074c5d8c0523" and quality "stable" for server
[17:38:24.285] Install and start server if needed
[17:38:25.556] Checking ssh with "ssh -V"
[17:38:25.713] > OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
[17:38:25.726] Running script with connection command: ssh -T -D 53538 "100.100.10.100" bash
[17:38:25.735] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[17:38:26.931] > no such identity: /home/user/.ssh/id_rsa: No such file or directory
> ]0;C:\WINDOWS\System32\cmd.exe
[17:38:26.933] Got some output, clearing connection timeout
[17:38:26.940] > root#100.100.10.100: Permission denied (publickey).
> The process tried to write to a nonexistent pipe.
As far as I can see, the issue lies with
[17:38:26.931] > no such identity: /home/user/.ssh/id_rsa: No such file or directory
However
ssh -vv root#100.100.10.100 -i /home/user/.ssh/id_rsa
Successfully connects in the debug and server is accessed
debug1: Authentication succeeded (publickey).
So this must be some issue with specifying the location of id_rsa in the config file for VS Code.
Host 100.100.10.100
HostName 100.100.10.100
User root
ForwardAgent yes
IdentityFile /home/autosermo/.ssh/id_rsa
We have tried everything we can think of for the value of IdentityFile (...~/.ssh/id_rsa etc) but cannot nail it down.
What are the other possible locations / what path should be provided to IdentityFile here?
Thank you

WSL is a bit of a red-herring here. When you are using the "Remote - SSH" extension in VSCode, you aren't going through WSL at all. As you can see from this line in the output ...
[17:38:25.713] > OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
... It's using OpenSSH for Windows.
The location for your private key in OpenSSH should be %userprofile%/.ssh (so something like C:\Users\username\.ssh). Try placing it there. Also try executing your ssh command from PowerShell or cmd rather than WSL, since that's the one being used by VSCode.

Related

VScode Remote SSH: Terminal exited with output 1 when connecting to known host

Until yesterday I was able to connect without any problems to the remote host using the remote ssh extension.
Today, before there was any prompt to enter my password, I got an error popup Visual Studio Code: Could not establish connection to "lxplus.cern.ch".
Also, there was this vscode notification
The terminal process "C:\WINDOWS\System32\cmd.exe /c (type "C:\Users\George\AppData\Local\Temp\vscode-linux-multi-line-command-lxplus.cern.ch-916464892.sh" | ssh -T -D 53187 "lxplus.cern.ch" bash) & exit /b 0" terminated with exit code: 1.
Also, here is the SSH output:
[14:56:29.907] Log Level: 2
[14:56:29.912] remote-ssh#0.94.0
[14:56:29.913] win32 x64
[14:56:29.987] SSH Resolver called for "ssh-remote+lxplus.cern.ch", attempt 1
[14:56:29.987] "remote.SSH.useLocalServer": false
[14:56:29.988] "remote.SSH.showLoginTerminal": false
[14:56:29.988] "remote.SSH.remotePlatform": {"lxplus.cern.ch":"linux","raspberrypi.local":"linux"}
[14:56:29.988] "remote.SSH.path": undefined
[14:56:29.988] "remote.SSH.configFile": undefined
[14:56:29.989] "remote.SSH.useFlock": true
[14:56:29.989] "remote.SSH.lockfilesInTmp": false
[14:56:29.989] "remote.SSH.localServerDownload": auto
[14:56:29.989] "remote.SSH.remoteServerListenOnSocket": false
[14:56:29.989] "remote.SSH.showLoginTerminal": false
[14:56:29.990] "remote.SSH.defaultExtensions": []
[14:56:29.990] "remote.SSH.loglevel": 2
[14:56:29.990] "remote.SSH.enableDynamicForwarding": true
[14:56:29.991] "remote.SSH.enableRemoteCommand": false
[14:56:29.991] "remote.SSH.serverPickPortsFromRange": {}
[14:56:29.991] "remote.SSH.serverInstallPath": {}
[14:56:29.996] SSH Resolver called for host: lxplus.cern.ch
[14:56:29.996] Setting up SSH remote "lxplus.cern.ch"
[14:56:30.002] Using commit id "1ad8d514439d5077d2b0b7ee64d2ce82a9308e5a" and quality "stable" for server
[14:56:30.007] Install and start server if needed
[14:56:30.010] Checking ssh with "ssh -V"
[14:56:30.056] > OpenSSH_for_Windows_8.1p1, LibreS
[14:56:30.057] > SL 3.0.2
[14:56:30.061] Running script with connection command: ssh -T -D 53187 "lxplus.cern.ch" bash
[14:56:30.064] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[14:56:30.516] > & was unexpected at this time.
> ]0;C:\WINDOWS\System32\cmd.exe
[14:56:30.516] Got some output, clearing connection timeout
[14:56:31.716] "install" terminal command done
[14:56:31.717] Install terminal quit with output: ]0;C:\WINDOWS\System32\cmd.exe
[14:56:31.717] Received install output: ]0;C:\WINDOWS\System32\cmd.exe
[14:56:31.718] Failed to parse remote port from server output
[14:56:31.719] Resolver error: Error:
at g.Create (c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:583926)
at t.handleInstallOutput (c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:582540)
at t.tryInstall (c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:680469)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
at async c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:642848
at async t.withShowDetailsEvent (c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:646166)
at async t.resolve (c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:643898)
at async c:\Users\George\.vscode\extensions\ms-vscode-remote.remote-ssh-0.94.0\out\extension.js:1:723024
[14:56:31.725] ------
I can connect without an issue from the terminal using ssh, and I can connect from another device using the Remote SSH extension wituout any problems.
The issue seems to be the terminal(?)
VScode suggested I check out https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch, but I could not find something to help me.
I tried deleting the .vscode-server folder on the remote machine, but it did not fix the issue.
I believe the problem comes before trying to even contact the server.

ssh works on putty and terminal but not vscode Remote ssh (Error: connection could not be established)

I recently came across this issue with the Vscode remote ssh extension. Everything was working fine but ssh suddenly has issues (connection could not be established, connection timed out, Permission Denied(public key, password))
Running ssh on terminal or Putty works fine so I'm at a loss as to what the issue is.
My Vscode version:
Version: 1.66.1 (user setup)
Commit: 8dfae7a5cd50421d10cd99cb873990460525a898
Date: 2022-04-06T14:50:12.141Z
Electron: 17.2.0
Chromium: 98.0.4758.109
Node.js: 16.13.0
V8: 9.8.177.11-electron.0
OS: Windows_NT x64 10.0.19044
My current node version
node 16.4.2
npm 8.5.0
My guess is that it might be due to node.js as I had recently used NVM to downgrade to a lower version but it was still able to work a day after installing a different version of node.js. I tried to install the latest version but the issue persists. Other things I have done:
Changing versions of Remote ssh
Reinstalling vscode
deleting the ssh config files
If nobody is able to solve this specific issue, do recommend a different IDE that can edit files from ssh. Would like to still complete my work with some kind of GUI but I'm also not sure what exactly to search for.
Here is the output log when I try to ssh. I have redacted some names.
[11:17:42.388] Log Level: 2
[11:17:42.390] remote-ssh#0.78.0
[11:17:42.390] win32 x64
[11:17:42.406] SSH Resolver called for "ssh-remote+sunfire", attempt 1
[11:17:42.407] "remote.SSH.useLocalServer": false
[11:17:42.408] "remote.SSH.showLoginTerminal": false
[11:17:42.408] "remote.SSH.remotePlatform": {"xxx.xxx.xxx.xxx.xxx":"linux","xxx":"linux"}
[11:17:42.409] "remote.SSH.path": undefined
[11:17:42.409] "remote.SSH.configFile": undefined
[11:17:42.409] "remote.SSH.useFlock": true
[11:17:42.409] "remote.SSH.lockfilesInTmp": false
[11:17:42.409] "remote.SSH.localServerDownload": auto
[11:17:42.410] "remote.SSH.remoteServerListenOnSocket": false
[11:17:42.410] "remote.SSH.showLoginTerminal": false
[11:17:42.410] "remote.SSH.defaultExtensions": []
[11:17:42.410] "remote.SSH.loglevel": 2
[11:17:42.411] "remote.SSH.enableDynamicForwarding": true
[11:17:42.411] "remote.SSH.enableRemoteCommand": false
[11:17:42.411] "remote.SSH.serverPickPortsFromRange": {}
[11:17:42.412] "remote.SSH.serverInstallPath": {}
[11:17:42.446] SSH Resolver called for host: sunfire
[11:17:42.447] Setting up SSH remote "sunfire"
[11:17:42.509] Using commit id "8dfae7a5cd50421d10cd99cb873990460525a898" and quality "stable" for server
[11:17:42.515] Install and start server if needed
[11:18:36.858] Checking ssh with "ssh -V"
[11:18:36.925] > OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
[11:18:36.933] Running script with connection command: ssh -T -D 49776 sunfire bash
[11:18:36.939] Terminal shell path: C:\Windows\System32\cmd.exe
[11:18:37.299] > ]0;C:\Windows\System32\cmd.exe
[11:18:37.299] Got some output, clearing connection timeout
[11:18:37.608] > Password:
[11:18:37.609] Showing password prompt
[11:18:40.335] Got password response
[11:18:40.336] "install" wrote data to terminal: "*******"
[11:18:40.372] >
[11:18:40.533] > 1dd6cf88d3c6: running
[11:18:40.591] > Unsupported platform: SunOS
> 1dd6cf88d3c6: start
> exitCode==35==
> listeningOn====
> osReleaseId==SunOS==
> arch====
> tmpDir==/tmp==
> platform====
> unpackResult====
> didLocalDownload==0==
> downloadTime====
> installTime====
> extInstallTime====
> serverStartTime====
> 1dd6cf88d3c6: end
[11:18:40.592] Received install output:
exitCode==35==
listeningOn====
osReleaseId==SunOS==
arch====
tmpDir==/tmp==
platform====
unpackResult====
didLocalDownload==0==
downloadTime====
installTime====
extInstallTime====
serverStartTime====
[11:18:40.594] Failed to parse remote port from server output
[11:18:40.595] Resolver error: Error:
at Function.Create (c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:586041)
at Object.t.handleInstallOutput (c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:584693)
at Object.t.tryInstall (c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:681924)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:644564
at async Object.t.withShowDetailsEvent (c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:647909)
at async Object.t.resolve (c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:645643)
at async c:\Users\Raihan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.78.0\out\extension.js:1:722950
[11:18:40.605] ------
[11:18:41.251] > grep: illegal option -- a
> grep: illegal option -- E
> Usage: grep -hblcnsviw pattern file . . .
> grep: illegal option -- a
> grep: illegal option -- E
> Usage: grep -hblcnsviw pattern file . . .
[11:18:41.977] "install" terminal command done
[11:18:41.985] Install terminal quit with output: Usage: grep -hblcnsviw pattern file . . .
add this code in setting.json in file->Preference
"remote.SSH.remotePlatform": {
"$yourRemoteServerName": "linux"
}

Why windows commands are not working in vscode-insiders' terminal (error: <3>init: (632) ERROR: UtilConnectUnix:466: connect failed 111)

VSCode Version: 1.53.0-insider (x64)
OS Version: Microsoft Windows [Version 10.0.21292.1010]
WSL version: WSL 2
distribution: Ubuntu-20.04
Steps to Reproduce:
(in wsl.exe)Type code-insiders ~ && exit
Press ctrl+j in the VSCode window
Type explorer.exe .
Result:
It shows me this error:
<3>init: (632) ERROR: UtilConnectUnix:466: connect failed 111
Question:
How can I fix it and why it is happening ?
Extensions on WSL:
ms-vscode.cpptools
eamodio.gitlens
ms-toolsai.jupyter
ms-python.vscode-pylance
ms-python.python
I think I had a similar issue here, you have to check the environment variables of you WSL2 session.
WSL_INTEROP=/run/WSL/197_interop
if this points to a not existing socket the connection fails.
cheers
Marco

VS code keeps reconnecting to remote ssh

Problem: VS code keeps disconnecting / reconnecting ssh with remote machine.
After entering password it immediately comes back with password prompt again.
The logs suggest that vs code server fails.
Are there any vs code server logs I can review on the remote machine?
Details: VS code ver 1.4.5 / Windows 10;
Remote: Macbook Air (High Sierra)
Logs are below:
[09:49:41.088] > Password:
[09:49:41.088] Showing password prompt
[09:49:45.455] Got password response
[09:49:45.456] "install" wrote data to terminal: "********"
[09:49:45.889] > 028771948a23: running
[09:49:45.922] > Acquiring lock on /Users/user/.vscode-server/bin/5763d909d5f12fe19f215cbfdd
> 29a91c0fa9208a/vscode-remote-lock.user.5763d909d5f12fe19f215cbfdd29a91c0fa9
> 208a
> \ln /Users/user/.vscode-server/bin/5763d909d5f12fe19f215cbfdd29a91c0fa9208a
> /vscode-remote-lock.user.5763d909d5f12fe19f215cbfdd29a91c0fa9208a.target /U
> sers/user/.vscode-server/bin/5763d909d5f12fe19f215cbfdd29a91c0fa9208a/vscod
> e-remote-lock.user.5763d909d5f12fe19f215cbfdd29a91c0fa9208a
>
[09:49:45.943] > Found existing installation at /Users/user/.vscode-server/bin/5763d909d5f12
> fe19f215cbfdd29a91c0fa9208a...
>
[09:49:46.017] > Found running server...
[09:49:46.050] > Checking server status on port 58236 with curl
>
[09:49:46.083] > 000
> 028771948a23##28##
>
[09:49:46.083] Received install output: 028771948a23##28##
[09:49:46.083] Server status check failed - waiting and retrying
[09:49:46.364] "install" terminal command done
[09:49:46.364] Install terminal quit with output:
[09:49:47.091] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D
55978 10.0.0.134 bash
[09:49:47.092] Terminal shell path: C:\Windows\System32\cmd.exe
[09:49:47.275] >
[09:49:47.281] Got some output, clearing connection timeout
[09:49:50.747] > Password:
[09:49:50.748] Showing password prompt

Selinux - File Contexts Look Good, But Selinux Won't Allow Write

I am trying to learn Selinux. With a sandbox and using VSFTPD to experiment with, I have a vsfptd server running in Centos. I have annonmous users to place files in /var/ftp/incoming. On a remote machine I can have the user successfully log in but could not place the file on the remove vsftpd server:
$ftp mysql_server
Connected to mysql_server (192.168.1.31).
220 Welcome to blah FTP service.
Name (mysql_server:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer ftp> put atd
local: atd remote: atd
227 Entering Passive Mode (192,168,1,31,19,161).
553 Could not create file.
ftp>
On the VSFTPD server, aureport -a report shows:
[root#mysql_server ftp]# aureport -a
AVC Report
========================================================
# date time comm subj syscall class permission obj event
========================================================
4. 04/08/2013 13:30:36 vsftpd unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 21 dir write system_u:object_r:public_content_t:s0 denied 28
5. 04/08/2013 13:34:57 vsftpd unconfined_u:system_r:ftpd_t:s0-s0:c0.c1023 2 dir write system_u:object_r:public_content_t:s0 denied 47
I checked the directory and the file contexts look good, so I don't understand why Selinux won't allow vsftpd to write to the incoming directory:
[root#mysql_server ftp]# ls -Z
drwx-wx---. root ftp system_u:object_r:public_content_t:s0 incoming
drwxr-xr-x. root root system_u:object_r:public_content_t:s0 pub
[root#mysql_server ftp]#
You need to run the following commands to allow in SELinux upload and edit files:
setsebool -P allow_ftpd_full_access on
setsebool -P ftp_home_dir on
Your SELinux type is not correct. Use 'public_content_rw_t' instead of 'public_content_t'. Read more on http://beginlinux.com/blog/2008/11/vsftpd-and-selinux-on-centos/