背景
由于Ubuntu自身问题,默认不支持使用root用户登陆ssh,个人使用习惯问题,这里记录修改方案,但存在安全隐患自己衡量.
环境
系统:Ubuntu Server 22.04
设置
1.给root用户添加一个密码
sudo passwd root
2.在sshd_config配置参数
sudo vim /etc/ssh/sshd_config
找到以下行
#PermitRootLogin prohibit-password
将其更改为
PermitRootLogin yes
确保以下行也存在,将 PasswordAuthentication
设置为 no
可以增强安全性,但这意味着你将不能通过密码登录 SSH
PasswordAuthentication no
3.给root用户使用密钥登陆,将pub密钥复制root目录下的
sudo vim ~/.ssh/authorized_keys
4.禁用公钥认证,确保密码登录已启用
PubkeyAuthentication no
PasswordAuthentication yes
5.重启 SSH 服务以应用更改
sudo systemctl restart ssh
评论区