本文最后更新于122 天前,其中的信息可能已经过时,如有错误请发送邮件到marcelozoeng@qq.com
问题说明
在安装好Ubuntu Server后,SSH无法使用root账号登录
解决思路
Ubuntu默认安装的openssh-server软件所用的配置是不允许root账号登录的,所以手动改一下配置文件就行了
解决方法
1.编辑SSH配置文件
sudo vi /etc/ssh/sshd_config
2.修改配置
找到文件中的PermitRootLogin这一行,修改值为yes,即可使用密码登录root用户
PermitRootLogin参数
yes:允许root用户通过SSH登录。
without-password:允许root用户通过密码认证登录,但不推荐这样做,因为它降低了安全性。
prohibit-password:仅允许root用户通过密钥认证(即使用SSH密钥)登录,这是更安全的选择。
# systemctl daemon-reload
# systemctl restart ssh.socket
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes #修改处
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
3.重启SSH服务
sudo systemctl restart sshd