建立金鑰檔
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 時都會提示要輸入。
指令一:從主機 A 上執行
ssh-copy-id user@remote-host-ip or ssh-copy-id -f -i $HOME/.ssh/id_rsa.pub user@remote-host-ip
指令二:從主機 A 上執行
cat ~/.ssh/id_rsa.pub | ssh user@remote-host-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
從主機 B 上執行,以手動方式複製:
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
從主機 A 上執行
ssh <remote-userB>@<remote-hostB-name>
不需要輸入密碼就可以登入。
Images 0 | ||
---|---|---|
No images to display in the gallery. |