三步實現(xiàn)SSH無密碼登錄

  • ssh-keygen 產(chǎn)生公鑰與私鑰對
  • ssh-copy-id 將本機(jī)的公鑰復(fù)制到遠(yuǎn)程機(jī)器的authorized_keys文件中

本地生成公私鑰

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/daodao/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/chengang/.ssh/id_rsa.
Your public key has been saved in /home/chengang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RymhT9wC+nuQHe9v6e9rSAUYQIxKuKbrEF1tAVWGiwY chengang@chengang-vm
The key's randomart image is:
+---[RSA 2048]----+
|   ..o+**..o     |
|  E .oo*.o...    |
|   +oo+.* +  .   |
| .o.+o.= *    .  |
|.o..  + S o  .   |
|..     o o  .    |
|..    . . .. o   |
|o      .   .+ .  |
|..         oo++. |
+----[SHA256]-----+

用ssh-copy-id將公鑰復(fù)制到遠(yuǎn)程機(jī)器中

$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.10.4.76
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/daodao/.ssh/id_rsa.pub"
The authenticity of host '10.10.4.76 (10.10.4.76)' can't be established.
RSA key fingerprint is SHA256:BERyt3qqK2giIkBJw0Nny1dEaKWdKxYGlF9rp6b9rT0.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.10.4.76's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@10.10.4.76'"
and check to make sure that only the key(s) you wanted were added.

登錄到遠(yuǎn)程機(jī)器(不用輸入密碼)

$ ssh root@10.10.4.76
Last login: Fri Sep 30 2016 from 10.10.4.77
[root@localhost ~]# who
root     pts/0        2016-09-30 13:02 (10.10.4.77)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容