Skip to content

Usermod in Linux: Managing users

A detailed guide to using the usermod command in Linux to manage user accounts, including changing the username, home directory and group settings.

Usermod in Linux: Managing users

Introduction

The usermod command in Linux is used to change user account settings, such as the username, home directory, groups. It is an important system administration tool that lets you manage user accounts flexibly.

Main capabilities

  1. Changing the home directory: Allows you to change the location of the user's home directory using the usermod command.
  2. Changing the username: Gives you the ability to change the user's login while keeping all their data and settings.
  3. Managing groups: Allows you to change the group the user belongs to.
  4. Changing the UID: Allows you to modify the user's unique identifier (User Identifier) in a Linux system.
  5. Configuring the shell: Gives you the ability to change the user's shell type for working with the system.

WARNING

Using the usermod command requires administrator (root) privileges.

Syntax

Basic command syntax:

bash
usermod [options] LOGIN

Main options:

  • -l: change the username
  • -d: change the user's home directory
  • -aG: add the user to a group
  • -g: change the user's group

Usage examples

Changing the home directory:

bash
usermod -d /new/home/dir username

Changing the username:

bash
usermod -l newusername oldusername

Adding to a group:

bash
usermod -g newgroupname username

Changing the user's UID:

bash
usermod -u newuid username

Changing the user's shell:

bash
usermod -s /bin/bash username

INFO

All changes are applied immediately, but may require restarting the user's session.

Additional resources

WARNING

When working with the usermod command, be careful, as incorrect use can lead to problems with accessing the system.

Our resources

Telegram channel: https://t.me/
F3 Cloud: https://f3cloud.com

F3 Cloud Knowledge Base