Root Security and SSH Configuration Guide (Step-by-Step)

This guide strengthens your server’s security by setting up safe SSH access, managing users efficiently, and assigning root privileges in a controlled way. Creating a secure .ssh directory and connecting via SSH ensures encrypted, protected access to your server. Adding users like user1 allows team members to log in individually, while the ability to remove users and their data helps keep access clean and limited. Setting a default text editor streamlines system changes, especially when working with important configuration files. Most importantly, using visudo to grant specific users sudo (root) privileges allows them to run administrative commands without compromising the root account itself. This minimizes risk, boosts accountability, and maintains a well-organized, secure server environment.

πŸ“ Step 1: Create the .ssh Directory (if not already present)

mkdir ~/.ssh/

This creates a secure folder to store your SSH keys. If it already exists, you can skip this step.

🌐 Step 2: Connect to the Server via SSH

ssh root@192.168.1.11

Replace 192.168.1.11 with your server’s domain name or IP address. This command logs you in as the root user.

πŸ‘€ Step 3: Add a New User and Set Password

To add a new user (example: user1) and set their password:

adduser user1

The system will prompt you to enter a password and optional user information.
Then set the password (if not prompted):

passwd user1

Enter the new password for the user kema.

πŸ—‘οΈ Step 4: Remove a User and Their Home Directory

To delete the user and also remove their home folder:

deluser user1 --remove-home

πŸ“ Step 5: Set Default Text Editor (Optional but Helpful)

If you want to choose your preferred editor (like nano, vim, etc.):

update-alternatives --config editor

You’ll see a list of installed editors. Enter the number of the one you prefer (e.g., 1 for nano).

πŸ” Step 6: Grant Sudo (Root) Privileges to a User

To allow a user (like user1) to execute commands as root:

  1. Open the sudoers file safely using the visudo command:
visudo

This opens the file in a safe environment, preventing syntax errors that could break your system.

  1. Add the following line at the bottom of the file:
   user1    ALL=(ALL:ALL) ALL

βœ… This gives full root privileges to the user user1.

Root Security and SSH Configuration Guide
Root Security and SSH Configuration Guide