This article describes how to disable SSH logins for the root account. For security reasons, you should create a normal user account, and then disable SSH logins for the root account as soon as possible.
Before you disable SSH logins for the root account, you must create a normal user account. (Otherwise, you will be unable to access your server when you disable the root account for SSH logins.)
To create a user and grant it administrative privileges on a server running AlmaLinux or Fedora, follow these steps:
useradd username
Type the following command, replacing username with the name of the user that you created in step 2:
passwd username
To grant administrative privileges to the user, type the following command:
visudo
This command opens the sudoers file for editing.
Add the following line to the file. Replace username with the name of the user that you created in step 2:
username ALL=(ALL) ALL
Now the user can run commands as the root user by prefixing the command with sudo. For example, the user can view the root home directory by typing the command sudo ls /root.
To create a user and grant it administrative privileges on a server running Debian or Ubuntu, follow these steps:
adduser username
Install the sudo package. To do this, type the following command:
apt-get install sudo
To add the user to the sudo group, type the following command. Replace username with the name of the user that you created in step 2.
usermod -a -G sudo username
Now the user can run commands as the root user by prefixing the command with sudo. For example, the user can view the root home directory by typing the command sudo ls /root.
After you create a normal user, you can disable SSH logins for the root account. To do this, follow these steps:
PermitRootLogin yes
Modify the line as follows:
PermitRootLogin no
Add the following line. Replace username with the name of the user you created in the previous procedure:
AllowUsers username
Restart the SSH service using the appropriate command for your Linux distribution:
service sshd restart
For Debian and Ubuntu, type:
service ssh restart
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.