VS Code - Openfolders and edit files through SSH tunnel - bash

I typically use VS Code's Remote-SSH extension to connect to an AWS instance where I do my work. There's a nice section of their documentation about how to do that here. I hate just using the terminal alone because I like the debugger and the ability to open up folders and files for viewing. Until recently I had been SSH-ing from my MacBook Pro (A) to an AWS instance running Ubuntu 18.04.4 LTS (B) without any issues. Now, however, I need to work on a new instance, also Ubuntu 18.04.4 LTS, (C) that I can only SSH into from B, and not from A.
This part of the documentation indicates that I can SSH from A to B and then forward a port to create an SSH tunnel. However, this only allows me to open a terminal into C. However, this doesn't allow me to open folders and files in the Explorer like I want to.
I've followed Qinsheng's instructions here to set up an SSH tunnel and use the Remote-SSH extension's "ProxyJump" functionality My config file looks like this:
Host B
HostName B.mydomain.com
IdentityFile /Users/MyID/.ssh/B_private_key
User me
Host C
HostName C
IdentityFile /Users/MyID/.ssh/C_private_key
ProxyJump B
User me
This works perfectly when I use the terminal on VS Code to run ssh C. Without having to input any password(s) I am taken to C and can perform my work. However, when I try to use the "Remote-SSH: Connect to Host" functionality to SSH into C, using ProxyJump through B and subsequently open a folder/view files there, I get the message "Could not establish connection to 'C'". The stack trace looks like this:
[13:59:48.537] Log Level: 2
[13:59:48.539] remote-ssh#0.51.0
[13:59:48.539] darwin x64
[13:59:48.541] SSH Resolver called for "ssh-remote+C", attempt 1
[13:59:48.541] SSH Resolver called for host: C
[13:59:48.541] Setting up SSH remote "C"
[13:59:48.546] Acquiring local install lock: /var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-remote-ssh-C-install.lock
[13:59:48.590] Looking for existing server data file at /Users/MyID/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-v1-91899dcef7b8110878ea59626991a18c8a6a1b3e-0.51.0/data.json
[13:59:48.593] Using commit id "91899dcef7b8110878ea59626991a18c8a6a1b3e" and quality "stable" for server
[13:59:48.595] Install and start server if needed
[13:59:48.599] Checking ssh with "ssh -V"
[13:59:48.629] > OpenSSH_8.1p1, LibreSSL 2.7.3
[13:59:48.632] askpass server listening on /var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-c4eabfddec4ae91c1e423a3167dd184d8553da26.sock
[13:59:48.633] Spawning local server with {"ipcHandlePath":"/var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-b00842fb08dbbff49678439b1335f105364fd9d5.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","52911","-o","ConnectTimeout=15","C"],"dataFilePath":"/Users/MyID/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-v1-91899dcef7b8110878ea59626991a18c8a6a1b3e-0.51.0/data.json"}
[13:59:48.633] Local server env: {"DISPLAY":"1","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/Users/MyID/.vscode/extensions/ms-vscode-remote.remote-ssh-0.51.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/Users/MyID/Desktop/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer)","VSCODE_SSH_ASKPASS_MAIN":"/Users/MyID/.vscode/extensions/ms-vscode-remote.remote-ssh-0.51.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/var/folders/w2/0w6jys8d34x940rj7f5r20vnh83ht7/T/vscode-ssh-askpass-c4eabfddec4ae91c1e423a3167dd184d8553da26.sock"}
[13:59:48.635] Spawned 29414
[13:59:48.734] > local-server> Spawned ssh: 29415
[13:59:48.738] stderr> OpenSSH_8.1p1, LibreSSL 2.7.3
[13:59:48.740] stderr> /bin/false: No such file or directory
[13:59:48.740] stderr> kex_exchange_identification: Connection closed by remote host
[13:59:48.741] > local-server> ssh child died, shutting down
[13:59:48.745] Local server exit: 0
[13:59:48.745] Received install output: OpenSSH_8.1p1, LibreSSL 2.7.3
/bin/false: No such file or directory
kex_exchange_identification: Connection closed by remote host
[13:59:48.746] Stopped parsing output early. Remaining text: OpenSSH_8.1p1, LibreSSL 2.7.3/bin/false: No such file or directorykex_exchange_identification: Connection closed by remote host
[13:59:48.746] Failed to parse remote port from server output
[13:59:48.747] Resolver error:
[13:59:48.750] ------
It seems clear to me that the main problem is something trying to access /bin/false as the interpreter. I assume that this is an issue with my MacBook Pro (A). I did notice that when running echo $SHELL on A that it was returning /bin/false, but I ran export SHELL=/bin/bash to change that and followed the suggestions in this post to set VS Code's integrated shell for MacOS to /bin/bash as well. I've checked echo $SHELL on B as well and it is similarly showing /bin/bash too.
My questions are these:
Is what I am trying to accomplish possible?
If it is, what am I doing wrong?/what can I check to help make sure that I can get to the VS Code functionalities that I want?

