More about SSH keys

tips

I’ll cover 2 topics:

  1. how to ssh without password
  2. how to setup multiple ssh keys

how to ssh without password

It’s more secure to login in through ssh keys than password. To realize this, we need to disable password login and add own ssh public key to the machine.

disable password auth

edit config sshd_config file and then disable below 2 authentications.

sudo vim /etc/ssh/sshd_config
PasswordAuthentication no
ChallengeResponseAuthentication no

service ssh restart

set SSH public key

append your SSH public key to file ~/.ssh/authorized_keys

how to setup multiple SSH keys

We may use different keys for different machines. The default key pair is id_rsa and id_rsa.pub. So what if you generate another key pair? Just 2 steps:

  1. add the path of your private key to file ~/.ssh/config in your local machine like below:

    IdentityFile ~/.ssh/id_rsa.another

  2. add paired public key to the remote machine authorized_keys file

SSH will try the key pairs one by one.