User Tools

Site Tools


This is an old revision of the document!

Better SSH experience

This page contains some suggestions on how to improve your SSH experience.

The ssh config file

You user own configuration file is located in your home folder at the path


In some cases this file does not exist, you can create it for example by issuing

touch ~/.ssh/config

This file is very useful to create ssh shortcuts to servers and add specific options for each server. In what follows I show some examples of how this can be used.

Speedup connection using tunneling

One can speedup logging in by configuring her/his own ssh client. This will also help in scp-ing data to the cluster.

The configuration example below shows how you can access a machine through another machine with a single ssh command. The scenario is as follows:

 User  --->  machine  ---->  machine ----> machine

And you want to use one single command to login to B or C.

# access
Host hostA
User <username on>
ForwardX11 yes  # this is equivalent to ssh -X
# directly access
Host hostB
User <Username on>
ForwardX11 yes
# Use this command if A uses Openssh server version < 5.4.
# It requires the program netcat (nc) to be installed on the
# machine.
ProxyCommand ssh -q nc 22
# directly access
Host hostC
User <Username on>
ForwardX11 yes
# Use this command if uses Openssh server version >= 5.4,
# that has native support for tunnelling ssh connections.
ProxyCommand ssh -q -W

Example: My user is florido. In the template above, I would change all the <Username …> to florido.

then to login to I will do:

ssh hostB

And I will have to input 2 passwords: one for, one for

In general you will have to input as many passwords as the number of hops. To overcome this problem, use a private/public ssh keypair technique described below.

Reduce passwords using a private/public ssh key pair

If you plan to use this, read the following:




This tutorial is nice:

:!: the below part of the document is work in progress. :!:

What is SSH PKI

SSH key pair is a form of PKI, Public Key Infrastructure. In this technology every user or machine has a pair of keys:

  • A Public key that can be shared with everyone and copied on servers
  • A Private key that should be kept secure at all times and only readable by your user

These user keys are usually stored in the user's ~/.ssh/ folder, the default names are id_rsa (private) and (public). But one can choose any location and any name.

The machine keys are usually stored in the /etc/ssh/ system folder, and they are generated at installation time by the OpenSSH scripts. They are of different kinds as they support different encryption schemas, their names being like ssh_host_<schema> (private) and ssh_host_<schema>.pub (public). In the example below, note how the private key is readable and writable ONLY by root while all the .pub ones are readable by everyone (but not writable!)

ls -ltrah /etc/ssh/ssh_host*
-rw-r--r-- 1 root root  393 mar 30  2016 /etc/ssh/
-rw------- 1 root root 1,7K mar 30  2016 /etc/ssh/ssh_host_rsa_key
-rw-r--r-- 1 root root  601 mar 30  2016 /etc/ssh/
-rw------- 1 root root  672 mar 30  2016 /etc/ssh/ssh_host_dsa_key
-rw-r--r-- 1 root root  173 mar 30  2016 /etc/ssh/
-rw------- 1 root root  227 mar 30  2016 /etc/ssh/ssh_host_ecdsa_key
-rw-r--r-- 1 root root   93 mar 30  2016 /etc/ssh/
-rw------- 1 root root  399 mar 30  2016 /etc/ssh/ssh_host_ed25519_key
-rw-r--r-- 1 root root  651 maj 10  2016 /etc/ssh/
-rw------- 1 root root  986 maj 10  2016 /etc/ssh/ssh_host_key

Every ssh pki key has a fingerprint, that is, a unique way to identify that key. You can check your machine unique fingerprint by using the ssh-keygen script provided by OpenSSH:


The overall mechanism is as follows. A user willing to connect to a server has to

  1. Copy his/her/hir public key to that server
  2. Instruct the server that such key is trustworthy by modifying the ~/.ssh/authorized_keys file
  3. run an ssh-agent on his/her/hir local machine that will take care of authenticating the user to the server when logging in. Usually this is automatically started by the ssh client if the user is using PKI.

OpenSSH on linux provides a set of scripts for managing keys:

  • ssh-keygen

:!: the above part of the document is work in progress. :!:

it_tips/ssh.1493805097.txt.gz · Last modified: 2017/05/03 11:51 by florido