Amazon AWS EC2 server, log in as root superuser

AWS ec2 uses the ec2-user account to log in by default, which does not have permissions to many folders. You need to change it to the root super administrator account to log in.

How to use root account SSH to log in to Amazon Cloud

By default, you log in using the ec2-user account, which does not have permissions to many folders. You need to change it to the root super administrator account.

Note: When creating When operating the system, you need to create a key pair first.Remote control, when creating a private key file, the default system format is ".PPK", useFor SSH connection, do not change here. If you choose the commonly used ".pem" format, you need to use to connect.

AWS Amazon Cloud Red Hat 9 WEB server build LNMP-1

Step 1: Use ssh to remotely log in to the Amazon cloud server

useTools, establish an Amazon cloud SSH connection, select Public Key as the method, fill in ec2-user as the account, and select the key file previously downloaded from the AWS Amazon cloud as the user key. The key password does not need to be filled in.

Log in as root superuser on Amazon AWS EC2

 

Log in as root superuser on Amazon AWS EC2

Step 2: Create a root password

Enter the following command:

sudo passwd root

Enter your root password, and then you will be prompted to enter a new password. You will need to enter it again for verification.

Log in as root superuser on Amazon AWS EC2

Step 3: Switch to root

Next, switch to root and enter the following command:

su root

Step 4: Modify the SSH configuration file

Edit as rootThe host's ssh login method changes the SSH location file.

vi /etc/ssh/sshd_config

Port 22 The default remote SSH port is 22 and does not need to be changed. If you want to use another port, uncomment # and fill in the port number. Also, pay attention to whether your firewall has the port enabled. Firewalls include system firewalls, firewalls on the AWS Amazon cloud platform, and SELinux.

If PermitRootLogin is marked with no or #, it needs to be changed to PermitRootLogin yes

PasswordAuthentication no changed to PasswordAuthentication yes

Change UsePAM yes to UsePAM no

After modification, press esc to exit the editing mode. After saving, press :wq and then disable the SELinux service.

Step 5: Add the ec2-user login password

After logging in with ec2-user, switch to the root super administrator user and set the login password for ec2-user.

Log in as root superuser on Amazon AWS EC2

Restart the server after setting.

If you cannot log in remotely through ssh, check whether SELinux is disabled.

How to disable SELinux

Security-Enhanced Linux (SELinux) is a Linux kernel feature that provides a security policy protection mechanism that supports access control.

Verify SELinux Status

Remotely connect to the EC2 instance with root privileges.
Run the command getenforce to verify the SELinux status. The returned status should be enforcing or permissive. The current status is enforcing. Run the command sestatus to obtain more SELinux information.

Log in as root superuser on Amazon AWS EC2

The parameter information SELinux status is displayed as enabled, indicating that SELinux is started.

Disable SELinux

Remotely connect to the ECS instance with root privileges. For more information about connection methods, see Connection Method Overview.
Run the getenforce command to verify the SELinux status.

If the return status is enforcing, it means SELinux is enabled.
Choose to temporarily disable or permanently disable SELinux.

Run the setenforce 0 command to temporarily disable SELinux.

Permanently disable SELinux. Run the following command to edit the SELinux config file.

vi /etc/selinux/config

Find SELINUX=Enforcing, press i to enter the edit mode, and change the parameter to SELINUX=Disabled.

Log in as root superuser on Amazon AWS EC2

After the modification is complete, press the Esc key on the keyboard and execute the command :wq to save and exit the file.
reboot Restart the ECS instance.

After rebooting, run the getenforce command to verify that SELinux status is disabled, indicating that SELinux is disabled.

Red Hat 9 Firewall

The system firewall of Red Hat 9 is closed by default. If you want to open ports, you need to set up open ports in the AWS cloud platform, or set up a transparent firewall to open all ports!

1/5 - (1 vote)

Leave a Reply

Your email address will not be published. Required fields are marked *