在 CentOS 上开启 SSH 并使用 root 登录,一般包含以下几个步骤(以 CentOS 7 / 8 / Stream 为例):
rpm -qa | grep openssh-server
如果没有输出,安装:
yum install -y openssh-server
systemctl start sshd
systemctl enable sshd
确认状态:
systemctl status sshd
vi /etc/ssh/sshd_config
找到以下配置(可能被注释):
#PermitRootLogin prohibit-password
修改为:
PermitRootLogin yes
⚠️ 如果是 CentOS 默认,可能是:
PermitRootLogin no
PasswordAuthentication yes
systemctl restart sshd
firewall-cmd --permanent --add-service=ssh
firewall-cmd --reload
查看:
getenforce
如果是 Enforcing,一般无需改动。
从另一台机器:
ssh root@服务器IP
sudo如需要,我可以帮你配置 密钥登录 + 禁用密码 + 禁止 root 登录 的安全方案。