Automatic login on ssh
At work/home I end up logging into multiple boxes at the same time, one to manage configuration, other to tail log files and another to check db stuff and the start of the day usually begins by running the same commands over and over again and then typing the password a number of times. Looked up some info to make this less painful by not atleast having to type the password. You can do that by copying your SSH keys to the authorized_keys file of the remote server. So this is how you do it.
Generate your ssh key
1 2 3 4 5 6 7 8 9 10 11 | busybox$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/Users/luke/.ssh/id_rsa): /Users/luke/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/luke/.ssh/id_rsa. Your public key has been saved in /Users/luke/.ssh/id_rsa.pub. The key fingerprint is: b5:d6:9f:26:13:15:8r:d5:58:55:bd:8b:e6:d1:a7:61 |
Now you need to copy this across to the server where you want to be able to login automatically:
1 2 | busybox$ cat ~/.ssh/id_rsa.pub | ssh luke@enterprise-starship.local 'cat >> .ssh/authorized_keys' busybox$ password: |
Alternatively you can copy them across using the following command:
1 | busybox$ ssh-copy-id -i .ssh/id_rsa.pub luke@enterprise-starship.local |
and that’s pretty much it, you now login using your standard ssh command without having to enter your password. You can do the same for other hosts as well, just run the same command for different hosts.
Comments(0)








