Disabling SSH Logins for the Root Account in Ruachost
For security reasons, one of the first steps you should take when setting up a new VPS or dedicated server is to disable SSH logins for the root account. Allowing direct root logins can expose your server to brute-force attacks. Instead, you should create a normal user account with administrative privileges and use that account for SSH access.
Step 1: Create a Normal User Account
Section titled “Step 1: Create a Normal User Account”Before disabling root logins, you must create a new user with administrative privileges.
On AlmaLinux / Fedora
Section titled “On AlmaLinux / Fedora”-
Log in to your server as root via SSH.
-
Create a new user:
useradd usernamepasswd username -
Grant administrative privileges:
visudoAdd this line:
username ALL=(ALL) ALL
On Debian / Ubuntu
Section titled “On Debian / Ubuntu”-
Log in to your server as root via SSH.
-
Create a new user:
adduser username -
Install
sudoif not already installed:apt-get install sudo -
Add the user to the sudo group:
usermod -a -G sudo username
Now, the new user can run administrative commands by prefixing them with sudo.
Step 2: Disable Root SSH Logins
Section titled “Step 2: Disable Root SSH Logins”Once your new user is created and tested, disable root SSH access:
-
Log in as root.
-
Open the SSH configuration file:
nano /etc/ssh/sshd_config -
Locate the line:
PermitRootLogin yesChange it to:
PermitRootLogin no -
(Optional but recommended) Add your new user to the allowed list:
AllowUsers usernameIf you skip this step, you may lock yourself out of the server.
-
Save and exit the file.
-
Restart the SSH service:
-
On AlmaLinux/Fedora:
service sshd restart -
On Debian/Ubuntu:
service ssh restart
-
-
Open a new terminal window and test logging in with your new user.
- Do not close your root session until you confirm the new user can log in successfully.