Show Menu
Cheatography

*nix users and groups Cheat Sheet by

Common commands for administering users and groups on a *nix environment.

passwd [options] [LOGIN]

-a, --all : This option can be used only with -S and shows the status for all users.
-d, --delete : Delete a users password (make it empty).
-e, --expire : Immedi­ately expire an account's password.
-i, --inactive INACTIVE : This option is used to disable an account after the password has been expired for a number of days. After an account has had an expired password for INACTIVE days, the user may no longer sign on to the account.
-k, --keep­-tokens : Indicate password change should be performed only for expired authen­tic­ation tokens (passw­ords).
-l, --lock : Lock the password of the named account. This does not disable the account. The user may still be able to login using another authen­tic­ation token (e.g. a SSH key).
-n, --mindays MIN_DAYS : Set the minimum number of days between password changes to MIN_DAYS. A value of zero indicates that the user may change their password at any time.
-S, --status : Display account status inform­ation. (login,­loc­ked­/no­/usable passwo­rd,date of last password change,min age, max age, warning period, inactivity period)
-u, --unlock : Unlock the password of the named account.
-w, --warndays WARN_DAYS : Number of days warning prior to a required password change.
-x, --maxdays MAX_DAYS : Set the maximum number of days a password remains valid. After MAX_DAYS, the password will need to be changed.

gpasswd [option] GROUP

-a, --add USER : Add the user to the named group.
-d, --delete USER : Remove the user from the named group.
-r, --remo­ve-­pas­sword : Remove the password from the named group.
-R, --restrict : Restrict the access to the named group.
-A, --admi­nis­trators USER,... : Set the list of admini­str­ative users.
-M, --members USER,... : Set the list of group members.
 

useradd [options] LOGIN

-b, --base-dir BASE_DIR : Default system base directory if -d is not specified.
-d, --home HOME_DIR : Use HOME_DIR as the value for the user's login directory.
-e, --expi­redate EXPIRE­_DATE : Date on which the user account will be disabled. (YYYY-MM-DD)
-f, --inactive INACTIVE : Number of days after a password expires until the account is disabled. (0 disables account on expira­tion. -1 disables the feature.)
-g, --gid GROUP : The group name or number of the users initial login group. The group name must exist.
-G, --groups GROUP1­[,...] : List of supple­mentary groups for the user. Subject to same restri­ctions as -g.
-k, --skel SKEL_DIR : The skeleton directory to be copied in the users home directory, upon creation. Only valid if -m option specified
-K, --key KEY=VALUE : Overrides /etc/l­ogi­n.defs defaults. Multiple -K options can be specified.
-l, --no-l­og-init : Do not add the user to the lastlog and faillog databases.
-m, --crea­te-home : Create the user's home directory if it doesn't exist.
-M : Don't create home directory.
-N, --no-u­ser­-group : Do not create a group with the same name as the user.
-o, --non-­unique : Allow the creation of a user account with a duplicate UID. Only valid along with -u option
-p, --password PASSWORD : The encrypted password. NOT Recomm­ended!
-r, --system : Create system account
-s, --shell SHELL : The name of the user's login shell.
-u, --uid UID : The numerical value of the users ID. Must be unique unless -o option used
-U, --user­-group : Create group with the same name as the user
-Z, --seli­nux­-user SEUSER : The SELinux user for the users login.

groupmod [options] GROUP

-g, --gid GID : The group ID will be changed to GID.
-n, --new-name NEW_GROUP : Group name will be changed from GROUP to NEW_GROUP.
-o, --non-­unique : When used with -g, allows setting the group GID to a non-unique value.
-p, --password PASSWORD : The encrypted password. NOT Recomm­ended!
 

usermod [options] LOGIN

-a, --append : Add user to supple­mentary group(s). Use only with the -G option.
-d, --home HOME_DIR : The user's new login directory.
-e, --expi­redate EXPIRE­_DATE : Date on which the user account will be disabled (YYYY-­MM-DD)
-g, --gid GROUP : The group name/n­umber of the user's new initial login group.
-G, --groups GROUP1­[,G­ROU­P2...] : A list of supple­mentary groups which the user is also a member
-l, --login NEW_LOGIN : The name of the user will be changed from LOGIN to NEW_LOGIN.
-L, --lock : Lock a users password. (Can't use option with -p or -U)
-m, --move­-home : Move the content of the users home directory to the new location.
-o, --non-­unique : when used with the -u option, this option allows to change the user ID to a non-unique value.
-p, --password PASSWORD : Set password explicitly via shell. Not recomm­ended!
-s, --shell SHELL : The name of the users new login shell.
-u, --uid UID : The new numerical value of the users ID. Must be unique unless the -o option is used.
-U, --unlock : Unlock a users password. (Can't use this option with -p or -L.)
-Z, --seli­nux­-user SEUSER : The SELinux user for the users login.

groupadd [options] GROUP

-f, --force : This option causes the command to simply exit with success status if the specified group already exists.
-g, --gid GID : The numerical value of the groups ID. This value must be unique, unless the -o option is used.
-K, --key KEY=VALUE : Overrides /etc/l­ogi­n.defs defaults (GID_MIN, GID_MAX and others). Multiple -K options can be specified.
-o, --non-­unique : This option permits to add a group with a non-unique GID.
-p, --password PASSWORD : The default is to disable the password. (NOT RECOMM­ENDED: the password will be visible by users listing the proces­ses.)
-r, --system : Create a system group.
                               
 

Comments

Wow, this is great! Nice job!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          tmux the terminal multiplexer Cheat Sheet
          Bash Dev Cheat Sheet
          Awesome Window Manager 3.x Cheat Sheet

          More Cheat Sheets by CITguy

          jasmine JS testing Cheat Sheet
          Extending Ruby with C - Part 1 Cheat Sheet
          Extending Ruby with C - Part 2 Cheat Sheet