Linux REHL9系ssh直接登录root
早期的 RHEL
系列发行版能直接使用 ssh
登录工具登录 root
用户。
RHEL9
后就不能直接使用 ssh 登录 root 用户了,需要先登录普通用户,然后基于普通用户再 su root
切换到 root。
root不能直接登录
[root@server ~]# cat /etc/redhat-release
Rocky Linux release 9.4 (Blue Onyx)
root用户不能直接登录实例:
login as: root
root@192.168.10.132's password:
Access denied
root@192.168.10.132's password:
Access denied
这需要普通用户的登录:
login as: hp
hp@192.168.10.132's password:
┌──────────────────────────────────────────────────────────────────────┐
│ • MobaXterm Personal Edition v23.1 • │
│ (SSH client, X server and network tools) │
│ │
│ ⮞ SSH session to hp@192.168.10.132 │
│ • Direct SSH : ✓ │
│ • SSH compression : ✓ │
│ • SSH-browser : ✓ │
│ • X11-forwarding : ✗ (disabled or not supported by server) │
│ │
│ ⮞ For more info, ctrl+click on help or visit our website. │
└──────────────────────────────────────────────────────────────────────┘
Last login: Thu Aug 15 09:30:25 2024 from 192.168.10.1
[hp@server ~]$
修改文件让root用户在ssh中直接登录
当非要用 root 来登录的时候需要修改文件。在 /etc/ssh/sshd_config
中末尾添加 PermitRootLogin yes
。
[hp@server ~]$ su root
Password:
[root@server hp]# vi /etc/ssh/sshd_config
--snip--
127 # X11Forwarding no
128 # AllowTcpForwarding no
129 # PermitTTY no
130 # ForceCommand cvs server
131
132 PermitRootLogin yes
:set nu
现在root又能够直接登录了。
login as: root
root@192.168.10.132's password:
┌──────────────────────────────────────────────────────────────────────┐
│ • MobaXterm Personal Edition v23.1 • │
│ (SSH client, X server and network tools) │
│ │
│ ⮞ SSH session to root@192.168.10.132 │
│ • Direct SSH : ✓ │
│ • SSH compression : ✓ │
│ • SSH-browser : ✓ │
│ • X11-forwarding : ✗ (disabled or not supported by server) │
│ │
│ ⮞ For more info, ctrl+click on help or visit our website. │
└──────────────────────────────────────────────────────────────────────┘
Last login: Thu Aug 15 10:07:10 2024
[root@server ~]#