Search Our Database

How to create a new user with root privileges in Linux

Last updated on |
by

Introduction

This guide explains how to create a new user on a Linux server with root (sudo) privileges and configure the server to allow this user to log in via SSH. Follow the steps below to set up the user and provide them with necessary access.

 

Prerequisites

  • You have root or sudo access to the server
  • You can access the server via SSH
  • You have basic knowledge of editing configuration files using a text editor such as nano or vi.

 

Step-by-Step Guide

Step 1: Create a new user

1. SSH into the server using a terminal or an SSH client such as PUTTY.

 

2. Create a new user by running the following command. Replace test with your desired username:

useradd test

 

3. Set a password for the new user:

passwd test

You will be prompted to enter and confirm the password.

 

Step 2: Grant the user sudo (root) privileges

1. Open the sudoers file using a text editor. We will use vi in this example:

vi /etc/sudoers

 

2. Scroll down and add the following line at the end of the file to grant the user root privileges without requiring a password. Replace test with the usernanme you created:

test ALL=(ALL) NOPASSWD: ALL

 

3. Save and exit the file. To save in vi, press ESC, then type :wq and hit Enter.

 

Step 3: Configure SSH access for the new user

1. Open the SSH configuration file:

vi /etc/ssh/sshd_config

 

2. Scroll to the end of the file and add the following line to allow the new user to log in via SSH. Replace test with the username you created:

AllowUsers test

 

3. Save and exit the file. To save in vi, press ESC, then type :wq and hit Enter.

 

Step 4: Restart the SSH service

1. After making changes to the SSH configuration, restart the SSH service to apply the changes:

service sshd restart

 

Conclusion

By following these steps, you have successfully created a new user with root privileges and configured the server to allow SSH access for that user. This setup is useful when managing multiple users who need administrative access. Make sure to follow security best practices, such as using strong passwords and monitoring user activity.

For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.

 

 

Article posted on 18 May 2020.