I figured it out. I had a bunch of /bin/false references in my /etc/passwd file, so I changed those out to /bin/bash and now it works like a charm. :)

Related

SFTP - "EOF while reading packet" error in PhpStorm, works fine in FileZilla

I'm trying to get an SFTP connection working in PhpStorm. It works fine in FileZilla.
In the SSH config section of the STFP config, I enter host, username and auth type (password) and click Test Connection. It connects fine.
If I click OK and go dialog level back and click Test Connection on the main SFTP config, I get Connection to dev.the-server.net failed. EOF while reading packet error. Like wise when I close the SFTP config dialog, there is an EOF while reading packet error where a directory listing should be.
If I use the same credentials and connect by FTPS, I can get a remote directory listing and download files, but I get the end of file error trying to upload.
This all seems to be PhpStorm issue because I can upload and download fine with FileZilla. For workflow reasons, I really need PhpStorm to connect.
Any thoughts on where to start?
Images of the SFTP dialog:
Main SFTP config
SSH section of SFTP config
Restarting PhpStorm helped to solve the problem.
For me, it failed because sftp-server was configured with the wrong path in sshd_config, and this link saved me. so:
Find the correct path of sftp-server (the whereis sftp-server command may be help), e.g. /usr/libexec/sftp-server.
Set the correct path in sshd_config (most likely in /etc/ssh/sshd_config), e.g. Subsystem sftp /usr/libexec/sftp-server.
Restart the sshd server (possibly /etc/init.d/sshd restart or /usr/sbin/sshd restart).
Restart your IDE.
In my case I've changed SSH settings, restarted SSH service, restarted PHPStorm but it didn't help. But when I restarted the whole server and then tried again it started to working again.
In my case I didn't install openssh in server. You can try this command.
sudo apt-get install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh

rsub with sublime and ssh connection refusual

I am trying to use rsub to create tunnel in ssh to sublime text, I run the command rmate .profile but i get the following response. I am using wateroof to open the ports 52968 on 1p4 and ip6, I followed the insturctions here and its just not working
I am running osx on my local machine and ubuntu 12.04 on my remote machine I am ssh into on digitalocean
root#anderskitson:~# rmate .profile
/usr/local/bin/rmate: connect: Connection refused
/usr/local/bin/rmate: line 186: /dev/tcp/localhost/52698: Connection refused
Unable to connect to TextMate on localhost:52698
I was having the same problem.
Let remoteHost = the IP or hostname of the machine you're attempting to ssh to.
I ran ssh -R 52698:localhost:52698 remoteHost from my local machine, after whice rmate .profile on remoteHost worked.
That led me to determine that ~/.ssh/config on my local machine was incorrect.
I set ~/.ssh/config to look like this:
Host remoteHost
RemoteForward 52698 localhost:52698
It's been working solidly since I made that change.
For anyone getting this same error using PuTTy on Windows, this commenter gives great instructions:
In PuTTy's config window, nagivate to the Connection > SSH > Tunnels pane
In the "Source Port" field, type 52698
In the "Destination" field, type 127.0.0.1:52698
Select the "Remote" and "Auto" radio buttons
Click the "Add" button
Go to the Session pane and save if you want to preserve these settings.
Here's an image which does the explaining visually:
I had the same issue and here is what works for me. If you have multiple servers you want this to work for, do the following as exactly shown here:
Host *
RemoteForward 52698 localhost:52698
I consulted this link: configure SSH config file and realized you can use * in config file.
Wildcards are also available to allow for options that should have a
broader scope.
I was trying to set this up for the first time using VS Code and got the generic "Connection refused" error even though my configuration seemed fine. It turned out to be because I hadn't reloaded the IDE after installing the rmate extension (Remote VSCode). Make sure that the rmate server is active on your local machine, whatever IDE you're using.
I had the same problem and fixed with replacing the HOSTNAME with the actual IP-Address when connecting:
e.g.: ssh pi#raspberrypi.local to ssh pi#192.168.1.1
I had the same problem and gone through most of the blogs, I did everything that was told.
At last, I found myself that textmate or submile editors are closed(force quit), this caused the problem.
For example my SSH config ~/.ssh/config file to connect with DigitalOcean with Remote Forward looks like:
Host DigitalOcean
Hostname xxx.xxx.xxx.xxx
User username
RemoteForward 52698 localhost:52698
and is called in a terminal
ssh DigitalOcean
rmate then connects fine with my local Atom editor
rmate stopped working for no apparent reason. Turns out I had tripped the 'man in the middle' check. I saw this warning when doing ssh --
\###########################################################
# WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! #
###########################################################
In my case, this warning was expected so I ignored it. This may not apply for you, so verify host identity. Didn't realize this line at the end of the warning --
Port forwarding is disabled to avoid man-in-the-middle attacks.
No wonder rmate stopped working. Verifying host identity and then clearing out offending entry from ~/.ssh/known_hosts made the warning go away and rmate started working again.
I run into this issue occasionally, and at least for my setup (which might be quite particular), I have found that killing zombie instances of ssh sessions does the job.
My particular setup :
I run Linux through a VM (VMWare Fusion) on my OSX host. Then I ssh into the the Linux host from OSX, and launch sublime from the Linux side. I usually have several ssh sessions running.
I recently rebooted my Mac (without first shutting down the VM, which was probably bad), and once I got back into the VM, was unable to launch Sublime - got the "connection refused" error mentioned by the OP.
So I did a ps aux on the Linux side, and looked for all instances of :
root 657399 0.0 0.1 13956 9332 ? Ss 14:52 0:00 sshd: user [priv]
user 657461 0.0 0.0 14088 5420 ? S 14:52 0:00 sshd: user#pts/1
(where user is my username). I killed the user jobs, e.g. 657461 above, and Voila! Every thing works now. Of course, in the process of killing these jobs, you are likely to kill the ssh session you are currently in, so you will have to log back into your session.
This might not work for users who don't have the necessary kill privileges on their remote machine, so don't know how useful this is, but thought I would put it out there.

