1. Home
  2. Linux
  3. Linux User and Group
  4. Linux – usermod

Linux – usermod

Modify User in Linux

Use usermod command to modify/update existing user account in Linux.

Syntax:

$ usermod [options] USER_NAME

Example:

Change the default shell of user myuser to /usr/sbin/nologin. Use -s or –shell to update default shell.

$ usermod --shell "/usr/sbin/nologin" myuser

Change Home Directory

Use -d or –home switch to change the current home directory of user. The new directory will create automatically, but the parent directory of new home must be exist.

$ usermod --home "/var/home/myuser" myuser

You can also use -m or –move-home with above switch to move content of home directory as well.

$ usermod --move-home --home "/var/home/myuser" myuser

Lock and Unlock User

Use -L or –lock to lock specific account in Linux system. Use -U or –unlock to unlock any locked user account under Linux system.

$ usermod --lock myuser         ## Lock account
$ usermod --unlock myuser       ## Unlock account

Change Primary Group

Use -g or –gid to forcefully change the user’s primary group. For example, set “staff” as the primary group for the myuser account.

$ usermod --gid staff myuser 

Adding User to Secondary Group

Use -G or –groups to add a user in multiple secondary groups. For example add myuser to staff, accounts group.

$ usermod -G staff,accounts myuser 
Tags ,