centos7实现免密登录

2020-07-13  本文已影响0人  邹智敏

Centos7 默认安装了 ssh服务

# 查看 ssh 状态
systemctl status sshd
# 启动 ssh
systemctl start sshd
# 停止 ssh
systemctl stop sshd

生成公钥和私钥,遇到提示直接敲回车即可

CentOS7 默认使用RSA加密算法生成密钥对,保存在~/.ssh目录下的id_rsa(私钥)和id_rsa.pub(公钥)。也可以使用“-t DSA”参数指定为DSA算法,对应文件为id_dsa和id_dsa.pub,密钥对生成过程会提示输入私钥加密密码,可以直接回车不使用密码保护。

[root@10-35-6-181 ~]# 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:KpNHEVPD6ChX1yHARZ46FSjy88cO8ri843vDnTCzO3c root@10-35-6-181
The key's randomart image is:
+---[RSA 2048]----+
|     .+OB...     |
|  . . =+o=.      |
|   o =..+        |
|  . = .+         |
|   o o+.S        |
|    .o*oo        |
|    +=oX .       |
|   .o+B = E      |
|   .**.= .       |
+----[SHA256]-----+
[root@10-35-6-181 ~]# ls ~/.ssh/
authorized_keys  id_rsa  id_rsa.pub

在需要免密登录的服务器中的~/.ssh/authorized_keys文件里面追加,id_rsa.pub(公钥) 里面的内容

centos7禁用密码登录方法

编辑/etc/ssh/sshd_config

将PasswordAuthentication参数值修改为no: PasswordAuthentication no

重启ssh服务:systemctl restart sshd.service

上一篇 下一篇

猜你喜欢

热点阅读