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.验证

posted @ 2020-11-25 11:43  时间会有答案  阅读(1099)  评论(0编辑  收藏  举报