centos 密钥登陆

Posted yunweiweb

tags:

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

服务端生成密钥和公钥

ssh-keygen -t rsa

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:/gGrlDJN5euMS5aai5feBkEI/0WjEnzPzx1xGtdkKG4 root@localhost.localdomain
The keys randomart image is:
+---[RSA 2048]----+
|.o..  o      +o  |
| .o.oo .  + +..  |
|  oo.o. .. B     |
|   o..oo  E      |
|    ...oSo .     |
|    .o +o+.      |
|    ooB + .      |
|   .oX.= . .     |
|  .o=o=.o .      |
+----[SHA256]-----+

创建authorized_keys存储公钥

touch /root/.ssh/authorized_keys

把公钥写入authorized_key

cat id_rsa.pub > authorized_keys

修改权限

chmod 700 /root/.ssh

chmod 600 /root/.ssh/authorized_keys

修改/etc/ssh/sshd_config

RSAAuthentication yes # 开启密钥登入的认证方式
PubkeyAuthentication yes # 开启密钥登入的认证方式
PasswordAuthentication no #禁用密码登陆

重启sshd,然后建议用xshell登陆测试

以上是关于centos 密钥登陆的主要内容,如果未能解决你的问题,请参考以下文章

centos 实现免密钥登陆

CentOS SSH密钥登陆改为密码登陆 (Conoha)

CentOS 7.x 通过密钥登陆SSH

使用密钥登录CentOS系统(基于密钥的认证)

Hapoop 搭建 设置虚拟机SSH无密钥登陆

centos 秘钥登陆配置