主機間無需密碼基於ssh通信

node1:172.16.58.1

node2:172.16.58.3

node1--> node2


首先在node1生成祕鑰

執行命令ssh-keygen -P ''

詢問保存路徑直接回車默認即可,

後面提示私鑰保存爲/root/.ssh/id_rsa

公鑰保存爲/root/.ssh/id_rsa.pub

[root@node1 ~]# ssh-keygen -P ''

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): 

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

dc:62:ba:81:ac:dd:d9:93:fa:b4:9b:21:8d:e7:98:8c [email protected]

The key's randomart image is:

+--[ RSA 2048]----+

|                 |

|                 |

|                 |

|       . .       |

|        S .      |

|   . . = .       |

|    o = =.       |

|   o + %o+       |

|  . E OoBo       |

+-----------------+

把祕鑰傳給node2主機

ssh-copy-id -i .ssh/id_rsa.pub [email protected]

[root@node1 ~]# ssh-copy-id -i .ssh/[email protected]

The authenticity of host '172.16.58.3 (172.16.58.3)' can'tbe established.

RSA key fingerprint isdb:f8:11:fa:7d:30:95:44:1b:eb:ea:89:ee:fa:a1:27.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '172.16.58.3' (RSA) to the listof known hosts.

[email protected]'s password:

Now try logging into the machine, with "ssh'[email protected]'", and check in:

 

  .ssh/authorized_keys

 

to make sure we haven't added extra keys thatyou weren't expecting.

測試是否成功免密碼登陸,沒有提示輸入密碼

ssh 172.16.58.3 'date';date
[root@node1 ~]# ssh 172.16.58.3 'date';date

Wed Dec 31 16:51:41 CST 2014

Wed Dec 31 16:52:42 CST 2014


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章