Home/Server & Website Managed Operations/How to Disable Direct Root Login on Linux Servers
Server & Website Managed Operations

How to Disable Direct Root Login on Linux Servers

Logging in as the root user has many drawbacks due to its excessive privileges; a minor mistake, such as deleting the wrong file, can lead to severe consequences. Disabling direct root login is, in a sense, also beneficial for server security.

For security reasons, it is recommended to first create a standard user and then switch to the root user using the su command.

1. Create a standard user with the username yunwei123.com

# useradd yunwei123.com

2. Set a password for the yunwei123.com user

# passwd yunwei123.com
Changing password for user yunwei123.com.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

3. Modify the sshd_config file as follows

# vi /etc/ssh/sshd_config
#PermitRootLogin yes 
Change to the following:
PermitRootLogin no

4. Restart the SSH service

# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

To log in, use the standard user created above. If you need to use the root user, switch to it using the su command.

FREE CHECKUP

Free server checkup

We will send a problem checklist and remediation advice within one business day — no obligation to engage.

135 410 16684
Weekdays Mon – Fri 10:00 – 22:00 (UTC+8) · 7×24 emergency response
Call now
CONTACT

Contact Us

How can we help?

* Required