Ubuntu无法使用root用户登陆

问题:

以root用户远程登陆ubuntu提示:
Please login as the user "ubuntu" rather than the user "root"

解决办法

一、编辑ssh登录方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#编辑SSH文件 
sudo vim /etc/ssh/sshd_config

#密码认证改为 yes
PasswordAuthentication yes

#root登陆许可改为 yes
PermitRootLogin yes

#PAM认证改为 no
UsePAM no

#重启SSH服务
service ssh restart

二、再编辑authorized_keys文件:

1
2
3
4
5
#打开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"

内容命令描述

1
2
3
4
5
6
7
8
#当此密钥用于身份验证时禁止TCP转发
no-port-forwarding
#使用此密钥进行身份验证时,禁止身份验证代理转发
no-agent-forwarding
#当此密钥用于认证时禁止X11转发
no-X11-forwarding
#用户提供的命令(如果有)被忽略
command="echo "'Please login as the user \"ubuntu\" rather than the user \"root\".'

三、重新登陆:

完成所有的设置之后,重新使用root用户登陆(如果还是不行,重启实例)

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!