切換到使用者home目錄,比如當前使用者目錄
cd ~/.ssh/
生成秘鑰
ssh-keygen -t rsa
提示輸入秘鑰通訊密碼,如果不需要密碼可以自己回車,預設空密碼
提示生成私鑰檔案id_rsa和公鑰檔案id_rsa.pub
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
寫入公鑰到authorized_keys
cat id_rsa.pub >> authorized_keys
設定秘鑰檔案和目錄許可權
chmod 600 authorized_keys
chmod 700 ~/.ssh
配置sshd,開啟秘鑰登入選項
vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
重啟sshd服務
systemctl restart sshd
下載私鑰檔案id_rsa,這個私鑰檔案可用於ssh客戶端連線,配置好ssh客戶端完成聯通測試。測試透過,配置sshd,禁用密碼登入選項
vim /etc/ssh/sshd_config
PasswordAuthentication no
重啟sshd服務
systemctl restart sshd
配置ssh命令使用pem秘鑰登入