AWS EC2 is logged on by default using the Ec2-user account and has no permissions on many folders. How to execute a command with the root account is a problem. The solution is as follows:
1. Log in to the EC2 server according to the method provided by the official website (recommended for Windows users to use Putty connection)
Host: Is the public DNS port for the server: 22
2. Create the root password and enter the following command:
sudo passwd root
3. You will then be prompted to enter new password. Enter a password for the root you want to set, and you need to enter it again for verification.
4. Next, switch to root and enter the following command:
Su Root
5. Use root to edit the Amazon Cloud host SSH login method, find Passwordauthentication No, change no to Yes. Input:
Vim/etc/ssh/sshd_config
6. Next, to restart the next sshd, such as the following command:
Sudo/sbin/service sshd Restart
7. Then switch to root identity
Su Root
8. Add the login password for the original "Ec2-user". As the following command:
passwd Ec2-user
Follow the prompts and enter your password two times.
9. Modifying the sshd configuration file
Vi/etc/ssh/sshd_config
PermitRootLogin
This line should read
Permitrootlogin Yes
PasswordAuthentication no
Switch
Passwordauthentication Yes
UsePAM yes
Switch
Usepam No
10. Restart the AWS VPS and you will be able to log in using root
Source: The blog "Using root user Login on AWS EC2" reproduced from the Luang-Zun blog
Link Address: http://www.luanzun.com/126.shtml
Log on with the root user on AWS EC2