配置ntp时间服务器,确保客户端主机能和服务主机同步时间:
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http:www.pool.ntp.org/join.html)
#pool 2.rhel.pool.ntp.org iburst
Server ntp.aliyun.com iburst
allow 192.168.59.128/24
配置ssh免密登陆:客户端主机通过redhat用户基于秘钥验证方式进行远程连接服务器的root用户
1.查看root用户ip
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:b9:db:f1 brd ff:ff:ff:ff:ff:ff
inet 192.168.59.128/24 brd 192.168.59.255 scope global dynamic noprefixroute ens160
valid_lft 1778sec preferred_lft 1778sec
inet6 fe80::20c:29ff:feb9:dbf1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:a4:02:2f brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:a4:02:2f brd ff:ff:ff:ff:ff:ff
2.创密钥
[redhat@localhost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/redhat/.ssh/id_rsa):
Created directory '/home/redhat/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/redhat/.ssh/id_rsa.
Your public key has been saved in /home/redhat/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:tTfInf/Ic4CDeV6q1QOp3WscOe18ZQ65HT/P+8YY9Sw redhat@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| |
| |
| . |
| o + o .|
| S +oB. *.|
| o++*E.*|
| .oo==^+|
| .o.*B@|
| .. .+=@|
+----[SHA256]-----+
3.查看密钥
[redhat@localhost ~]$ ll /home/redhat/.ssh
total 8
-rw-------. 1 redhat redhat 2622 Mar 16 21:07 id_rsa
-rw-r--r--. 1 redhat redhat 582 Mar 16 21:07 id_rsa.pub
4.传密钥给服务器root用户:
[redhat@localhost ~]$ ssh-copy-id root@192.168.59.128
5.远程连接root
[redhat@localhost ~]$ ssh 'root@192.168.59.128'
Activate the web console with: systemctl enable --now cockpit.socket
This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register
Last login: Thu Mar 16 21:16:08 2023
[root@localhost ~]#