How to modify user accounts?

QuestionsQuestions8 SkillsProUser Account ManagementOct, 09 2025
0102

Modifying user accounts in Linux is primarily done using the usermod command. This command allows you to change various attributes of an existing user account without having to delete and recreate it. Here’s a concise guide on how to use usermod effectively.

Common usermod Options

  1. Change Username:
    To rename a user, use the -l option:

    sudo usermod -l new_username old_username
  2. Change Home Directory:
    To change the home directory and move the contents, use the -d and -m options:

    sudo usermod -d /new/home/directory -m username
  3. Add User to Groups:
    To add a user to supplementary groups, use the -aG option:

    sudo usermod -aG groupname username
  4. Change User's Login Shell:
    To change the default shell for a user, use the -s option:

    sudo usermod -s /path/to/new/shell username
  5. Set Account Expiration Date:
    To set an expiration date for the user account, use the -e option:

    sudo usermod -e YYYY-MM-DD username

Example of Modifying a User Account

Suppose you want to change the username from "joker" to "batman", add "developers" group, and change the home directory:

sudo usermod -l batman joker
sudo usermod -aG developers batman
sudo usermod -d /home/batman -m batman

Verifying Changes

After making modifications, you can verify the changes using:

id batman

This command will display the user ID, group memberships, and other relevant information.

Further Learning

To enhance your skills in user management, consider exploring:

  • User Deletion: Learn how to safely remove user accounts with userdel.
  • Password Management: Understand how to change user passwords with passwd.
  • User Information: Familiarize yourself with commands like getent and chage for user information and account aging.

Feel free to ask if you have more questions or need additional examples!

0 Comments

no data
Be the first to share your comment!