AWS】Create a root user on EC2 and log in with the root user

Recently, there was a project that required the use of AWS's EC2 server;
after creating the server instance, I found that there was no root user. After reading the AWS EC2 documentation carefully, I found that the default user is ec2-user;
then we need to create a root user.

1. Create the root user.
Note: It must be executed under the ec2-user user.

sudo passwd root
will prompt you to enter your password twice:

Changing password for user root.
New password:
Retype new password:

After the input is completed, our root user is successfully created;
we try to log in to the user

su root
enter password

Password:
[root@****** ec2-user]#You
can log in normally;
AWS EC2 by default, password authentication and root user login are disabled; AWS EC2 manages the user account of the Linux instance

2. Enable password login.
It also tells us that if necessary, you can enable password login yourself;

vim /etc/ssh/sshd_config

Change the no in the PasswordAuthentication no configuration to yes to support password login for other users.

If you need root user password to log in

Change the PermitRootLogin configuration to yes

To restart sshd you can use the following command. You can also use systemctl restart sshd.service;

sudo /sbin/service sshd restart

3. Set passwords for other users.
You can set passwords for other users under the root user.

passwd username
enter password

New password:
Retype new password:
In this way, you can log in with a normal password; however, it is still recommended to use a key to log in; the password can be set and used during sudo.

Guess you like

Origin blog.csdn.net/wwj256/article/details/133384559