1.登陸root用戶
執行以下生成公私鑰對
ssh-keygen -t rsa
2.生成完成
Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub.
cd /root/.ssh
ll
看到剛生成的文件,表示成功
pwd
3.將公鑰內容導入authorized_keys文件中,並將私鑰拷貝到用來登陸服務器的終端
cat id_rsa.pub >> authorized_keys
4.修改SSH的配置文件
vi /etc/ssh/sshd_config
把以下#去掉,保存退出
#PubkeyAuthentication yes
重啟ssh
service sshd restart
5.用secureCRT或者ssh通過私鑰連接驗證,驗證正常登陸即可
6.關閉密碼登陸
vi /etc/ssh/sshd_config
PasswordAuthentication yes改為no
service sshd restart
7.驗證