Files
linux.softwareshinobi.com/landing/docs/commands/access/usermod.md
Software Shinobi 611d0816cc
All checks were successful
learn org at code.softwareshinobi.com/linux.softwareshinobi.com/pipeline/head This commit looks good
changed file names and directories
2025-06-19 08:36:13 -04:00

1.8 KiB

The usermod command

The usermod command lets you change the properties of a user in Linux through the command line. After creating a user we sometimes have to change their attributes, like their password or login directory etc. So in order to do that we use the usermod command.

Syntax:

usermod [options] USER

Note : Only superuser (root) is allowed to execute usermod command

Options and their Functionalities:

Option Description
-a to add anyone of the group to a secondary group
-c to add comment field for the useraccount
-d to modify the directory for any existing user account
-g change the primary group for a User
-G to add supplementary groups
-l to change existing user login name
-L to lock system user account
-m to move the contents of the home directory from existing home dir to new dir
-p to create an un-encrypted password
-s to create a specified shell for new accounts
-u to assigned UID for the user account
-U to unlock any locked user

Examples:

  1. To add a comment/description for a user:
sudo usermod -c "This is test user" test_user
  1. To change the home directory of a user:
sudo usermod -d /home/sam test_user
  1. To change the expiry date of a user:
sudo usermod -e 2021-10-05 test_user
  1. To change the group of a user:
sudo usermod -g sam test_user
  1. To change user login name:
sudo usermod -l test_account test_user
  1. To lock a user:
sudo usermod -L test_user
  1. To unlock a user:
sudo usermod -U test_user
  1. To set an unencrypted password for the user:
sudo usermod -p test_password test_user
  1. To create a shell for the user:
sudo usermod -s /bin/sh test_user
  1. To change the user id of a user:
sudo usermod -u 1234 test_user