0. Command
groupadd – Create a new group with the
groupmod – Make changes to groups using the
useradd– Create a new user with the
passwd – Set and reset a user's password
usermod Make changes to the user account
Related Group Command
grep groupname /etc/group– View group details from local group file.getent group groupname– Display group information (local + network).id user– Show user and group membership information.find / -nogroup– Find files owned by orphaned GIDs.
Create Group
groupadd -g 1212 alamgir– create group with specify GIDgroupadd auto– Automatic GID Assignmentgrep auto /etc/group– verify group creationgroupadd -r alamgir– assign GID by system automatically
Modify Group
groupmod -n newname oldname– Rename an existing group.groupmod -g GID groupname– Change a group’s GID.
Delete Group
usermod -g group user– Change a user’s primary group.usermod -aG group user– Add a user to a supplementary group.gpasswd -d user group– Remove a user from a supplementary group.groupdel groupname– Delete a group (must not be a primary group).
Create user
useradd -u 1212 -g cse -G ict,cps -m -c 'Alamgir Here' alamgir
User Related
useradd username– Add a new user.useradd -u UID username– Set a specific user ID for the new user.useradd -g groupname username– Set primary group.useradd -G group1,group2 username– Set supplementary groups.useradd -m username– Create a home directory.useradd -M username– Do not create a home directory.useradd -d /home/path username– Specify a full home directory path.useradd -b /base/path username– Base directory for home.useradd -d /full/path username– Full home directory path.useradd -k /path/to/skel username– Custom skeleton directory.useradd -s /path/to/shell username– Set login shell.useradd -c "Comment" username– Set the GECOS/comment field.
Modify user
usermod– Modify an existing user account.usermod -c "Comment" username– Change the GECOS/comment field.usermod -d /home/newpath username– Change the user’s home directory.usermod -e YYYY-MM-DD username– Set account expiration date.usermod -f DAYS username– Allow login for DAYS after password expires.usermod -g GROUP username– Change primary group.usermod -G GROUPS username– Change supplementary groups (overwrite).usermod -aG GROUPS username– Append supplementary groups.usermod -l NEWNAME username– Change login name.usermod -L username– Lock the user account.usermod -U username– Unlock the user account.usermod -s /path/to/shell username– Change the login shell.usermod -u UID username– Change the UID (may orphan files).
User password
passwd username– Set or change a user’s password.chage -l username– Show password aging info.chage -M DAYS username– Set maximum password age.chage -m DAYS username– Set minimum password age.chage -W DAYS username– Set warning period before password expires.chage -I DAYS username– Set inactive days after password expires.
Delete user
userdel username– Delete a user account (home directory remains).userdel -r username– Delete a user account along with home directory and mail spool.
Others
id username– Show UID, GID, and group memberships.groups username– Show groups the user belongs to.whoami– Show the currently logged-in username.who– Show currently logged-in users.w– Show logged-in users, system uptime, and running processes.last username– Show login history for the user.getent passwd– Display all users from system database.getent group– Display all groups from system database.