Creating Users and Groups in Linux


Creating a User

  1. Via GUI Tools
    • Some distros have a GUI tool you can use
    • Find from the Menu
  2. Via Shell
    • every distro supports useradd utility
    • e.g., sudo useradd -m -c "Hoburn Washburne" -u 1006 hwash
      • -m sets a home directory
      • -c adds a comment field containing full name
      • -u sets UID of 1006
      • sets username to hwash
    • when an account is created, it is in a locked state
      • user cannot login
      • to unlock, need to use passwd command

Modifying an Account

Check If a User is Logged In

  • some account changes could be disruptive if a user is logged in
    • check if the user is logged out:
      • who
      • w
      • last shows a list of recent logins and who is still logged in
        • displays data stored in /var/log/wtmp
  1. Using GUI tools
    • usually can modify:
      • Account type
        • standard or privileged user
      • Name
      • Password
      • Groups
  2. Using Shell
    • passwd changes a user’s password
      • e.g., sudo passwd hwash
        • enter new password
        • retype
        • done
      • can also adjust password aging and other options
    • usermod modifies an existing user
      • options are identical to useradd
      • e.g., sudo usermod -u 1072 -m -d /home2/hwash hwash
        • -u changes UID to 1072
        • -m changes home directory to /home2/hwash
        • -d moves contents of original home to the new home

Deleting Accounts

  1. Delete via GUI
  2. Delete via Shell
    • userdel command deletes accounts from CLI
      • e.g., sudo userdel hwash
      • -r option deletes user’s home directory
        • does not delete user’s home directory by default
      • -f option force deletes a user if they are currently logged in
        • will still complain about user being used by a process, but will still delete the account

Managing Groups

  1. Using GUI Tools
    • can typically find in Menu
    • typically part of User management
  2. Via Shell
    • groupadd command creates a group
      • e.g., groupadd -g 1001 consultants
    • to add users to group:
      • usermod -aG consultants rich
    • groups rich checks all groups for an account
    • groupmod command modifies a group
    • groupdel deletes a group

Wheel Group

The wheel group is an important group used for system administration.

  • members are granted admin privileges
    • allows access to sudo command
  • not all distros use this group