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

ssh基于key认证登陆

时间:2018-01-15 11:04:25      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:ast   秘钥   key   默认   登陆   密钥对   which   服务   远程服务   

ssh基于key认证登陆

一、在客户端生成密钥对

ssh-keygen -t rsa [-P ‘‘] [-f “~/.ssh/id_rsa"]
## -r rsa:指定算法
## -P :加对称秘钥口令
## -f :可以指定生成路径
## /.ssh/id_rsa 生成秘钥默认路径

我们简单操作就不加密码了

[root@centos7 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Y9ia1CPAxegHbp767h8I5iLKCpLxuHxZxB7gfWSIkLw root@centos7
The key‘s randomart image is:
+---[RSA 2048]----+
|..o .oo          |
| o +oo.o         |
|  oo*.o          |
| E .+*.=         |
|. oooo* S        |
| B .o= = o       |
|B o.+ +          |
|Bo.o   .         |
|=o.++..          |
+----[SHA256]-----+

查看生成的公钥和私钥

[root@centos7 .ssh]#ls
id_rsa  id_rsa.pub
## id_rsa私钥
## id_rsa.pub公钥

二、把公钥文件传输至远程服务器

ssh-copy-id [-i [公钥文件]] [user@]host

如果传输时写时误传了私钥文件系统会自动转换成公钥文件传输,不用紧张
三、测试

[root@centos5 .ssh]#ssh 192.168.27.6
Last login: Sun Jan 14 17:04:42 2018 from 192.168.27.1
[root@centos6 ~]#

登陆成功

ssh基于key认证登陆

标签:ast   秘钥   key   默认   登陆   密钥对   which   服务   远程服务   

原文地址:http://blog.51cto.com/13574131/2060925

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