In this article, we want to teach you How to create and manage users and groups in Linux.
In the previous articles, we mentioned how to create users on CentOS 7, Now You can use this Linux command for all of the Linux distributions like Centos, Ubuntu, Debian, Fedora and etc., and all of the versions of them.
Create and Manage Users and Groups in Linux
To create and manage users in Linux you can follow the below instruction.
Creating users in Linux
you can create users in Linux with the useradd command.
useradd is a low-level utility to create users in Linux. On Debian, administrators should usually use adduser instead.
For creating 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
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.
View the User’s login Shell
parameter -s view the name of the user’s login shell.
List group’s member
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.
Managing users in Linux
To manage the users in Linux you can use the usermod command.
sudo usermod -s /bin/zsh username
How to delete users
You can delete a user by userdel command:
sudo userdel username
Note: if you want to delete the home directory of that user you shod use the -r option.
Create and manage groups
We have all the above commands that we have to create users and manage them for the groups too.
groupadd command used for creating the groups:
sudo groupadd groupname
We use groupmod for modifying the groups.
sudo groupmod -n group_new group_old
-n parameter changes the name of the group to a new name.
With groupdel, you can delete the groups.
sudo groupdel group-name
Change groups passwords
Also, we use passwd for changing the passwords.
sudo passwd group-name
Note: you can add a user to a group with the following command:
sudo -aG group-name username
In this article, you learn how to create and manage the users, Also for groups too.
Hope you enjoy this article about How to create and manage users and groups in Linux.