December 27, 2021
SSH, the Secure Shell, supports remote login and command-line or GUI access across the network through encrypted tunnels protected by public-key cryptography.
SSH is a useful tool that allows doing all your work in your CS account, even while working outside the GNU/Linux lab, including from any campus Mac computer or, in some cases, your personal computer. Using SSH has some limitations and caveats that require occasional care and attention to avoid.
The host machine is the machine to which you want to connect, in this case, a CS machine where you will do your work. All CS GNU/Linux workstations support incoming and outgoing SSH access.
The client machine is the machine that you are physically using to connect to the host.
The GNU/Linux and macOS environments include a built-in SSH client. On Windows, you can use the standard SSH client in the Windows Subsystem for Linux (WSL) (a mostly-sort-of-GNU/Linux environment hosted inside the Windows operating system) or install a Windows-native SSH client like PuTTy.
Make sure to follow these steps carefully—doing one incorrectly may prevent SSH from working in VS Code.
ssh YOUR_CARLETON_USERNAME@mantis.mathcs.carleton.edu
as the ssh command (replacing YOUR_CARLETON_USERNAME
with the part of your Carleton email before the @
)
mantis
If you can’t connect after following these steps, use F1 to bring up the command palette, type in “ssh config” and select “Remote-SSH: Open SSH Configuration File…”. Choose the same one you selected in step 5 (should be the first option). Make sure you see an entry that looks like this:
Host mantis.mathcs.carleton.edu
HostName mantis.mathcs.carleton.edu
User awb
If you see one containing mantis
that doesn’t look like that, delete it, and try again starting from step 3.
Assume:
mantis.mathcs.carleton.edu
. On the campus network, “inside” the carleton.edu domain, you can leave off “.carleton.edu”.In the example below, a line prefix up through the $
symbol indicates the command prompt. Text to its right on the same line is the command. Lines not starting with this prefix are output from commands.
On your client machine, open a terminal and use the following ssh
client command to log in to the machine mantis
as user ccarleton
and establish a remote command-line shell on mantis
:
carl@client:~$ ssh ccarleton@mantis
On your first login from your client machine, SSH will prompt for confirmation.
On all logins, enter your Carleton password when SSH prompts for it:ccarleton@mantis's password:
Once you enter your Carleton password successfully, SSH will present you with a shell running on mantis
, as if you had logged in physically and opened a terminal on mantis
.
Notice that the prompt shows that your shell is running on mantis
, indicated by @mantis
. This prompt helps tell whether you are running commands on your machine or the remote machine.
ccarleton@mantis:~$
Any commands you enter here run on mantis
, manipulating files on mantis
, etc., but the interactive input/output happens here in this terminal on your client machine instead of on mantis
‘s’ screen and keyboard.
When you are done working on mantis
log out by typing logout
, exit
, or Control-D at the command prompt. SSH will close the connection and exit, returning you to the command prompt on your local machine.
ccarleton@mantis:~$ logout
Connection to mantis closed.
carl@client:~$
SSH always checks that the remote machine is who you think it is. The first time you connect to any given host from here, your local SSH client has no way of knowing if this is the same machine as last time, since there was no last time.
The authenticity of host 'mantis.mathcs.carleton.edu (137.22.4.81)' can't be established.
RSA key fingerprint is SHA256:VV6Y83C2KcoUuyZEUYRcO/G/sDWnJ/gQRav88uGoXxE
Are you sure you want to continue connecting (yes/no)?
Enter yes at the prompt to continue.
SSH will remember this fingerprint and check it again every time you connect to mantis
in the future, aborting if it does not match.
Warning: Permanently added 'mantis.mathcs.carleton.edu,137.22.4.81 (RSA) to the list of known hosts.
Be aware the remote work comes with some caveats that require you to more mindful of your work than when you work directly on a physical machine.
If you close your laptop, if the WiFi drops out, or if your client machine otherwise loses network access, the SSH connection will be broken, and any in-progress remote commands will terminate in error. This includes unfortunate results like losing your last few minutes (or more) of work. Save often, definitely before closing or moving your laptop! A dropped SSH connection can also mean losing your context if you had many shells or editor windows open. Unfortunately, this can happen more often than desirable due to sometimes spotty WiFi coverage.
If you log in to a workstation physically and also login as the same user remotely, you may experience odd effects when trying to start potential GUI applications like emacs
. Even though your command-line SSH connection may not support GUI access, emacs
might happily pop up on the GUI on the screen where your are logged in physically. This is pretty annoying if you are not actually in the lab, but forgot to logout before leaving this workstation. Log out when you leave.
By default, SSH opens connections that support only text command-line interaction. The -X
option of the ssh
client allows individual windows from the host’s window system (called X
) to be piped across the network to your local client machine as well. Depending on your client machine operating system, you may need extra software on the client (your client machine) to display the GUI:
For GNU/Linux, this should work with no additional software.
For macOS, install XQuartz.
For Windows, it depends, and it’s a bit more complicated.
carl@client:~$ ssh -X ccarleton@mantis
ccarleton@mantis's password:
ccarleton@mantis:~$
As before, you get a command-line shell running on mantis
, but now, any GUI application that you launch from the shell (e.g., emacs
) will run on mantis
as before, but will show its windows here on your local display.
In addition to the standard caveats about remote SSH work, you should take care interacting with remote GUI applications.
-X
does not seem to work, try -Y
(a slightly less secure version) instead.Password authentication works fine for SSH, but can get tedious if you use SSH frequently, although using a password manager or keychain on your client machine may help. Password authentication is also susceptible to all the issues around passwords. Public key authentication is an attractive alternative.
Several SSH features, like the SSH agent, host aliases, etc., make using SSH more efficient, robust, or secure. They generally require some learning and configuration work.
We do not have time to write about public key authentication or other features now, but feel free to ask. A quick web search for “ssh key” will yield many helpful resources.