Users Linux

December 11, 2021

List Users in Linux

To list all users on a Linux system, use the following command:

compgen -u

Managing User Groups

Add User to Group

To add an existing user to a secondary group, use the usermod command with -a -G options:

sudo usermod -a -G groupname username

Example: Adding User to Sudo Group

sudo usermod -a -G sudo linuxize

Important Notes

  • Always use the -a flag with -G to append groups
  • Without -a flag, user will be removed from unlisted groups
  • Command runs silently on success
  • Warnings appear only for non-existent users/groups

Additional User Management Commands

  • useradd - Create new user
  • userdel - Delete user
  • groups - List user's groups
  • id - Show user and group IDs
#Linux #Users #System #Administration