Ubuntu 22.04 SSH 设置

允许 root ssh 登录

# 给 root 设置密码
passwd root

# 修改配置
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori

vi /etc/ssh/sshd_config
PermitRootLogin yes

# 重启 sshd 服务
systemctl restart sshd

开启秘钥认证和关闭密码认证

注意事项,可以先开启秘钥认证,秘钥认证成功后再关闭密码认证,以防秘钥认证失败无法使用密码登录

vi /etc/ssh/sshd_config
# 修改下面
PubkeyAuthentication yes
PasswordAuthentication yes # !!! 秘钥认证成功后再改成 no,关闭密码认证

# 在最后添加
PubkeyAcceptedAlgorithms +ssh-rsa

# 确保 /etc/ssh/sshd_config.d/*.conf 下没有额外的配置,有则删除

# 重启 sshd 服务
systemctl restart sshd
posted @ 2023-06-15 11:42  klvchen  阅读(1048)  评论(0编辑  收藏  举报