Visual Studio Code is a great editor for local files. Remote VSCode is an extension that enables editing files on remote systems in your local VSCode. Note that you will need to specify individual files on the remote computer and they will appear in your local VSCode. You cannot open a remote folder and expect all of the code there to be indexed for code browsing with this method.
- Install rmate on the remote computer. rmate has been ported from its original Ruby implementation to Python, Bash and other languages. I like to use rmate-python. Installing it is easy:
$ sudo pip3 install rmate
//-------- Remote VSCode configuration --------
// Port number to use for connection.
// Launch the server on start up.
// Address to listen on.
// If set to true, error for remote.port already in use won't be shown anymore.
$ ssh -R 52698:127.0.0.1:52698 yourlogin@remotecomputer
- Once you are SSHed into the remote computer, run this command there:
$ rmate -p 52698 file/you/want/to/edit
The file will appear in your local VSCode for editing. The remote file will be updated with any changes you make locally after you save the file.
Tried with: Visual Studio Code 1.22.2 and Remote VSCode 1.1.0
I installed the latest stable release of ConEmu. I opened a Cygwin shell and used SSH to connect to a remote computer. I ran Byobu on the remote computer. I noticed that its status bar would shift upward, overwriting the entire screen after some time.
This problem is documented here. The solution suggested by the ConEmu creator is to use the ConEmu/msys terminal connector plugin. Using this connector is however a bit complicated. But, according to this post, it has been rolled into ConEmu starting with the 170705 release. I checked and found that the stable release I had installed was 161206. The stable release was years behind!
Seeing no recent stable version available, I opted to download a preview release from here. This release was dated later than 170705. byobu worked fine through SSH from Cygwin after that!
Cygwin not only provides most of the Linux programs and shells, it also comes with a builtin X server called Cygwin/X. This is great if you want to run Cygwin GUI applications locally or over SSH from a remote computer.
- Install Cygwin, if you do not already have it.
- Use the Cygwin setup program and install the
xinit packages. The first one is the X server and the second installs a lot of scripts and programs that enable you to start the server and use it.
- Install the
xeyes package. This is a small X application that we will use for testing X.
Use Cygwin/X for local apps
- Kill the
XWin and other X server processes if they are running and close all your Cygwin windows. Open a new Cygwin window.
- Set the
DISPLAY environment variable:
$ export DISPLAY=:0.0
- startx: If you run
startx, you get X server opening a X window with XTerm running inside it. From here on, you can open X apps by running them from that XTerm. You can try by running
xeyes inside that XTerm. Once you kill this X window, your X server is closed.
startxwin: If you run
startxwin, you get X server running, but no windows are displayed. You can now open another Cygwin window and can invoke individual X apps there and they will be displayed in individual windows. You can try by running
xeyes from the Cygwin shell. This is called the multiwindow mode.
Use Cygwin/X for remote apps
- Follow all the steps shown above for local X apps. Make sure you have killed the earlier X server processes, set the
DISPLAY environment variable locally and run
startxwin. Make sure local X apps can display a window to the Cygwin/X server.
- SSH to the remote computer running Linux using ssh on Cygwin or PuTTY. Make sure you have X11 Forwarding enabled for this SSH session. This is usually done by specifying
-X (untrusted forwarding) or
-Y (trusted forwarding) or setting the corresponding X11 Forwarding option in your SSH config file.
- Check the
DISPLAY on the remote computer. It should be set to some value like shown below:
$ echo $DISPLAY
DISPLAY is empty, then either you did not set
DISPLAY locally, did not cleanly restarted a X server locally or there was a problem with SSH X11 Forwarding. Please diagnose.
- Run the
xeyes program from the remote computer. It should display in a window on your local machine. Your Cygwin/X server is working! You can now run GUI/X apps from the remote computer and display them locally. Beware that they will be slow to display and refresh.
Tried with: Cygwin 2.10.0 and Windows 10
I tried to SSH to a server using a private key file and got this error:
$ ssh -i myprivate.key 10.0.0.100
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
Permissions 0664 for '/home/joe/myprivate.key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/joe/myprivate.key
This key file strangely had access permissions by all to read, write and execute! SSH was complaining that such a file is too open and could be compromised. I reduced the access permissions to just read by me:
$ chmod 0400 myprivate.key
SSH worked after this change 🙂
Tried with: SSH 6.6 and Ubuntu 14.04
There are times when you want to check if you are in a SSH session from your shell. For example, I like to change the shell prompt based on whether it is in a local machine or in a SSH session on another machine.
An easy way to do this is to check if any environment variable related to SSH has been set. For example, I check if the
SSH_CLIENT variable is set in my shell. In Fish, this can be done by checking the result of
set --query SSH_CLIENT for example.
Normally when you SSH into a computer, you need to provide a username and it will prompt you for your password, like this:
$ ssh joe@server_machine
By generating a public-private key pair on the local machine and sharing the public key with a remote machine, you can SSH to the remote machine without providing a login or being prompted for a password.
After this setup is done, you will operate like this:
$ ssh server_machine
$ That is it! You are logged in without login or password!
To set this up:
- Generate a public-private key pair on your local computer. If you already have one (probably you generated it for Github) and want to use that, then skip this step.
$ ssh-keygen -t rsa -b 4096 -C "email@example.com"
This generates a public key in
~/.ssh/id_rsa.pub and its corresponding private key in
- We need to add the public key from local machine to the
~/.ssh/authorized_keys file on the remote computer you are logging to. You can do this manually. However, the
ssh-copy-id script does this for you. Just pass the remote computer name as input:
$ ssh-copy-id remote_machine
If there is no
~/.ssh/authorized_keys file on the remote machine, this script will create it for you. If the file exists, your public key from local machine will be appended to the existing file.
Reference: Arabesque: Linux Crypto – SSH Keys
Tried with: Ubuntu 14.04
DigiSSHD is one of the many SSH server apps for Android devices. This app requires a rooted device. If your device is not rooted, it will just fail to execute.
Tried with: DigiSSHD 0.2.2, Moto G2 (XT1068) and Ubuntu 14.04
The SSH Server app from Ice Cold Apps enables you to SSH into any Android device. I use this to SSH from my Ubuntu computers to my Android devices, both connected to my home wireless network.
- If you have not rooted your phone, you will not be able to access privileged directories and files. You will also have to pick a port number that is bigger than 1024.
First, create a Server and create a User in the app. Remember to specify a port number that is bigger than 1024. Start the server to run the SSH server.
SSH to the Android device using its IP address, the username you created and the port you specified. You will be asked to accept its key and will be prompted to enter the password you specified earlier:
$ ssh firstname.lastname@example.org -p 1700
- Assign a static IP address to your Android device for easier access, so that you do not have to look up what IP address has been assigned to it every time.
Tried with: SSH Server 3.1, Moto G2 (XT1068) and Ubuntu 14.04
I SSH to another Linux computer and get this error:
$ ssh email@example.com
ssh: connect to host 172.20.128.100 port 22: Connection refused
Typically, there is no complicated reason of permissions why this failed. Since the OpenSSH client is almost always installed by default on Linux computers, people assume that the OpenSSH server is also installed. It is not and it gives this error!
Install the OpenSSH server on the host and you should be able to SSH to it:
$ sudo apt install openssh-server
Tried with: Ubuntu 14.04
A SSH session gets hung or frozen sometimes. To exit or kill the SSH session and get back to the local shell, press this key sequence:
That is you press 3 keys in sequence: Enter, then tilde and then period.
Tried with: OpenSSH 5.9p1 and Ubuntu 12.04 LTS