SSH Connection from MAC to Amazon EC2 not working

I am trying to connect to Amazon EC2 via:
ssh -i ~/.ssh/YOUR_KEYPAIR_FILE.pem ec2-user#YOUR_IP_ADDRESS
The terminal takes 1 or 2 mins and then prints:
ssh: connect to host XXX port 22: Operation timed out
Any ideas?
Login to AWS
Go to the Instances section
Click on the security group associated with your EC2 instance
Down the bottom click on the inbound tab and then click edit
Create this rule
TYPE SSH
PROTOCOL TCP
PORT RANGE 22
SOURCE Anywhere
You should now be able to connect to the instance on port 22 via ssh with your key.
You need to open port 22 in your security group. All ports are closed by default.
Can you try changing permissions to YOUR_KEYPAIR_FILE.pem like this
chmod 600 YOUR_KEYPAIR_FILE.pem
Then shoot the command
ssh -i YOUR_KEYPAIR_FILE.pem ec2-user#YOUR_IP_ADDRESS
I had a similar problem. I checked all my networking time and time again from the ec2 instance all the way through the VPC and out to the internet. Security groups were allowing all sources through ports 22 and 80. My NACL was allowing the right permissions. I knew AWS was all ok yet everytime I went to try ssh into an instance I would still get an operation timeout, indicating that problem must be with my local machine instead.
First to check that the ssh port was open I ran the following:
ssh localhost
This worked fine!
Afte doing some research on the net, in the end it all boiled down to java and my terminal not recognising that java was installed on my machine.
Supporting Document:
AWS Documentation
No Java means that your .pem will not be recognised
Start by running the follwing:
java -version
If you get no hits then install relevant java SDK for your OS and once installed run
which java
You should get something like this:
/usr/bin/java
Now we can try connect to an instance again and hopefully you should have success this time!
ssh -v -i ~/Downloads/labamikey.pem ec2-user#ec2-34-200-217-2.compute-
__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|
[ec2-user#ip-10-0-0-54 ~]$

How to Connect to localhost with SSH(PuTTy)

I just figured how to connect to my webhost with PuTTy .
But how to I connect to my localhost? I put
Servername: localhost
port: 22 (I've tried 80 too)
And it gives me an error "failed to connect"
How do I connect?
If you are using Cygwin on your local host, you can connect to Cygwin's sshd (SSH Daemon).
3 easy commands to install the sshd as a service: (always there when you startup the machine)
$ ssh-host-config -y # enable sshd. "-y" answers yes to all queries.
$ cygrunsrv --start sshd # start it as an autostart Windows service
$ ssh localhost # try to recursively log in via ssh
Taken from: http://nfnaaron.posterous.com/tag/puttycyg#Section2
(The second approach)
=> You get the entire ssh infrastructure: public key authentication, ssh-agent, etc...
Ensure that you have running a SSH server (such as openssh-server) running on localhost and not just a web server (such as apache). Also ensure, that localhost is really mapping to 127.0.0.0/8
The solution in the answer above won't work unless you have installed Cygwin with the OpenSSH package selected - you have to do this manually during the installation process (see option a below).
Depending on the intended purpose of your connection you can try one of the options below, option (b) being much easier to install but lacking the *nix shell capabilities.
a. You can install a Cygwin shell with ssh server, this site (http://ist.uwaterloo.ca/~kscully/CygwinSSHD_W2K3.html) has instructions for Windows Server but they work for other Windows too with may be some of the questions shown in the output on the page not appearing on non-server version of Windows. Also, where it says in the instructions to issue the command:
mount -s --change-cygdrive-prefix /
delete the -s option so that the command is
mount --change-cygdrive-prefix /
(at least this was the case for me on Windows 7).
b. PuTTy site suggests WinSSHD (http://www.bitvise.com/winsshd-download). It's an easy self-installer. Once it's up you have to click onthe StartSSHD link about 1/3rd of the screen down on the first page of the config window. Then you can connect your PuTTy to localhost. However, in my experience, it didn't provide any *nix command support, only the native Windows ones and I couldn't find anything in their user guide on this.
Hope this helps.
Just adding this answer in case anyone is still looking for a solution.
In your hostname (or IP address) section, enter localhost or 127.0.0.1
Leave the port to its default value 22
Click on open
Now a login shell will popup -
Log in as your username, your username is basically what you get when you type whoami in your Terminal.
In the password section, type the password that you use as your system's password.
The above steps should connect localhost with ssh(PuTTY)

SSH hangs on Mac Book Pro; AFS and Network Preferences?

I am having an issue with SSH hanging on my Mac Book Pro. This only happens to me once I get home from work after I have used SSH while at work. The three factors I have narrowed the issue down to are SSH, our work AFS network drive and the method of network connectivity.
At work we use an AFS drive with Kerberos Authentication to do all of our software development work on. I authenticate with Kerberos in order to gain access to the AFS drive where all my source code lives, but I open a local editor (Eclipse) which references the files on the AFS drive. Whenever I need to compile my code, I SSH in to my development server (which is also authenticated to the AFS drive) and compile from there. (Sanity Note: I know that it is a super wacky setup, but I promise I had NOTHING to do with it. I'm just making do with what I've got.)
For my Network Preferences, I use the Automatic location all the time. For that configuration I have Built-in Ethernet en1 configured to use DHCP and our company's DNS server for when I'm at work (there is no wireless available). When I go home I connect to my home network via wireless, again using DHCP.
I have a hunch that the AFS connection/Ethernet configuration is somehow the culprit here. Restarting the SSH daemon doesn't correct the problem. The only way I have found to correct the issue is by restarting the computer each time I want to use SSH. Keep in mind that I have no other (known) networking issues while at home after I've had the laptop at work.
I have a co-worker who has reported to me the same issue on his MBP.
I'm truly stumped on this one. Please provide some guidance. Thanks!
Can you be more specific about "SSH hanging"?
It sounds like your ssh client hangs after losing the connection and you are unable to do anything in the terminal. To get around this, you can use the ssh escape character (default: ‘~’) to begin an escape sequence, and use the the '.' to terminate the connection.
You can get a list of other ssh escape sequences using ~?, here's the one for OpenSSH SSH client:
Supported escape sequences:
~. - terminate connection
~B - send a BREAK to the remote system
~C - open a command line
~R - Request rekey (SSH protocol 2 only)
~^Z - suspend ssh
~# - list forwarded connections
~& - background ssh (when waiting for connections to terminate)
~? - this message
~~ - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)
If typing ~. does not work, it could be that you have the escape character disabled, in which case you can put
EscapeChar ~
inside ~/.ssh/config or /etc/ssh_config
Even when the escape character is disabled, you can simply pull up another Terminal window and type
killall ssh
to end all running ssh processes, allowing you to connect out again.
Restarting the SSH daemon would not correct this problem because sshd allows other clients to connect in to your machine, and does not affect your ssh clients connecting out to some other machine.
It appears that the fix for my issue is to delete my Kerberos tokens that are valid while at work, but not valid when at home. Hope this can help anyone having a similar issue.
Just a shot in the dark:
I recently had problems using ssh after installing Rogue Amoeba Audio Hijack Pro.
I could only use ssh as super user (sudo).
An Update to 2.8.1 resolved the issue...
Also see http://www.macobserver.com/article/2008/03/19.8.shtml for the issue.

Resources