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

  1. grep groupname /etc/group – View group details from local group file.
  2. getent group groupname – Display group information (local + network).
  3. id user – Show user and group membership information.
  4. find / -nogroup – Find files owned by orphaned GIDs.

Create Group

  1. groupadd -g 1212 alamgir – create group with specify GID
  2. groupadd auto – Automatic GID Assignment
  3. grep auto /etc/group – verify group creation
  4. groupadd -r alamgir – assign GID by system automatically

Modify Group

  1. groupmod -n newname oldname – Rename an existing group.
  2. groupmod -g GID groupname – Change a group’s GID.

Delete Group

  1. usermod -g group user – Change a user’s primary group.
  2. usermod -aG group user – Add a user to a supplementary group.
  3. gpasswd -d user group – Remove a user from a supplementary group.
  4. groupdel groupname – Delete a group (must not be a primary group).

Create user

  1. useradd -u 1212 -g cse -G ict,cps -m -c 'Alamgir Here' alamgir

User Related

  1. useradd username – Add a new user.
  2. useradd -u UID username – Set a specific user ID for the new user.
  3. useradd -g groupname username – Set primary group.
  4. useradd -G group1,group2 username – Set supplementary groups.
  5. useradd -m username – Create a home directory.
  6. useradd -M username – Do not create a home directory.
  7. useradd -d /home/path username – Specify a full home directory path.
  8. useradd -b /base/path username – Base directory for home.
  9. useradd -d /full/path username – Full home directory path.
  10. useradd -k /path/to/skel username – Custom skeleton directory.
  11. useradd -s /path/to/shell username – Set login shell.
  12. useradd -c "Comment" username – Set the GECOS/comment field.

Modify user

  1. usermod – Modify an existing user account.
  2. usermod -c "Comment" username – Change the GECOS/comment field.
  3. usermod -d /home/newpath username – Change the user’s home directory.
  4. usermod -e YYYY-MM-DD username – Set account expiration date.
  5. usermod -f DAYS username – Allow login for DAYS after password expires.
  6. usermod -g GROUP username – Change primary group.
  7. usermod -G GROUPS username – Change supplementary groups (overwrite).
  8. usermod -aG GROUPS username – Append supplementary groups.
  9. usermod -l NEWNAME username – Change login name.
  10. usermod -L username – Lock the user account.
  11. usermod -U username – Unlock the user account.
  12. usermod -s /path/to/shell username – Change the login shell.
  13. usermod -u UID username – Change the UID (may orphan files).

User password

  1. passwd username – Set or change a user’s password.
  2. chage -l username – Show password aging info.
  3. chage -M DAYS username – Set maximum password age.
  4. chage -m DAYS username – Set minimum password age.
  5. chage -W DAYS username – Set warning period before password expires.
  6. chage -I DAYS username – Set inactive days after password expires.

Delete user

  1. userdel username – Delete a user account (home directory remains).
  2. userdel -r username – Delete a user account along with home directory and mail spool.

Others

  1. id username – Show UID, GID, and group memberships.
  2. groups username – Show groups the user belongs to.
  3. whoami – Show the currently logged-in username.
  4. who – Show currently logged-in users.
  5. w – Show logged-in users, system uptime, and running processes.
  6. last username – Show login history for the user.
  7. getent passwd – Display all users from system database.
  8. getent group – Display all groups from system database.