ssh基于key认证登陆

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ssh基于key认证登陆相关的知识,希望对你有一定的参考价值。

ssh基于key认证登陆

一、在客户端生成密钥对

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

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

[[email protected] .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 [email protected]
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]-----+

查看生成的公钥和私钥

[[email protected] .ssh]#ls
id_rsa  id_rsa.pub
## id_rsa私钥
## id_rsa.pub公钥

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

ssh-copy-id [-i [公钥文件]] [[email protected]]host

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

[[email protected] .ssh]#ssh 192.168.27.6
Last login: Sun Jan 14 17:04:42 2018 from 192.168.27.1
[[email protected] ~]#

登陆成功

以上是关于ssh基于key认证登陆的主要内容,如果未能解决你的问题,请参考以下文章

ssh客户端及基于key登陆

通过SSH,使用Public-Key Infrastructure (PKI)认证,怎么配置登陆Linux服务器

Ubuntu为账户提供public key认证登陆

ssh以及ssh的key认证

SSH用法

ssh-key关于authorized_keys电脑与linux互相认证