Two linux computers ssh password-free login


http://chenlb.iteye.com/blog/211809

sh Passwordless login requires public and private keys. Under linux, you can use ssh-keygen to generate a public/private key pair. Below I take CentOS as an example.

There are machines A (192.168.1.155), B (192.168.1.181). Now I want to log in to B through ssh without password.

1. Generate a public/private key pair on the A machine.
[chenlb@A ~]$ ssh-keygen -t rsa -P ''

-P means password, -P '' means empty password, you can also do not need -P parameter, so you need three carriage return, use -P Enter once.
It generates .ssh directory under /home/chenlb with id_rsa and id_rsa.pub under .ssh.

2. Copy id_rsa.pub from computer A to computer B. In the .ssh/authorized_keys file of computer B, I use scp to copy it.
[chenlb@A ~]$ scp .ssh/id_rsa.pub [email protected]:/home/chenlb/id_rsa.pub
[email protected]'s password:
id_rsa.pub 100% 223 0.2KB/s 00:00

Since there is no password-free login yet, you need to enter a password.

3. Machine B adds the id_rsa.pub copied from machine A to the .ssh/authorzied_keys file.
[chenlb@B ~]$ cat id_rsa.pub >> .ssh/authorized_keys
[chenlb@B ~]$ chmod 600 .ssh/authorized_keys

The authority of authorized_keys should be 600.

4. Machine A logs in to machine B.
[chenlb@A ~]$ ssh 192.168.1.181
The authenticity of host '192.168.1.181 (192.168.1.181)' can't be established.
RSA key fingerprint is 00:a6:a8:87:eb:c7:40:10 :39:cc:a0:eb:50:d9:6a:5b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.181' (RSA) to the list of known hosts .
Last login: Thu Jul 3 09:53:18 2008 from chenlb
[chenlb@B ~]$

You are asked to enter yes when logging in for the first time.

Now machine A can log in to machine B without a password.

Summary: The logged-in machine can have the private key, and the logged-in machine must have the public key of the logged-in machine. This public/private key pair is generally generated on the private key host. The above is the public/private key pair using the rsa algorithm, of course, dsa can also be used (the corresponding files are id_dsa, id_dsa.pub)

If you want machines A and B to log in to each other without password, you can configure machine B in the same way as above.

Reference: Usage of SSH-KeyGenhttp://blog.163.com/chen98_2006@126/blog/static/158584272007101862513886/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326200525&siteId=291194637