centos ssh password-free key login

Assuming that you log in to host B via ssh from host A, and replace the password with the secret key, the steps are as follows:



1. Execute on host A: ssh-keygen -t rsa

    everything is default, no password is required, and two files are generated:

     /root/.ssh/ id_rsa

     /root/.ssh/id_rsa.pub



2. Generate authorized_keys file:

touch /root/.ssh/authorized_keys

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

chmod 700 /root/.ssh /id_rsa



3. Copy the authorized_keys file to host B:

scp /root/.ssh/authorized_keys [email protected]:/root/.ssh/

If there is no /root/.ssh directory on host B, then Log in to host B and execute ssh-keygen -t rsa, and then copy the authorized_keys file.



4. Completed



5. If the IP of a certain host is adjusted in the future, and the following error occurs during SSH, you can perform it again according to the previous operation.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
a0:70:17:12:e3:3c:ed:ae:1c:2b:b7:2a:10:c7:bf:8f.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:8
ECDSA host key for 10.2.169.48 has changed and you have requested strict checking.
Host key verification failed.

参考: http://www.cnblogs.com/lavezhang/p/5533294.html

Guess you like

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