SSH CheatSheet

To add multiple servers key fingerprint to the list of known hosts on the client:

for a in 192.168.56.{101..110}; do ssh-keyscan $a >>~/.ssh/known_hosts ; done

To add a single host:

ssh-keyscan 192.168.0.101 >>~/.ssh/known_hosts

To generate a pair of strong private (no extension) and public (.pub) keys on a client:

ssh-keygen -t ed25519 -C "[email protected]"

Alternatively, RSA which is more common, although less fast and secure (but suits for older servers – before 2014):

ssh-keygen -t rsa -b 2048 -C "[email protected]"

The public (.pub) part of the key sits (in clear text) in ~/.ssh/authorised_keys file on the server; can be placed there with:

ssh-copy-id -i key.pub [email protected]

The client uses the private part of the same key to connect to the server:

ssh -i key [email protected]

To set up a shortcut to the frequently accessed servers add the following to the $HOME/.ssh/config The server can be accessed after with the command: ssh lab1

Host lab1

        KeepAlive yes
        IdentityFile ~/.ssh/key
        HostName 192.168.56.100
        User serveradmin

The right permissions to the file are also necessary:

chown $(id -u):$(id -g) ~/.ssh/config
chmod 600 ~/.ssh/config