Remember that Professor Chan had taught me the approach how to be able to ssh or scp from a host to a server without supplying the password in the lab class. But I had no time to try it, so I thought it is not easy. Today I began to study the diagram he gave us, read Jayakara Kini’s blog, and do the test on Fedora 10, I found in fact it is very easy.
I suppose my machine A is a server and B is a client. On machine B, I create a public and private key pair, send the public key file to machine A, append its contents to the file authorized_keys of the server (Machine A). That’s it!
On client side (Machine B)
1. Generate the public and private key pair.
[joker@b ~]$ ssh-keygen –t rsa
Generating publice/private rsa key pair.
Enter file in which to save the key (/home/joker/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/joker/.ssh/id_rsa.
Your public key has been saved in /home/joker/.ssh/id_rsa.pub.
The key fingerprint is:
The key’s randomart image is:
2. Transfer the public key to the server (Machine A)
[joker@b ~]$ scp ~/.ssh/id_rsa.pub firstname.lastname@example.org:.ssh/id_rsa.pub-hostb
3. Append the contents of the public key to the file authorized_keys of the server (Machine A)
[joker@b ~]$ ssh email@example.com
[joker@a ~]$ cd .ssh
[joker@a ~]$ cat id_rsa.pub-hostb >> authorized_keys
[joker@a ~]$ chmod 600 authorized_keys
Logout and return machine B, try to use ssh or scp command, the system didn’t ask me the password anymore.
Finally, I think the diagram of Prof. Chan’s and Jayakara’s blog is worth reading for more understanding. I list the links as below.