Share your love
3 Easy Steps to Create and Manage Users and Groups in Linux
In this article, we want to teach you How to create and manage users and groups in Linux. Managing users and groups in Linux is essential for maintaining the security and management of the system. You can follow the steps below to learn how to manage your users and groups in Linux distributions.
How To Create and Manage Users and Groups in Linux?
To Create and Manage Users and Groups in Linux, you need to log in to your Linux distro as a root or non-root user with sudo privileges. For this purpose, you can check the Orcacore website and search for Linux initial setup guides.
Then, follow the steps below and use the Linux Commands to complete this guide.
Step 1 – Creating users in Linux
At this point, you can create users in Linux with the useradd command.
The useradd is a low-level utility to create users in Linux. On Debian-based systems, administrators should usually use adduser instead.
To create a user, you can use the following command:
sudo useradd [optins] username
Here are some common options for useradd command to create users in Linux.
Define the home directory in the useradd command
- Parameter -b: The default base directory for the system if -d HOME_DIR is not specified. BASE_DIR is concatenated with the account name to define the home directory. If the -m option is not used, BASE_DIR must exist. If this option is not specified, the useradd command to create users in Linux will use the base directory specified by the HOME variable in /etc/default/useradd, or /home by default.
- Parameter -d: Home directory (The new user will be created using HOME_DIR as the value for the user’s login directory. The default is to append the log-in name to BASE_DIR and use that as the login directory name. The directory HOME_DIR does not have to exist but will not be created if it is missing.
- Parameter -m: Create the user’s home directory if it does not exist.
How to Add a comment for users
With the parameter -c you can add a comment for users in the useradd command.
View the User’s login Shell
Also, you can use a parameter -s to view the name of the user’s login shell.
List the group’s member
The parameter -G lists the supplementary groups of which the user is also a member.
How to change passwords for users
By passwd command, you can change the password:
sudo passwd username
Here you learn how to create users in Linux and get familiar with its options.
Step 2 – Managing users in Linux
To manage the users in Linux, you can use the usermod command. For example:
sudo usermod -s /bin/zsh username
How to delete users
You can delete a user by the userdel command:
sudo userdel username
Note: If you want to delete the home directory of that user, you should use the -r option.
Step 3 – Create and manage groups
We have all the above commands that we have to create users and manage them for the groups too. Let’s see how you can use them.
Create groups in Linux
The groupadd command used for creating the groups:
sudo groupadd groupname
Modify groups
We use groupmod for modifying the groups. For example:
sudo groupmod -n group_new group_old
The -n parameter changes the name of the group to a new name.
Delete groups
With groupdel, you can easily delete the groups.
sudo groupdel groupname
Change groups passwords
Also, we use passwd for changing the passwords.
sudo passwd groupname
Note: you can add a user to a group with the following command:
sudo -aG groupname username
Conclusion
In this article, you have learned to Create and Manage Users and Groups in Linux by using the Linux Commands. Hope you enjoy it. Also, you may like to read the following articles:
Find the PID of a Process in Linux Terminal