解决云服务器实例(Ubuntu16.04)使用秘钥对使普通用户无法登陆的问题

问题是怎么出现的:

  1. 阿里云服务器在使用秘钥对登陆后,阿里云会自动将密码登录给禁用
  2. 然而,云服务器的一个实例只能绑定一个秘钥对;
  3. 系统默认为root用户,当使用了秘钥对登陆后,再想使用普通用户登录已经无法实现了;
#编辑 /etc/ssh/sshd_config 文件,进行如下设置:
vim /etc/ssh/sshd_config

在打开的sshd_config文件中可以看到PasswordAuthentication被改为了no,如下所示:

PasswordAuthentication no

怎么解决:

  1. 进入root用户;
  2. ​ 创建普通用户;
  3. ​ 编辑 /etc/ssh/sshd_config 文件,进行如下设置:

vim /etc/ssh/sshd_config

RSAAuthentication no
PubkeyAuthentication no
#此操作为关闭秘钥对登陆,若将no改为yes则是打开秘钥登陆

另外,请留意 root 用户能否通过 SSH 登录:

PermitRootLogin yes

当你完成全部设置,再打开密码登录:

PasswordAuthentication yes

最后,重启 SSH 服务:

service sshd restart

给普通用户添加sudo权限:

vim /etc/sudoers

进入文件后好找到root用户的配置,在root用户的配置下为普通用户添加与root用户一样的配置,如下所示:

root ALL=(ALL) ALL 
test ALL=(ALL) ALL #(test为你所添加的普通用户的用户名)

猜你喜欢

转载自blog.csdn.net/Keep_on_Growing/article/details/81139574