码迷,mamicode.com
首页 > 其他好文 > 详细

密钥对登陆

时间:2016-05-13 05:16:19      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:服务器   输入密码   enter   

客户端ip:192.168.1.129

服务器ip:192.168.1.130

第一步 客户端生成密钥对

#ssh-keygen -t rsa

Enter file in which to save the key (/root/.ssh/id_rsa):

表示密钥保存位置默认:/root/.ssh/id_rsa 直接 enter键 默认

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

这表示输入密码  ,可以直接enter键

技术分享

[root@lnmp ~]# cd /root/.ssh/

技术分享

id_rsa是私钥,id_rsa.pub是公钥

[root@lnmp ~]#scp id_rsa.pub root@192.168.1.130:/tmp/

将公钥上传到服务器端

技术分享

第二步 服务器端配置

[root@mysql ~]# cd /tmp/

查看一下是否上传成功

技术分享

[root@mysql tmp]# mkdir /root/.ssh

[root@mysql tmp]# chmod 700 /root/.ssh/

技术分享

[root@mysql tmp]# cd /root/.ssh/

[root@mysql .ssh]# touch authorized_keys

技术分享

[root@mysql .ssh]# cat /tmp/id_rsa.pub >> authorized_keys

把公钥追加到密钥文件中,然后验证一下

技术分享

关键的一步  

[root@mysql ~]# chmod 600 /root/.ssh/authorized_keys

技术分享

修改配置文件

RSAAuthentication yes                      rsa验证

PubkeyAuthentication yes                 密钥验证

AuthorizedKeysFile      .ssh/authorized_keys            密钥位置

修改前:

技术分享

修改后

技术分享

把密码验证也关掉

技术分享

重启一下ssh服务

[root@mysql ~]# /etc/init.d/sshd restart

验证一下 ,没有提示输入密码说明配置成功

技术分享


密钥对登陆

标签:服务器   输入密码   enter   

原文地址:http://dongxin.blog.51cto.com/3486403/1772557

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!