Ubuntu无法使用root用户登录解决方法
当尝试以 root 用户远程登录 Ubuntu 时,若出现提示,可按本文步骤修复。
当尝试以root用户远程登录Ubuntu时,提示如下错误信息:
Please login as the user "ubuntu" rather than the user "root"解决方案: 一、编辑SSH配置文件
打开SSH配置文件:
sudo vim /etc/ssh/sshd_config修改以下设置:
#启用密码认证
PasswordAuthentication yes
#允许root用户登录
PermitRootLogin yes
#禁用PAM认证
UsePAM no保存并退出编辑后,重启SSH服务:
sudo service ssh restart二、编辑authorized_keys文件
打开authorized_keys文件
sudo vim /root/.ssh/authorized_keys删除ssh-rsa行前面的所有内容
例如:
no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10;exit 142"其中,命令含义如下:
no-port-forwarding:禁止TCP转发。 no-agent-forwarding:禁止身份验证代理转发。 no-X11-forwarding:禁止X11转发。 command="echo '...'":显示提示信息并终止会话。
三、重新登录 完成上述设置后,重新尝试使用root用户登录。如果依然无法登录,可以尝试重启实例。
这样就可以解决Ubuntu无法使用root用户登录的问题了。