建立金鑰檔
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (<your-home-dir>/.ssh/id_rsa): 按 Enter
Enter passphrase (empty for no passphrase): 按 Enter
Enter same passphrase again: 按 Enter
以上指令會產生兩個檔案
chmod 0600 <your-home-dir>/.ssh/id_rsa
NOTE:將 id_rsa.pub 複製到 主機 B 。
將 id_rsa.pub 複製到 .ssh 目錄
cd ~/.ssh mv id_rsa.pub host-A-hostname.pub cat host-A-hostname.pub >> authorized_keys2
NOTE:
如果 .ssh 目錄裡沒有 authorized_keys 檔案,檔名可以不用加上 2
ssh <remote-user>:<remote-host-name>
不需要輸入密碼就可以登入。