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.
Table of Contents
π 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:
- 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.
- Add the following line at the bottom of the file:
user1 ALL=(ALL:ALL) ALL
β
This gives full root privileges to the user user1
.
