SurferCloud Blog SurferCloud Blog
  • HOME
  • NEWS
    • Latest Events
    • Product Updates
    • Service announcement
  • TUTORIAL
  • COMPARISONS
  • INDUSTRY INFORMATION
  • Telegram Group
SurferCloud Blog SurferCloud Blog
SurferCloud Blog SurferCloud Blog
  • HOME
  • NEWS
    • Latest Events
    • Product Updates
    • Service announcement
  • TUTORIAL
  • COMPARISONS
  • INDUSTRY INFORMATION
  • Telegram Group
  • banner shape
  • banner shape
  • banner shape
  • banner shape
  • plus icon
  • plus icon

How to Add Users in Linux: A Complete Guide

December 14, 2024
4 minutes
TUTORIAL
142 Views

Managing users is a fundamental task for system administrators working with Linux. Whether you’re setting up a server or managing a development environment, knowing how to create new users is essential. This guide will walk you through the process of adding users on Linux using various methods and best practices.

Why Add Users on Linux?

Creating individual user accounts allows for better access control, file permission management, and system security. It enables each user to have a unique home directory, shell environment, and set of permissions.

Methods to Add Users in Linux

There are several ways to add users on a Linux system. The most common methods are using the useradd command or the adduser command.


1. Using the useradd Command

The useradd command is a low-level utility to add users. Here’s the basic syntax:

sudo useradd [options] username  

Example 1: Create a New User

To create a new user named "john":

sudo useradd john  

This command creates the user but does not set a password.

Example 2: Create a User with a Home Directory

To create a user with a home directory:

sudo useradd -m john  

The -m option creates a home directory at /home/john/.

Example 3: Create a User with a Custom Shell

To specify the shell (for example, /bin/bash), use the -s option:

sudo useradd -s /bin/bash john  

Example 4: Create a User with an Expiration Date

If you want to set an expiration date for a user account:

sudo useradd -e 2024-12-31 john  

This command sets the expiration date to December 31, 2024.


2. Using the adduser Command

The adduser command is a higher-level, interactive script that simplifies the user creation process.

sudo adduser john  

The system will prompt you to provide a password, full name, phone number, and other details. This method is more user-friendly than useradd.


3. Set a Password for the User

Regardless of the method you use, you’ll need to set a password for the new user:

sudo passwd john  

The system will prompt you to enter and confirm the new password.


4. Assign User to a Group

Adding a user to a specific group can help manage permissions and access. To add a user to the "sudo" group, use:

sudo usermod -aG sudo john  

This gives the user administrative privileges.


5. Verify User Creation

To verify if the user was created successfully, check the /etc/passwd file:

cat /etc/passwd | grep john  

6. Delete a User

To delete a user from the system, you can use the following command:

sudo userdel john  

To delete the user along with their home directory:

sudo userdel -r john  

Best Practices for User Management

  1. Use Unique Usernames: Avoid using generic usernames like "user1" or "guest."
  2. Set Strong Passwords: Enforce password policies to protect accounts from unauthorized access.
  3. Limit Sudo Access: Only grant sudo privileges to users who absolutely need them.
  4. Regularly Audit Users: Periodically review user accounts and remove inactive or unnecessary accounts.

Why Choose SurferCloud for Linux Server Management?

If you frequently manage Linux servers and users, having a reliable and efficient cloud server can make your tasks much easier. We recommend SurferCloud for lightweight cloud servers. SurferCloud offers fast, secure, and customizable Linux environments, allowing you to manage users, deploy applications, and maintain system security with ease.

SurferCloud VPS Special Offers:

  • 🎁 VPS Barato for $0.0/month: Get $5 + $5 Free Account Balance with SurferCloud!
  • 📣 VPS Barato for $1.0/month: https://www.surfercloud.com/promos/ulighthost (Notice! The promotion has been recently updated, changing from $1 for the first month to $9.9 for 12 months, making it even cheaper.)
  • 📢 VPS Barato for $2.0/month: https://www.surfercloud.com/promos/BlackFriday
  • 🚀 VPS Barato for $5.9/month: https://www.surfercloud.com/promos/uhost

With the knowledge of adding users in Linux, you can now manage system access more efficiently. If you need a secure, stable server to test your user management skills, SurferCloud provides an excellent environment to practice and deploy your applications.

Tags : create user in linux linux add user linux add user to group linux user management linux useradd command

Related Post

5 minutes TUTORIAL

How to Install Nano on Ubuntu: A Step-by-Step

If you’re new to Ubuntu or Linux in general, you migh...

4 minutes TUTORIAL

How to Transfer Files to and from Windows VPS

Efficient file transfer is a crucial skill for managing...

3 minutes INDUSTRY INFORMATION

How to Set Up a VNC Server on Ubuntu: A Step-

Virtual Network Computing (VNC) allows you to access an...

Affordable CDN

ucdn

2025 Special Offers:

annual vps

Light Server promotion:

ulhost-promo

Cloud Server promotion:

cloud server

Copyright © 2024 SurferCloud All Rights Reserved.  Sitemap.