Linux User Management
Introduction
Section titled “Introduction”This guide explains how to manage users and groups in Linux, including creating users, assigning passwords, and organizing group memberships.
Creating Users
Section titled “Creating Users”To create a simple user in Linux, you simlpy run the command:
useradd usernameHere username is the name of the user. This creates a new user with default settings. You can use -m to create a home directory like shown below.
useradd -m usernameThis will create a home folder inside the /home directory like /home/username.
Setting Passwords
Section titled “Setting Passwords”To change the password for a user, you can use:
passwd usernameThis will prompt you to set or change the password for the user.
Creating Groups
Section titled “Creating Groups”To create a group, you simply use:
groupadd groupnameHere groupname will be the name of the group.
Adding Users to Groups
Section titled “Adding Users to Groups”To add a user to a group, you can use:
usermod -aG groupname usernameThis will add the user username to the group groupname. To remember easily, usermod modiefies the user parameter and appends it to a Group. Without append, it might overwrite something you don’t want it to.
Viewing Group Membership
Section titled “Viewing Group Membership”By running groups username, you will list all the groups that the user username is a member of. This way, you can check your configuration.
Deleting Users and Groups
Section titled “Deleting Users and Groups”To delete users and groups, you can use userdel username to delete the user username and groupdel groupname to delete the group groupname.
If you also want te remove the users home directory, you can add -r to userdel like below.
userdel -r usernameListing Users and Groups
Section titled “Listing Users and Groups”To list all users, you can use view /etc/passwd and to list all groups, you can use view /etc/group.