Remote access via SSH

Accessing the server remotely via SSH.

ssh <account_name>@<server_hostname>

Server aliases

Creating aliases for hosts in your local SSH config file. This can be done to more easily connect to servers that have names that are too long and are hard to remember.

You will need to run a Bash shell on your local computer, such as Gnome Terminal, KDE Konsole, or Windows PowerShell. Edit your ssh config file with any text editor. To do it from the command line:

nano ~/.ssh/config

Then, enter the following information:

host <alias>  # <alias> is the name you would like to call the server (e.g. ocelot)
hostname <address>  # the server address, for instance abc.myserver.net or 10.0.0.2
user <username>  # Your username on the server

Press ctrl+X and type Y to save.

Now you can run ssh <alias>.

Note: If the folder .ssh does not exist in your home directory, you can create it with mkdir /home/<username>/.ssh.


Passwordless login

Using a public key to log in through SSH. This allows you to log in to an SSH server without having to type your password every time.

First, on your local machine, run: ssh-keygen, follow the prompts. You can leave the pass-phrase blank. This will generate a pair of public and private keys for your user.

Next, we will paste the generate key onto the server's list of authorized keys:

  1. List the public key with cat ~/.ssh/id_rsa.pub
  2. Copy the entire key using command+C on Mac or ctrl+shift+C on Windows/Linux. It should look something like ssh-rsa ABcdeFg12345... yourname@yourhost. (WARNING: Keep your private key private!!!)
  3. Log in to the server with ssh.
  4. On the server, open the authorized keys file with nano ~/.ssh/authorized_keys.
  5. Paste your key at the bottom of this file (command+V on Mac, ctrl+shift+V on Windows and Linux)
  6. Exit nano with ctrl+X and type Y to save.

Now, the next time you try to log in with SSH, you will not need to type your password. Combine this with the alias for quickly accessing servers with SSH.