美文网首页AWS
【填坑】AWS Ubuntu 下 root 的创建&登录

【填坑】AWS Ubuntu 下 root 的创建&登录

作者: peony007 | 来源:发表于2017-09-04 20:10 被阅读21次

常规

  • 使用key密匙登录服务器
    你选择的实例操作系统名作为初始登录用户名。
  • 设置或者更改root密码
sudo passwd root
Changing password for user root.
New password: 
Retype new password: 
  • 更改/etc/ssh/sshd_config 配置
sudo vim /etc/ssh/sshd_config 

::去掉以下两项的注释
PermitRootLogin yes 
PasswordAuthentication yes 
  • 重启ssh 服务
 sudo /etc/init.d/ssh restart
  • 切换到root用户,修改ubuntu用户的密码
su root

...
passwd ubuntu
Enter new UNIX password: 
Retype new UNIX password: 

看网络上一般这么操作后,都能成功使用root登录了,可是我们今儿就还是不行,还得另辟蹊径。

进阶

参考:如何启用root用户通过SSH登录AWS Ubuntu实例

的确,在没有任何设置前,如果尝试使用root登录,会提示:

Please login as the user “ubuntu” rather than the user “root”.

按文档中提到的删除部分设置后重启sshd,终于可以正常使用root登录了。

  • 编辑authorized_keys文件
sudo vim /root/.ssh/authorized_keys

删除加粗突出显示的文字,切记ssh-rsa文本之前没有空格。

借用原文图片

至此root登录问题完美解决!

相关文章

网友评论

    本文标题:【填坑】AWS Ubuntu 下 root 的创建&登录

    本文链接:https://www.haomeiwen.com/subject/retyjxtx.html