SSH passwordless login configuration

SSH passwordless login configuration

Environment:
VMware 16
virtual machine: centos7_x64
Network: NAT

configuration steps

Prepare two virtual machines:
ip address: 192.168.174.129, 192.168.174.130
The ip address can be viewed with ip addr, and the command needs to use yum to install net-tools

## 虚拟机A操作
#cd当前用户的根目录
cd ~
# 如果没有.ssh目录
mkdir .ssh
cd .ssh/
ssh-keygen -t rsa  # 生成过程一路回车即可
ll  # 查看.ssh目录 应当至少有rsa_id , rsa_id.pub 文件

# 将公钥传给虚拟机B
ssh-copy-id [email protected]

# 下面操作需要root权限,如果你不是root用户需要su root或者当前用户有sudo权限
# 配置sshd_config 文件
vim /etc/ssh/sshd_config

## ---------几个重要的参数 
HostKey /root/.ssh/id_rsa  #添加 HostKey为id_rsa文件的绝对路径  
PubkeyAuthentication yes   #修改 启动公钥验证
AuthorizedKeysFile    .ssh/authorized_keys  #这个不用管,它会根据你当前的用户去找验证文件
PermitEmptyPasswords yes   #修改 允许空密码 在登陆时,就可以直接ssh 192.168.174.xxx 而不需要再输入密码
#PasswordAuthentication no  默认配置 注释掉

# 保存修改后, 重启ssh服务
service sshd restart
# 修改.ssh目录读写权限, 不修改系统会认为不够安全不会启用该密钥
chmod 600 ~/.ssh

General meaning:
insert image description here

Login instructions

Login format
ssh ip: ssh 192.168.174.129
By default, you will find the login user according to your current user, and find the verification file on the corresponding user, such as A:root–>B:root:
ssh user@ipssh [email protected]
Specify the login user, in the specified The user finds the verification file on the

Guess you like

Origin blog.csdn.net/qq_29757633/article/details/109011108