DEV Community

Cover image for Creating a New User on a Linux Operating System
johanputra
johanputra

Posted on • Edited on

Creating a New User on a Linux Operating System

Creating a new user account on a Linux operating system is a fundamental administrative task. The following steps describe a standard and secure approach applicable to most Linux distributions.

Steps to Create a New User

1. Open the Terminal

Open the terminal on your Linux system. This can typically be done using the keyboard shortcut:

Ctrl + Alt + T
Enter fullscreen mode Exit fullscreen mode

Alternatively, search for Terminal in the application menu.


2. Log In as Root or Use sudo

If you are already logged in as the root user, you may proceed to the next step. Otherwise, use sudo to gain superuser privileges.

sudo su -
Enter fullscreen mode Exit fullscreen mode

Note:
Direct root access may be disabled on some systems. In such cases, continue using sudo with each administrative command.


3. Create a New User

To create a new user, use either adduser or useradd. The adduser command is recommended because it automatically configures default settings such as the home directory and shell.

adduser new_username
Enter fullscreen mode Exit fullscreen mode

You will be prompted to:

  • Set a password for the new user
  • Enter optional user information (full name, phone number, etc.)

4. Set or Update the User Password

If needed, you can manually set or update the password for the new user using:

passwd new_username
Enter fullscreen mode Exit fullscreen mode

5. Grant Additional Privileges (Optional)

If the new user requires administrative (superuser) privileges, add the user to the appropriate group.

Debian / Ubuntu-based distributions:

usermod -aG sudo new_username
Enter fullscreen mode Exit fullscreen mode

RHEL / CentOS / Rocky / AlmaLinux:

usermod -aG wheel new_username
Enter fullscreen mode Exit fullscreen mode

This allows the user to execute commands using sudo.


6. Log Out or Switch to the New User

After creating the user, you may log out from the current session or switch directly to the new account.

exit
su - new_username
Enter fullscreen mode Exit fullscreen mode

Best Practices

  • Avoid logging in directly as root for daily operations.
  • Grant sudo access only when necessary.
  • Use strong, unique passwords for all user accounts.
  • Regularly audit user and group memberships.

Top comments (0)