|
Sometimes you want to jump from one server to another without entering the password. What you have to do is called "key exchange". Although this is very easy to set up many people don't know how to do this. This is a very straight forward copy/paste tutorial about how to exchange ssh keys.
Situation: You want to be able to ssh from servera to serverb (and vice versa) without entering a password
Step 1: create your public and private keys on server A (servera)
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/madmadmod/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/madmadmod/.ssh/id_rsa. Your public key has been saved in /home/madmadmod/.ssh/id_rsa.pub. The key fingerprint is: 9f:e5:a7:12:46:69:52:34:63:ff:3b:8c:39:74:cd:be madmadmod@servera
--> do not enter a passphrase (just press enter)
Step 2: do the same on server B (serverb)
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/madmadmod/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/madmadmod/.ssh/id_rsa. Your public key has been saved in /home/madmadmod/.ssh/id_rsa.pub. The key fingerprint is: 3f:e5:a7:12:46:69:52:34:63:ff:3b:8c:29:14:cd:be madmadmod@serverb
--> do not enter a passphrase (just press enter)
Step 3: Exchange the public keys copy the public key from /home/username/.ssh/id_rsa.pub from servera to a file called /home/username/.ssh/authorized_keys2 on serverb. You can do this manualy (copy+paste) or with the following command:
#cat ~/.ssh/*.pub | ssh madmadmod@serverb 'umask 077; cat >>/home/madmadmod/.ssh/authorized_keys2'
and now do the same with the public key from server b: #cat ~/.ssh/*.pub | ssh madmadmod@servera 'umask 077; cat >>/home/madmadmod/.ssh/authorized_keys2'
|
can it do multiple server exchange public key? how to do it? insert a new line content of id_rsa.pub into authorized_keys2 file?
Thanks