###场景: 被登录服务器:A 本地客户端:B
###被登录服务器A操作: ####1、A开启免密登录功能
vim /etc/ssh/sshd_config
如下三行注释去掉
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
####2、重启ssh服务
service sshd restart
####3、创建必要文件
mkdir /root/.ssh/
touch /root/.ssh/authorized_keys
chmod 700 /root/.ssh/
chmod 600 /root/.ssh/authorized_keys
###本地客户端B操作 ####1、生成公钥
ssh-keygen
后续直接一路回车
####2、查看公钥
[root@Linux ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxuwX47YOe1ym8mE5lL8//zo6A41EqAPYPcoqIMa+DGr/ElxY4hxpP9hcTb/iqYMmalfQzSt1HOeDlE56kxH5Q5rNaQxh/esbp7C5IZmiJc17WBCbbmrzRSjY+uzz6iKXFEqwrwqeqrt5Inlyoy43XVkP5yaibKKLpXK9hFGT2ZA3nHJ5X3bwaVBkYGF/+f/haBNJk/GiwYumj62Wap1rzOyJ7m8N123123wqrrHongebnBtwqWeNUoc+84Ej337oHxHRdl4GoMyDxWQLGDAiQWP+s/bm12T9PG0AHqkzX4aooXUWLMY6z4uVgGWvhcl66rqwq44fqwrqwri3IHmQ== root@Linux
####3、复制id_rsa.pub内内容
将内容粘贴至服务器A的/root/.ssh/authorized_keys
###未生效问题: 1、.ssh和authorized_keys权限不对:
chmod 700 /root/.ssh/
chmod 600 /root/.ssh/authorized_keys
2、selinux问题
方法一:在A端关闭selinux<不妥>
方法二:单独设置目录的sebool:restorecon -r -vv /root/.ssh
评论区