Visual Studio Code Remote - SSH with key via KeePass / KeeAgent fails - visual-studio-code

I am having trouble using the remote-ssh plugin in Visual Studio between machine A and machine B where the key is provided by KeeAgent from a KeePass database on machine A.
Machine A runs on Windows 10 and I have set up the Host (machine B) in Visual Studio Code correctly according to the guide. However, when trying to use the remote feature, I get the following error:
[09:48:32.111] Log Level: 2
[09:48:32.121] remote-ssh#0.51.0
[09:48:32.121] win32 x64
[09:48:32.124] SSH Resolver called for "ssh-remote+XXX.XXX.XXX.XXX", attempt 1
[09:48:32.125] SSH Resolver called for host: XXX.XXX.XXX.XXX
[09:48:32.125] Setting up SSH remote "XXX.XXX.XXX.XXX"
[09:48:32.314] Using commit id "91899dcef7b8110878ea59626991a18c8a6a1b3e" and quality "stable" for server
[09:48:32.317] Install and start server if needed
[09:48:38.141] getPlatformForHost was canceled
[09:48:38.142] Resolver error: Connecting was canceled
[09:48:38.147] ------
where XXX.XXX.XXX.XXX obviously is the correct IP of machine B in my output.
As I mentioned, the SSH key for this machine is provided via KeeAgent and works fine with PuTTy. I am not allowed to store a SSH key in plaintext on machine A, hence the Keepass/KeeAgent solution. I guess this is the Problem, that somehow Visual Studio Code does not work with KeeAgent.
Can I work around this, i.e. by telling VS Code to use plink.exe as SSH client, which works with KeeAgent? Or does VS Code allow the encrypted storage of SSH keys itself, thereby making KeeAgent obsolete? I am new to both VS Code and the remote-ssh plugin, so I'm sorry if my questions have obvious solutions.
Maybe the problem lies elsewhere though. In that case I am thankful for every hint.
Thanks!

Go to Options > KeeAgent, then scroll down to Agent Mode Options and activate Enable agent for Windows OpenSSH (experimental): (default: disabled) Enable an SSH agent socket compatible with the built-in Windows 10 SSH client.

Related

I cannot SSH with Kerberos in VS Code on Windows 10 even though PuTTY works fine

Problem Summary:
I can SSH to remote host using Kerberos and PuTTY on Windows 10, but I can't connect using VS Code.
Steps I have tried:
I used MIT Kerberos Ticket Manage to generate a Kerberos API key.
Then, in PuTTY I selected both “Attempt GSSAPI authentication” and “Allow GSSAPI credential delegation” . After entering the host name and my username, I can successfully connect to the remote host in PuTTY.
However, I cannot connect to the remote host in VS Code using the following SSH config file:
Host my-host
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes
User my-name
My error looks like this:
I learned from this Stack Overflow answer that Windows "has two Kerberos libraries (MIT KfW & Windows SSPI)", so my suspicion is that VS Code is not looking for GSSAPI libraries in the correct order, like the PuTTY screen shot. But I don't know how to specify the order like in PuTTY.
Please help! Thanks!

vscode remote ssh connection cannot connect on windows server 2022

I'm trying to setup Remote SSH extension on vscode to connect to a server that runs Windows Server 2022.
First, I can connect with SSH from the terminal ssh username#public_ip -p port then I enter the password and I can access the server.
I installed the Remote - SSH extension on vscode. I was able to connect to a Raspberry Pi without problems... But I cannot connect to a Windows Server 2022.
It asks me to enter the username password twice, then after a few seconds it stops with two errors pop-ups (see picture below).
Could not fetch remote environment
Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)
errors
Also, from another machine. I can connect to my server with vscode and the same extension (Windows Server 2022) without any problems so I don't think that the server has any issues. Seems like the problem is on my computer that won't connect.
I was able to connect once but I did break something and I don't know what. I tried to reinstall the extension but nothing helped.
EDIT:
I think I fixed it.
Here's what I did.
I uninstalled the Remote - SSH extension
I opened the settings.json on my local computer and deleted everything that had to do with this extension.
Deleted the config file from C:\Users\username\.ssh\config
I restarted vscode
Installed the extension
And it worked.

2FA with VS Code Remote-SSH?

