Setting permissions, revoking access, and performing other user management duties in Linux can improve your system's security and organization, ensuring users can access the resources they need when they need to.
The useradd command lets you create, modify, and check user accounts, helping you handle multi-user environments across various Linux distributions.
But how do you use it?
Our guide tells you everything you need to know about the useradd command in Linux, as well as some best practices for user management.
Put simply, useradd is a command for creating new user accounts in Linux and other Unix-related operating systems. It interacts with system files to configure user details so you can set up accounts more efficiently. These system files include:
Useradd isn't the only user management command for Linux. For example, the adduser command generates prompts throughout the user creation process, making it a more user-friendly and interactive alternative to useradd.
That said, useradd is robust and script-friendly, making it a good choice if you want to automate administrative tasks. It lets you control the user creation process from start to finish.
Here's a closer look at how the useradd and adduser commands differ:
The general format of the useradd command is:
useradd [options] USERNAME
Here's a breakdown of this syntax:
Follow these instructions if you want to create new users in Linux using the useradd command.
Start by opening your command-line interface, or terminal, in Linux. The quickest way to do this is to use the following keyboard shortcut: Ctrl-Alt-T.
You'll need to have root or sudo privileges to create new users. Check whether you can run commands as the root user by typing the following into your terminal:
sudo -v
If you have administrative privileges, it's time to create a new user. You can do this by typing the following command:
sudo useradd newuser
This simple form of the useradd command creates a user account but doesn't set a password or create a home directory just yet.
To assign a password to a new user, use this command:
sudo passwd newuser
You can then enter and confirm your password.
Check whether you successfully created a new user account by typing:
cat /etc/passwd | grep newuser
Alternatively, you can type:
id newuser
This command displays the user ID, group ID, and group memberships associated with your newly created user.
You can customize how you create new users in Linux with the useradd command in various ways. Below are some of the flags you can use:
The above flags might be enough to successfully create users in your Linux environment. However, you could use more advanced options to customize the user creation process even further.
Here are some examples:
So far, you've learned how to create new users in Linux. But what happens if you want to modify user details after creating accounts? The usermod command comes in handy here.
Here are some scenarios where you might want to use the usermod command:
Below, you'll find some other useful commands that can help you check and manage users:
The command is useradd. This command is used to create new user accounts in Linux. For example, you can run:
sudo useradd newuser
This will add a new user named "newuser" to your system.
Useradd is a low-level, non-interactive command, while adduser offers interactive prompts and a user-friendly interface. Both commands help you create users in Linux.
After creating a user with the useradd command, use the "passwd" command to assign a password to that user.
You can list all users by viewing the "/etc/passwd" file. View this file by typing cat /etc/passwd in your terminal.
It depends on whether you've used other Linux commands before. If you're unfamiliar with the operating system's command-line interface, you might struggle at first. The instructions above will make this process much easier.
If you don't want to use Linux's terminal, you can always download a graphical user interface (GUI) tool for user management. Various programs can help you create, modify, and check users in your Linux environment without requiring you to run scripts.
While the useradd command lets you check and manage users, you'll need a robust security solution to truly safeguard your Linux environment. That's where Delinea comes in. Our Zero Trust Privileged Access Management platform gives you 100% control over user permissions and access levels so you can ensure only the right people see your sensitive information.
Delinea centralizes and automates user access controls, making it easier to grant, modify, or revoke access to all of your systems and infrastructure, including Linux. As a result, you can maintain the least privilege necessary and ensure users have the correct permissions.
What's more, Delinea reduces the chances of unauthorized access and improves your compliance with data governance frameworks and other security policies. Whether you're managing users on-premises or in the cloud, we can help.