建立金鑰檔
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 。
如果有設定 passphrase,在每次登入遠端 SSH 時都會提示要輸入。
將 id_rsa.pub 複製到 .ssh 目錄
cd ~/.ssh mv id_rsa.pub host-A-hostname.pub cat host-A-hostname.pub >> authorized_keys chmod 0700 ~/.ssh chmod 0640 authorized_keys
NOTE:
如果 .ssh 目錄裡已經有 authorized_keys 檔案,可以另存一個檔名加上 2,例如 authorized_keys2
ssh <remote-userA>@<remote-hostA-name>
不需要輸入密碼就可以登入。