在服務器運維過程當中,有時爲了方便執行腳本,會設置免密碼登陸。node
固然若是這個主機被攻破,那麼其餘主機也就乖乖投降了。git
完成免密登陸,主要使用兩個命令:服務器
第一個:生成公鑰運維
ssh-keygen Generating public/private key pair. Enter file in which to save the key (/ceph-admin/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /ceph-admin/.ssh/id_rsa. Your public key has been saved in /ceph-admin/.ssh/id_rsa.pub.
tips:使用git時候,根據後臺設置,有些操做須要公鑰,此時也須要生成公鑰。ssh
默認的Windows的公鑰地址是「C:\Users\[SomeOne]\.ssh\id_rsa.pub",默認的Linux公鑰地址在「~/.ssh/id_rsa.pub」ide
第二個:把公鑰複製到其餘服務器spa
ssh-copy-id root@node1
其中node1是目標主機,能夠是ip地址,也能夠是域名。code