I am using the Remote-SSH extension in Visual Studio Code to connect to a remote machine. This remote machine is protected by Duo's two-factor authentication. When I SSH in a terminal (outside of VS Code), I'm able to log-in perfectly - the terminal prompts me through the 2FA process. However, inside VS Code when I'm using the extension, I am not able to log-in. After typing in my SSH hostname and ID, the VS Code interface prompts me for my password over and over again, and does not proceed beyond that point.
Has anyone encountered this issue before? I'd love to know if there is an existing solution. Unfortunately, 2FA is managed by my company and I can't turn it off.
I run into the same problem and fixed it by using SSH ControlMaster for Single Singe-On.
If you connect to the relevant machine using <user_name>#<host_name> you can simply add the following to your ~/.ssh/config:
Host <nickname>
User <user_name>
HostName <host_name>
ControlMaster auto
ControlPath ~/.ssh/%r#%h:%p
If you now open up a new session in your terminal running ssh <nickname> you will be asked for the password and the 2FA key. But all other subsequent ssh sessions (including svn, rsync, etc. that run over ssh) will piggyback off the initial connection without the need for re-authentication.
You can now in VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, ⇧⌘P) and simply enter: <nickname> and ControlMaster will automatically connect you using the already standing connection.
In my case, the nickname that I choose is "ody". After connecting VSC's Remote Development extension shows the following in the bottom left corner and lets me browse the files on the remote machine.
From the FASCR:
Note that all subsequent connections are dependent on the initial connection — if you exit or kill the initial connection all other ones die, too. This can obviously be annoying if it happens accidentally. It’s easily avoided by setting up a master connection in the background:
ssh -CX -o ServerAliveInterval=30 -fN <nickname>
The -fN make it go into the background and sit idle, after authenticating. (C for compression,Y for X forwarding, and o ServerAliveInterval=30 to prevent dropped connections have nothing to do with the ControlMaster but are almost always helpful.)
Note that all port forwarding, including X display forwarding, must be setup by the initial connection and cannot be changed.
Got to settings in VS Code and enable this setting, remote.SSH.showLoginTerminal. This pulls up the terminal so that sign in via 2FA that way.
You can use ~/.ssh/config file to configure your hostnames and keys. But I don't know if there is a way to save passwords for convenience.

Manage to connect through the terminal, but not through the remote explorer

I am coming from notepad, and am learning how to work with VS Code.
I am now trying to access my online repertory on the webserver.
I followed up the guide here: https://code.visualstudio.com/docs/remote/ssh
I did manage to access my server through the terminal window.
(ssh user#domain + password).
When connecting, this shows in the log:
"Linux infong-eu27 4.4.246-icpu-061 #2 SMP Thu Nov 26 10:58:41 UTC 2020 x86_64"
This tells me that it is working on Linux.
If I type "Ls", I can see my folders and navigate among them.
So far, so good!
Second phase: Connecting through the remote explorer.
Step 1:
I configured the ssh with the same credentials I used with the terminal.
Step 2:
I am opening the remote explorer, I can see my server's name. I right click on it and select "connect".
Step 3:
I am then asking to choose the system. I am picking Linux as shown earlier when connecting through the terminal.
Step 4: I am entering the same password I used before to connect in the terminal.
Step 5: Infinite loading, or a very long one till I get 2 notifications / errors:
Could not fetch remote environment
Failed to connect to the remote extension host (error time limit..)
That being said, it also says in the bottom left corner, in the "remote window", that I am connected. This does not seems right.
Any chance someone could help?
I am frustrated because it connects in 1s using the terminal, but not in the remote explorer.
UPDATE:
I found this article on medium that paraphrases the official documentation.
https://medium.com/#sujaypillai/connect-to-your-remote-servers-from-visual-studio-code-eb5a5875e348
I managed, through Git bash, to create a ssh pair key, and managed to copy one on my server.
I then followed the instructions on how to set it up on VS Code successfully!
Now, when I try to connect, I am asked for my key pass:
But, when I do: super long loading, and the same error message.
When I looked on my server with a sftp software, I see that VS did manage to connect as files were installed in a VS folder it created:
This is reported in issue 4415 (no answer) and issue 4204
The last one includes:
This might be caused by our new automatic port forwarding feature which scans the remote OS for available ports in order to forward them locally (microsoft/vscode#112843)
This is fixed by PR 113342, for the next 1.54 Feb. 2021 release. That bug is about setting remote.autoForwardPorts to false and... still seeing VSCode auto-forward ports!
Check on your server (while VSCode attempts to connect) if:
the CPU is high
if there are any services running on public port on said server
I solved a similar issue by following the error logs from the remote ssh extension. I had to install libatomic1 on the remote server with
sudo apt-get install libatomic1

How to set ControlMaster with Remote-SSH in Visual Studio Code?

I use Visual-Studio-Code with Remote-SSH extension and I don't want to authentiaction multiple times after I login. So I search the ControlMater option with ssh_config to setup.
After I connected and I got below error message.
Can't connect to Leo-OA: unreachable or not Linux x86_64 (packet_write_poll: Connection to UNKNOWN port -1: Permission denied)
My environment:
Client:
Visual Studio Code 1.35 Stable
Windows 10 1803
Server:
Ubuntu 16.04 LTS
Below is my setting file
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host STONE-OA
HostName 10.32.21.123
User rock
Host Leo-OA
HostName 10.32.21.123
User root
Port 60001
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r#%h-%p
ControlPersist 600
I want to know what is the main problem and how to fix. Thanks everybody.
This feature is not supported on Windows.
Simply running ssh on Windows with ControlMater in PowerShell without VS code has problem too. However you can use ControlMater in WSL without problem.
https://code.visualstudio.com/docs/remote/troubleshooting#_enabling-alternate-ssh-authentication-methods
If you are on macOS and Linux and want to reduce how often you have to enter a password or token, you can enable the ControlMaster feature on your local machine so that OpenSSH runs multiple SSH sessions over a single connection.