Skip to content

Instantly share code, notes, and snippets.

@hmcclungiii
Last active January 5, 2020 19:32
Show Gist options
  • Save hmcclungiii/ec44b2d975045691f0c6ef12ec7490bf to your computer and use it in GitHub Desktop.
Save hmcclungiii/ec44b2d975045691f0c6ef12ec7490bf to your computer and use it in GitHub Desktop.
Linux commands for working with users and groups in the terminal.

Important Files and Paths

  • /etc/login.defs is the configuration file for login parameters, containing some defaults that are used for the commands below.
  • /etc/adduser.conf contains the default configuration and settings for creating new users with adduser
  • The default files for new users is stored in /etc/skel, though this can be changed in /etc/adduser.conf
  • The user database is stored at /etc/passwd
  • User passwords are stored in /etc/shadow
  • Group info is stored at /etc/group

Find all users that login through the terminal.

sudo awk -F':' '$2 ~ "\\$" {print $1}' /etc/shadow

Get the groups a user belongs to.

groups username

Get the GIDs a user belongs to.

id username id uid

Add a group

addgroup

Add a user

  • Omitting the groupname argument will cause a new group to be created with the same name as the new user.

adduser username groupname

Delete a user

deluser

Change a users password

passwd

Change group passwords

gpasswd

Modify a user

  • Where adduser only allows the user to be added to one group, usermod allows a user to be added to multiple groups. usermod chfn

Give password an expiration date

chage

Set a disk usage quota

edquota

Regarding Sudo

To grant sudo privileges to an existing user, usermod -aG sudo username

Miscellaneous

To switch users without having to logout and back in, su - username

For more information:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment