作业:配置ssh免密登陆:客户端主机通过redhat用户基于秘钥验证方式进行远程连接服务器的root用户
实现免密登录:
服务端:
#修改sshd的配置文件
[root@localhost ~]# vim /etc/ssh/sshd_config
AllowUsers root redhat
PermitRootLogin yes
#重启后生效
[root@localhost ~]# syetemctl restart sshd
客户端:
#如果没有redhat用户先创建一个
[root@localhost ~]# useradd redhat
[root@localhost ~]# id redhat
#查看 redhat 名称的用户是否存在,如果存在,则默认显示用户的相关信息。
#uid 表示的是用户的数字编号
#gid 用户组的数字编号。
#groups 表示该用户属于哪个用户组
uid=1001(redhat) gid=1001(redhat) groups=1001(redhat)
#切换到redhat用户
[root@localhost ~]# su - redhat
#创建公私钥
[redhat@localhost ~]$ ssh-keygen -t rsa
[redhat@localhost ~]$ ll /home/redhat/.ssh/
total 16
-rw-------. 1 redhat redhat 2622 Mar 13 19:19 id_rsa #私钥
-rw-r--r--. 1 redhat redhat 582 Mar 13 19:19 id_rsa.pub #公钥
-rw-------. 1 redhat redhat 843 Mar 13 19:51 known_hosts
-rw-r--r--. 1 redhat redhat 97 Mar 13 19:27 known_hosts.old
#将公钥发给要免密登录的用户
[redhat@localhost ~]$ ssh-copy-id root@192.168.174.130
#免密登录成功
[redhat@localhost ~]$ ssh root@192.168.174.130
Web console: https://localhost:9090/ or https://192.168.174.130:9090/
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: Tue Mar 14 20:04:55 2023 from 192.168.174.131
[root@localhost ~]#