ssh基于key认证登陆

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 ~]#

登陆成功

转载于:https://blog.51cto.com/13574131/2060925

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值