usermod Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

The usermod command in Linux is a crucial tool for system administrators. It allows them to modify existing user accounts, altering properties such as home directories, shell types, and group affiliations. Understanding how to use the usermod command in Linux can greatly enhance your ability to manage users effectively.

Syntax of usermod Command in Linux

The basic syntax of the usermod command in Linux is as follows:

Where:

  • usermod: This is the command itself, telling Linux to modify a user.
  • [options]: These are the different flags or parameters that you can use with the command to specify what modifications you want to make.
  • LOGIN: This is the username of the account you wish to modify.
Sharpen Your Fundamentals with Free Learning

Options in usermod Command in Linux

  1. -d, --home: This option changes the user's home directory.

    For example -

    Output:

    This command changes the home directory of 'username' to '/new/home/directory'.

  2. -s, --shell: This option changes the user's login shell.

    For example -

    Output:

    This command changes the login shell of 'username' to '/bin/ksh'.

  3. -a, --append: This option is used with -G and adds the user to the supplementary group(s).

    For example -

    Output:

    This command adds 'username' to 'group1' and 'group2' without removing them from any other groups.

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Changing a user's home directory:

    Output:

    Explanation: This usage of the usermod command in Linux alters the home directory of the user.

  • Adding a user to additional groups:

    Output:

    Explanation: This usage of the usermod command in Linux adds the user to additional groups without removing them from their current groups.

Tips

  • Always make sure you have administrative rights or root access before attempting to modify user accounts with the usermod command in Linux. Without these rights, the command may not execute successfully.

  • When changing a user's home directory, it's a good practice to also move the contents of the old directory to the new one using the -m or --move-home option.

  • Be cautious when changing the login shell. Make sure the new shell is installed and configured correctly. A wrong shell can prevent the user from logging in.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of usermod Command in Linux

  • Locking a user's password:

    Output:

    Explanation: This command locks the password of 'username', making it impossible for them to login until the password is unlocked.

  • Expire a user's password:

    Output:

    Explanation: This command sets the expiry date of 'username''s password to 1 day after the account was created, effectively expiring the password immediately.

  • Change user's primary group:

    Output:

    Explanation: This command changes 'username''s primary group to 'new_group'.

Conclusion

  • The usermod command in Linux is a powerful tool for managing user accounts.

  • It can modify various properties of a user account including the home directory, login shell, and group affiliations.

  • Advanced uses of the command include locking and expiring passwords, and changing the primary group of a user.

  • Remember to use the usermod command with caution, as incorrect usage can lead to user login issues.