首先在A機器上生成密鑰
$ ssh-keygen -t rsa
一路回車即可。
然後在将生成的公鑰複制到機器B上的~/.ssh/authorized_keys中,使用如下指令:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub [Buser]@[Bip]
最後,測試免密碼登入:
$ ssh [Buser]@[Bip]
如果順利OK,如果無效還提示輸入密碼,檢查以下權限:
//使用者權限
chmod 700 /home/username
//.ssh檔案夾權限
chmod 700 ~/.ssh/
// ~/.ssh/authorized_keys 檔案權限
chmod 600 ~/.ssh/authorized_keys