Can't connect to AWS EC2 server via vscode sftp extension on Ubuntu 22.04 OS - visual-studio-code

I used to connect remote servers provided by Linode and GCP and I use Visual Studio Code via Sftp extension and all works just fine. However, with the same set of configurations, I couldn't connect to my Aws EC2 server.
The following is the sftp.json (with sensitive information changed)
And the aws security setting is as following
The strange thing is that I can ssh connect to the server on the terminal and I can use filezilla to send file with the same credential as well. But somehow I can't connect to it via Visual Studio Code sftp or SSH remote extension.

I searched the anwser on the internet and found an answer that worked for me.
The problem has to do with the Ubuntu 22.04 default server default key setting and not with the VSCode.
The solution is adding
PubkeyAcceptedKeyTypes=+ssh-rsa
in /etc/ssh/sshd_config
and then restart the service on the server with the following command
sudo systemctl restart sshd
The source of the answer comes from https://github.com/liximomo/vscode-sftp/issues/37 under the user windware-ono's answer.

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!

Disable install of VS Code server

I use my VS Code remote - SSH extension to jump between a lot my customers servers, and would actually like not install the VS Code server on every server that I use.
Is there a way not to install the VS Code server, when you use the Remote - SSH extension, or is there maybe even another extension I should use instead?
To fix this on your own (without using the script mentioned above), you could simply log into each of the linux. cs servers (using SSH), then the command pkill -u node , which will stop any running vscode-server processes
I fixed it but not using the official remote - SSH, but the extension SSH FS, which is a little more combersome as it can see you'r "normal" ssh config, but i works.
https://marketplace.visualstudio.com/items?itemName=Kelvin.vscode-sshfs

VS Code Remote-SSH won't reconnect to one specific working directory on remote Ubuntu host

I'm using VSCode 1.72.2 with Remote-SSH v0.90.1 on Windows to develop against an AWS EC2 VM running Ubuntu 22.04 LTS. A couple days ago, I was working in my project source folder in /opt/t4/ on the target host. When I was finished, I stopped the VM from the AWS console, forgetting that VS Code was still SSHed in.
When I brought the VM back up, I can reconnect VS Code/Remote-SSH to the host as before, except that I can no longer connect using /opt/t4/ as my working directory. I can use any directory except the one I was using when I disconnected.
I can navigate down to it and work in it if I use /opt/ as my working directory. I can navigate to it by manually SSHing to the remote host. I can create a subfolder in a remote shell at /opt/t4/test/, and then connect VS Code using that subfolder as my working directory. I can see and select /opt/t4/ in the Open Folder dialog in VS Code. But when I try to connect using that working directory, the connection times out with a not-particularly-useful error message:
[00:05:49.867] SSH Resolver called for "ssh-remote+my.remote.host", attempt 2, (Reconnection)
[00:05:49.868] SSH Resolver called for host: my.remote.host
[00:05:49.868] Setting up SSH remote "my.remote.host"
[00:05:49.870] Using commit id "d045a5eda657f4d7b676dedbfa7aab8207f8a075" and quality "stable" for server
[00:05:49.872] Install and start server if needed
[00:05:49.874] Using SSH config file "C:\Users\me\.ssh\config"
[00:05:49.874] Running script with connection command: ssh -T -D 1518 -F "C:\Users\me\.ssh\config" "my.remote.host" bash
[00:05:49.875] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[00:06:06.876] Resolver error: Error: Connecting with SSH timed out
at g.Timeout (c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.90.1\out\extension.js:1:585348)
at Timeout._onTimeout (c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.90.1\out\extension.js:1:679743)
at listOnTimeout (node:internal/timers:559:17)
at process.processTimers (node:internal/timers:502:7)
[00:06:06.877] ------
I tried Remote-SSH: Uninstall VS Code Server from Host from VS Code.
I tried deleting ~/.vscode-server on the Linux host from an SSH session.
I tried Remote-SSH: Kill VS Code Server on Host from VS Code.
I tried Remote-SSH: Kill Local Connection Server for Host from VS Code.
I tried deleting and recreating the host connection details in the local config file from SSH-Remote.
I tried rebooting both local and target hosts.
I tried setting /opt/ as my working dir, then deleting and recreating /opt/t4. I was able to do this, but as soon as I try reconnecting using /opt/t4 as the working dir, VS Code still fails to connect.
I'm... stumped. My suspicion is that there is something corrupt cached Windows-side, but I don't know where to look for that.
Microsoft is aware and working on a fix. There are a variety of workarounds in this thread: https://github.com/microsoft/vscode-remote-release/issues/7324
Thanks to the link from #Mike Barry, I managed to find the local workspace for that target folder and delete it to force it to reinitialize, which cleared the issue.
Deleted C:\Users\me\AppData\Roaming\Code\User\workspaceStorage\[guid]\ and reconnected with no problem.

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.

ssh not working for Amazon EC2 server

I have setup and launched an instance of Amazon EC2 server with Ubuntu in it. Now I have integrated cygwin with command prompt also so all linux commands are working in command prompt.
I tried to access the server using ssh -i munish.pem ubuntu#52.11.190.155 (munish.pem contains my secret key).
After running this command I get an error: 'ssh' is not recognized as an internal or external command, operable program or batch file. I searched net and could find solution for github not for Amazon EC2 service...
You can use putty software in window for connecting to the AWS EC2 instance.
Follow the below steps:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html
Hope it helps..
You can open PowerShell and check ssh command is available or not.
If not, you can install OpenSSH in Windows 10. See following guide on how to install it.
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse