2023-06-29 07:59:34
Linux is by default a multi-user system (meaning that many users can connect to it simultaneously and work), so Linux user management is one of the fundamental tasks of a system administrator, which includes everything from creating , update and delete user accounts or user groups on a Linux system.
In this quick short article, you will learn how to add or remove a user from a group on a Linux system.
Check a user group on Linux
To find out which group a user is in, simply run the following “groups” command and provide the Username ( linuxparty in this example) as an argument.
# groups linuxparty
linuxparty : linuxparty wheel
To find out the root user group on Linux, just run the “groups ” command without any arguments.
# group
root
Check a user group on Linux
Add a user to a group in Linux
Before attempting to add a user to a group, make sure the user exists on the system. To add a user to a certain group, use the usermod command with the “-a” flag which tells the usermod which adds a user to the complementary groups, and the “-G” option specifies the actual groups in the following format.
In this example, linuxparty is the username and postgres is the name of the group:
# usermod -aG postgres linuxparty
# groups linuxpartyand would output:
linuxparty : linuxparty whell postgres
Add user to group in Linux
Remove a user from a group in Linux
To remove a user from a group, use the command gpasswd with the “-d” option as follows.
# gpasswd -d linuxparty postgres
and the message would come out:
Removing user linuxparty from group postgresAnd we check…
# groups linuxparty
Remove user from group in Linux
Also, on Ubuntu and its derivatives, you can remove a user from a specific group using the following “deluser” command (where linuxparty is the username and postgres is the name of the group).
$ sudo deluser linuxparty postgres
For more information, see the man pages for each of the different commands we’ve used in this article.
$ man groups
$ man usermod
$ man gpasswd
$ man deluser
To add a user to the sudoers group on Ubuntu and Debian, follow these steps:
More information:
How to create a sudo user on Ubuntu, RHEL, Fedora, Debian, CentOS, Rocky and AlmaLinux
Log in to your Debian system with an account that already has sudo privileges or with a root account.
Open a terminal.
Run the following command to edit the sudoers configuration file using the “visudo” text editor:
sudo visudo
This command ensures that the file is edited correctly and prevents crashes if there are syntax errors.
Find the line that contains the configuration for the sudoers group. It should look like this:
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
Add a new line below that setting to add the new user to the sudoers group. The syntax is as follows:
username ALL=(ALL:ALL) ALL
Replace “username” with the actual username you want to add. Be sure to leave a tab between the username and the rest of the line.
Save the changes and close the text editor.
The user should now have sudo privileges. You can verify this by logging out and back in with the new user’s account, then try running a command with sudo, for example:
sudo apt update
You will be prompted for the user’s password to verify sudo privileges.
Remember to exercise caution when granting users sudo privileges and make sure you trust them, as they will have access to sensitive commands and settings on the system.
#add #remove #Linux #user #group