甲骨文开启 root密码远程登录命令合集
# Ubuntu 启用 root 用户密码登录 SSH
以下是一份整合后的完整操作流程,可以直接复制执行:
```bash
# 1. 切换 root
sudo -i
# 2. 设置 root 密码(需要手动输入两次)
passwd
# 3. 写入优先级最高的配置文件,强制允许 root + 密码登录
cat > /etc/ssh/sshd_config.d/99-root-pass.conf <<'EOF'
PermitRootLogin yes
PasswordAuthentication yes
EOF
# 4. 注释掉 cloud-init 里的 PasswordAuthentication no,避免冲突
sed -i 's/^\s*PasswordAuthentication\s\+no/# &/' /etc/ssh/sshd_config.d/60-cloudimg-settings.conf
# 5. 检查配置是否正确(无输出代表没问题)
sshd -t
# 6. 重启 ssh 服务(Ubuntu 用 ssh,不是 sshd)
systemctl restart ssh
# 7. 再次确认最终配置是否生效(yes 表示成功)
sshd -T | egrep 'passwordauthentication|permitrootlogin|usepam'
改密码后的一条命令
echo -e "PermitRootLogin yes\nPasswordAuthentication yes" > /etc/ssh/sshd_config.d/99-root-pass.conf && sed -i 's/^\s*PasswordAuthentication\s\+no/# &/' /etc/ssh/sshd_config.d/60-cloudimg-settings.conf && sshd -t && systemctl restart ssh && sshd -T | egrep 'passwordauthentication|permitrootlogin|usepam'
关闭系统防火墙
# 开放所有端口 iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F
2、CentOS
# 删除多余附件
systemctl stop oracle-cloud-agent
systemctl disable oracle-cloud-agent
systemctl stop oracle-cloud-agent-updater
systemctl disable oracle-cloud-agent-updater
# 关闭防火墙并禁止自启动
systemctl stop firewalld.service
systemctl disable firewalld.service