Step 1 : ADD New user

At the command prompt, type the following command. Replace username with the name of the user that you want to add:

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

press esc

then type :wq to exit and save the file

Step 2: Disable SSH logins for root

After you create a normal user, you can disable SSH logins for the root account. To do this, follow these steps:

Log in to the server as root using SSH.

Open the /etc/ssh/sshd_config file in your preferred text editor (nano, vi, etc.).

Locate the following line:

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:

For CentOS and Fedora, type:

service sshd restart

Leave a Reply

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