Login as root user on AWS EC2

By default, AWS EC2 uses the "ec2-user" account for login, which does not have permissions for many folders.

The problem is how to execute commands using the root account.

The solution is as follows:

  1. Connect to the EC2 server according to the method provided on the official website (Windows users are recommended to use PUTTY for connection).
    Host: The "Public DNS" of the server
    Port: 22

  2. Create a password for the root account by entering the following command:

sudo passwd root
  1. You will then be prompted to enter:
new password

Enter the password you want to set for the root account, and then enter it again for verification.
4. Next, switch to the root account by entering the following command:

su root
  1. Use the root account to edit the SSH login method for the Amazon cloud server.
    Find PasswordAuthentication no and change no to yes.
vim /etc/ssh/sshd\_config
  1. Next, restart sshd with the following command:
sudo /sbin/service sshd restart
  1. Then switch to the root account again:
su root
  1. Add a login password for the original "ec2-user".
    Enter the following command:
passwd ec2-user

Follow the prompts and enter the password twice.
9. Modify the sshd configuration file:

vi /etc/ssh/sshd\_config

Change the line PermitRootLogin to PermitRootLogin yes
Change PasswordAuthentication no to PasswordAuthentication yes
Change UsePAM yes to UsePAM no
10. Restart the AWS VPS, and you will be able to log in as root normally.

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