iTech / Linux · 2020年2月20日

解决Debian 9/Ubuntu默认不能登录root账号

首先通过ssh登录vps主机,比如默认用户名是ubuntu

登录成功后,输入su,获取root权限,输入密码,命令行显示root账号

1、修改ssh配置文件:vim /etc/ssh/sshd_config

在#PermitRootLogin without-password  此行下新增一行:

PermitRootLogin yes

在该段的其他行前面都加上#注释掉,只保留PermitRootLogin yes这行,不然还是无法登录。

保存退出

2.重启ssh。输入命令

service sshd restart

3.搞定

针对甲骨文云平台的修改方式如下

sudo -i 切换到root模式

sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config;

sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config;

再通过passwd 修改root密码

service sshd restart