Ubuntu中开启root用户ssh远程登录
1.将用户和Shell环境一起切换成root身份
su - root
2.编辑sshd_config文件
vi /etc/ssh/sshd_config
3.修改配置
默认的Authentication区块
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
修改为以下
# Authentication:
LoginGraceTime 120
#PermitRootLogin prohibit-password
PermitRootLogin yes
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
4.重启SSH服务
systemctl restart sshd.service
5.24.04及一些新版本中的操作
sudo nano /etc/ssh/sshd_config.d/50-vm-root-login.conf
########################################
# Ubuntu Server VM - Simple SSH Config
########################################
Protocol 2
Port 22
# 允许 root 登录(仅限虚拟机 / 本地环境)
PermitRootLogin yes
# 建议:root 只能用密钥登录(更安全)
PubkeyAuthentication yes
PasswordAuthentication yes
# 如你想更安全,可改成:
# PasswordAuthentication no
# PAM 必须开启,否则登录可能异常
UsePAM yes
# 登录体验
LoginGraceTime 30
MaxAuthTries 6
PrintMotd no
# 保持连接,防止虚拟机休眠断线
ClientAliveInterval 300
ClientAliveCountMax 3
# 不折腾人的默认值
AllowTcpForwarding yes
X11Forwarding no
########################################
# End
########################################

浙公网安备 33010602011771号