- How to add a new group?
- How to add a new user?
- How to switch from one user to another user?
- How to get information about a particular user?
- How to delete a user?
- How to delete a group?
- How to change the ownership of a file?
- How to change the group membership of a file?
- How to change the group of a user?
- How to add a user to multiple groups?
- How to check available groups?
- How to change the password of a user?
- What is the difference between
adduseranduseraddin Linux? - What is the
sudocommand? - What is the
sudoersfile? - How to check the allowed commands by
sudofor a particular user?
To add a group, use the addgroup command with sudo permissions:
sudo addgroup <groupname>Example:
sudo addgroup pythongroupNote: All created groups can be viewed in the /etc/group file.
To add a user, use the adduser command. Specify a group using --ingroup if needed:
sudo adduser --ingroup <groupname> <username>Example:
sudo adduser --ingroup pythongroup pyuser1If no group is specified, a new group with the same name as the username is created:
sudo adduser pyuser2Note: User details are stored in the /etc/passwd file:
cat /etc/passwdUse the su command to switch users:
su <username>Example:
su pyuser1To switch to the root user:
sudo -i- Without
-: Switches user only (keeps the original environment). - With
-: Switches both user and environment.
To view a user's information, use the id command:
id <username>Use the deluser command:
sudo deluser <username>Use the delgroup command:
sudo delgroup <groupname>Use the chown command:
sudo chown <username>:<groupname> <filename>Use the chgrp command:
sudo chgrp <groupname> <filename>Modify the user's primary group:
sudo usermod -g <groupname> <username>Use the usermod command with -aG:
sudo usermod -aG <group1>,<group2> <username>To list all groups:
cat /etc/groupUse the passwd command:
sudo passwd <username>adduser: High-level command, interactive, and user-friendly.useradd: Low-level command, less interactive, requires manual steps.
sudo allows a permitted user to execute commands as another user (typically root).
The /etc/sudoers file defines permissions for users and groups to execute commands with sudo. Use visudo to safely edit it.
To see what commands a user can execute with sudo:
sudo -l -U <username>