How to Create a User in Linux
![](https://mlft16w5bajv.i.optimole.com/w:640/h:427/q:mauto/f:best/https://eleventhunicorn.com/wp-content/uploads/2023/08/WhatsApp-Image-2023-08-19-at-18.05.37.jpeg)
One of the most basic jobs in Linux is the creation of users. System administrators must regularly manage users as the company’s size expands or contracts. Or perhaps you want to add a user in Linux to allow one of your family members to use your computer while protecting your personal data. In any event, let’s look at how to create a user in Linux in this post. There are two methods for creating a new Linux user, and we’ve demonstrated both with examples.
In Linux, use the useradd command to create a user.
The oldest approach is to create a new Linux user with the useradd command. Before we begin, you can check the list of all Linux users to see if the user you’re attempting to add already exists. There are four ways to list users, but the most frequent is as follows.
getent /etc/passwd
If you don’t see the user here, you can add them with the useradd command. The useradd command has the following syntax:
sudo useradd -s /bin/bash -m -c "Full Name" -G"nameofthegroub" "username"
Let us go over each entity in the preceding command one by one.
Sudo: To create a new user, you must have superuser rights.
useradd: The useradd command tells Linux that we want to create a new user.
-s: specifies the default shell.
-m: Creates and assigns the user a /home directory.
-c: Uses the user’s complete name.
-G: Assigns a group to the user. This group can then be expanded to include other users.
The user account’s name is tayeeb.
The command below is an example of the useradd command.
sudo useradd -s /bin/bash -m -c "Tayeeb Hasan" tayeeb
![](https://mlft16w5bajv.i.optimole.com/w:1024/h:721/q:mauto/f:best/https://eleventhunicorn.com/wp-content/uploads/2023/08/Created-user-Tayeeb.webp)
IMAGE CREDIT- beebom
Even though the account has been created, it is still not secure because there is no password. There are two methods for creating a password. If you’re an admin, you can do it yourself first and then tell the profile holder the password. Alternatively, the ideal approach to do the same thing is to assign a temporary password to the newly created user and let the user to choose what password they wish to use afterwards. The following command can be used to accomplish this. Enter a temporary password after running this program.
sudo passwd --expire "username"
Swap the username with an actual username and it should look like this:
sudo passwd --expire tayeeb
![](https://mlft16w5bajv.i.optimole.com/w:1004/h:721/q:mauto/f:best/https://eleventhunicorn.com/wp-content/uploads/2023/08/adduser-tayeeb-and-expire-password.webp)
IMAGE CREDIT- beebom
You can set an initial password for the user and provide it to them, after which Linux will prompt them to input a new password twice, which will be the new password.
In Linux, use the adduser command to create a user.
The adduser command was added considerably later in the kernel and makes adding users a breeze. Because they have the same name, you may be confused between the useradd and adduser commands. However, there are a few distinctions between the two Linux commands.
useradd is a built-in Linux command, whereas adduser is a high-level utility tool that allows for extensive customisation when establishing a user in Linux. You can use the adduser command to establish a home directory for new users, set a password, and use one of numerous options.
Here’s how to use the adduser command in Linux to add a user.
sudo adduser "username"
The program will then prompt you to input your password, the user’s name, and other information before asking for the password a second time. After that, use the command passwd –expired to allow the user to change their password the next time they try to log in with the new account. Adduser worked great for us on an Ubuntu VM but not on Fedora for unclear reasons.
![](https://mlft16w5bajv.i.optimole.com/w:1024/h:642/q:mauto/f:best/https://eleventhunicorn.com/wp-content/uploads/2023/08/New-password-for-Tayeeb-hasan.webp)
IMAGE CREDIT- beebom
Once executed, the program prompts you to enter and confirm a password as well as the user’s entire name. If you like, you can skip the remaining fields, such as phone number, room number, and so on.
In Linux, use the GUI to create a user.
Creating a new user in Linux is as simple as it is with Windows. Here’s how to make a new user in Linux using the graphical user interface.
- Navigate to Settings > Users and enter your password to unlock the menu.
![](https://mlft16w5bajv.i.optimole.com/w:1024/h:752/q:mauto/f:best/https://eleventhunicorn.com/wp-content/uploads/2023/08/Screenshot-from-2023-07-01-14-44-46.webp)
IMAGE CREDIT- beebom
- In the Other Users section, click the Add User option.
![Add user button in Linux GUI](https://beebom.com/wp-content/uploads/2023/07/Add-user-button-in-Linux-GUI.jpg?w=640)
IMAGE CREDIT- beebom
- Enter the new Linux user’s name, username, password, and other information.
![Users menu in Settings in Linux GUI](https://beebom.com/wp-content/uploads/2023/06/Users-menu-in-Settings.png?w=1024)
IMAGE CREDIT- beebom
- Finally, click Add, and the new user should now be visible when the current user signs out.
- To allow the user to set their own password at the next login, go to user details > Password and tick the box next to “Allow user to change their password.”
![allow user to change the password](https://beebom.com/wp-content/uploads/2023/06/allow-user-to-change-the-password.png?w=1024)
IMAGE CREDIT- beebom
Some frequently asked questions are here as follows:
- How do I set a password for a new user in Linux? After creating a new user account, you can set a password using the
passwd
command followed by the username. For example,sudo passwd username
. You can also set an initial temporary password and prompt the user to change it upon their first login. - Can I create a user account with a graphical interface in Linux? Yes, most Linux distributions provide a graphical user interface (GUI) for user management. You can navigate to the system settings, user accounts, or similar sections in the GUI to create new users. This approach is especially user-friendly for those who are not familiar with command-line operations.
- What is the purpose of assigning a user to a group during user creation? Assigning a user to a group during user creation helps manage permissions and access to files and resources. Users in the same group share certain privileges, making it easier to control who can access specific files and directories. Group membership simplifies permission settings and enhances security.
- What precautions should I take while creating user accounts in Linux? When creating user accounts, it’s essential to use strong passwords and adhere to password policies. Additionally, avoid giving unnecessary privileges to users to prevent security vulnerabilities. Regularly review and manage user accounts to ensure that former employees or inactive users are removed or disabled.
- How can I enable users to change their passwords on their own? To allow users to change their passwords at their convenience, you can use the
passwd
command with the--expire
flag after creating their account. This forces the user to change their password upon their next login, promoting better security hygiene. - Are there any risks associated with improper user management in Linux? Improper user management can lead to security breaches and unauthorized access to sensitive data. Inadequate management may also result in resource allocation issues and difficulties in tracking user activities. Therefore, it’s crucial to follow best practices and regularly audit user accounts.
- Can I automate user creation using scripts in Linux? Yes, you can automate user creation using shell scripts or configuration management tools. By writing scripts, you can consistently create users with predefined settings, making it more efficient in scenarios where multiple users need to be added.
- What’s the importance of maintaining user accounts as a Linux system grows? As a Linux system expands, user management becomes critical for security and efficiency. Regularly reviewing user accounts helps ensure that only authorized personnel have access to the system. It also helps prevent resource allocation issues and enhances the overall integrity of the system.
In conclusion, user management is a fundamental aspect of maintaining a Linux system, whether in a professional setting or for personal use. As demonstrated, there are two primary methods for creating new user accounts: using the command line interface with tools like useradd
and adduser
, or employing graphical user interface tools provided by the Linux distribution. Each method offers its own advantages and may cater to different levels of user familiarity.
Creating a user account involves specifying essential information such as the username, password, and user’s group, along with additional details like the user’s full name and contact information. Care should be taken to set strong passwords and to manage user permissions effectively, ensuring that security remains a top priority.
As the needs of an organization or a personal setup evolve, user management becomes an ongoing task. Adding, modifying, or deleting user accounts should always be approached with security and data integrity in mind. By following the appropriate procedures and best practices, system administrators and Linux users alike can ensure the smooth operation of their systems while safeguarding sensitive information.
To know more tips and guides, click here.