Back to the command reference

usermod

UsersFundamentals In real Linux

Modify a user account

Name: usermod = user modify

This command needs a real Linux system; you can practise it in real Linux mode.

Full man page

Description

usermod changes an existing account: supplementary groups, login shell, home, name, lock state and so on. The classic mistake is -G without -a, which removes the user from every other supplementary group.

Group changes take effect at the next login.

Syntax

usermod [OPTION]... USER

Common options

-aGAppend to groups (without -a the list is replaced)
-G / --groups GROUPSSet the supplementary groups (without -a, the old ones are replaced)
-g / --gid GROUPChange the primary group
-s / --shell SHELLChange the login shell
-d / --home DIRChange the home directory (with -m the files move too)
-l / --login NEWNAMEChange the login name
-L / -ULock / unlock the account
-e / --expiredate DATEThe account expiry date
-c / --comment COMMENTChange the comment (full name)

Examples

  • $ sudo usermod -aG docker alice

    Let alice use docker

    Explain
  • $ sudo usermod -s /bin/zsh alice

    Switch the default shell to zsh

    Explain

Related