linux 禁用密碼登陸 啟用ssh key登陸 配置


1.在服務器上執行

#ssh-keygen -t rsa -C 793413226@qq.com

輸入文件名(如xxxx)和私鑰密碼,並二次確認

會生成2個文件:xxxx,xxxx.pub

將公鑰寫入/root/.ssh/authorized_keys文件,將私鑰xxxx下載到本地留作登陸使用

#cat xxxx.pub >> /root/.ssh/authorized_keys

修改配置 其實centos7.4及之后的版本只要關閉密碼登錄就好了,因為秘鑰文件登錄是默認打開的

#vim /etc/ssh/sshd_config

#禁用密碼驗證
PasswordAuthentication no
#啟用密鑰驗證
RSAAuthentication yes #centos 7.4及之后的版本不用加這個 PubkeyAuthentication yes #centos 7.4及之后是默認開啟的

 保存並重啟sshd

#service sshd restart #centos系統

/**************************************************

ssh-keygen -t rsa -C 793413226@qq.com

[root@wzj home]# ssh-keygen -t rsa -C 793413226@qq.com
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): wzjroot
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in wzjroot.
Your public key has been saved in wzjroot.pub.
The key fingerprint is:
SHA256:P0PVjNZ5yw523CXeD+0nFwstCXeuLyr+d2f8rNknLrw 793413226@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| = . |
| .+.*.o|
| oo.B=+|
| S . *oO+|
| o . Bo+|
| +. ..+=|
| . ooooB*|
| ..ooE+*=B|
+----[SHA256]-----+

**************************************************/

 


免責聲明!

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



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