2臺centos7系統服務器,其中ip一臺128,另一臺129
使用root用戶登錄128系統
1、切換到/root/.ssh目錄,root用戶必須在該目錄下
cd /root/.ssh
2、執行以下命令後,如果提示,就一直按“Enter”鍵,直至生成公鑰
ssh-keygen -t rsa
3、上傳公鑰到129上
ssh-copy-id -i id_rsa.pub 192.168.0.129 這種方式會覆蓋之前創建的
其他方式:
scp id_rsa.pub [email protected]:/root/.ssh/authorized_keys_from_128
cat authorized_keys_from_128 >> authorized_keys 已經存在則內容追加,否則創建新文件
4、重啓129服務器ssh服務,service sshd restart
5、在128上執行ssh [email protected] 不需要密碼可以直接登錄
6、本機登錄自己免密登錄:
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys