banner
老孙

老孙博客

资深网民孙先生
mastodon
email

在AWS EC2上使用root用户登录

aws ec2 默认是使用ec2-user账号登陆的,对很多文件夹是没有权限的

如何使用 root 账号执行命令就是一个问题了。

解决办法如下:

1. 根据官网提供的方法登录连接到 EC2 服务器(官网推荐 windows 用户使用 PUTTY 连接)
主机:是服务器的Public DNS
端口:22

2. 创建 root 的密码,输入如下命令:

sudo passwd root 

3. 然后会提示你输入

new password

输入一个你要设置的 root 的密码,需要你再输入一遍进行验证。
4. 接下来,切换到 root 身份,输入如下命令:

 su root 
 

5. 使用 root 身份编辑亚马逊云主机的 ssh 登录方式,
找到 PasswordAuthentication no,把no改成yes
输入:

vim /etc/ssh/sshd\_config 

6. 接下来,要重新启动下 sshd,如下命令:

sudo /sbin/service sshd restart 

7. 然后再切换到 root 身份

su root 

8. 再为原来的”ec2-user” 添加登录密码。
如下命令:

passwd ec2-user 

按提示,两次输入密码。
9. 修改 sshd 配置文件

 vi /etc/ssh/sshd\_config 

PermitRootLogin这行改为PermitRootLogin yes
PasswordAuthentication no改为PasswordAuthentication yes
UsePAM yes改为 UsePAM no
10. 重启 AWS VPS,就可以使用 root 正常登陆了

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.