项目要求
一.配置两台主机
主机1.
主机名: server.example.com
ip: 172.25.254.100
建立用户timinglee,其密码为timinglee
主机2
主机名:client.example.com
ip: 172.25.254.200
二.安需求完成项目
172.25.254.200 在远程登录172.25.254.100的root用户时需要免密连接
并确保只有root用户和timinglee用户可以被登录
代码实现
配置服务器
[root@sever100 ~]# hostnamectl hostname server.example.com
[root@server ~]# hostname
server.example.com
[root@server ~]# passwd timinglee
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl status firewalld
配置客户端
[root@sever200 ~]# hostnamectl hostname client.example.com
[root@client ~]#systemctl stop firewalld
[root@client ~]# systemctl status firewalld
[root@client ~]# ssh-keygen --------非对称加密
[root@client ~]# cd /root/.ssh/
[root@client .ssh]# ls
id_rsa id_rsa.pub known_hosts known_hosts.old
[root@client .ssh]# ssh-copy-id -i id_rsa.pub root@172.25.254.100
[root@server ~]# cd /root/.ssh
[root@server .ssh]# ls
authorized_keys known_hosts known_hosts.old
[root@server home]# vim /etc/ssh/sshd_config -------在服务器上配置sshd服务白名单
AllowUsers timinglee root
[root@server home]# systemctl restart sshd.service -----注意修改配置后一定要重启服务
测试
[root@client .ssh]# ssh -l root 172.25.254.100
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Sat Apr 20 17:03:54 2024 from 172.25.254.1
[root@server ~]#
[root@server ~]# exit
注销
Connection to 172.25.254.100 closed. ----------------------root身份在白名单内所以正常访问
[root@client .ssh]#
[root@client ~]# ssh -l yuraytao 172.25.254.100
yuraytao@172.25.254.100's password:
Permission denied, please try again.---------------------------yuraytao身份不在白名单内,权限被拒绝
由于水平有限,文中错误之处在所难免,恳请大佬不吝赐教!