Linux設置密鑰登陸及關閉密碼登陸


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.驗證


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM