What does the `-m` option do in usermod?

QuestionsQuestions8 SkillsProDec, 22 2025
0101

In the context of the usermod command, the -m option stands for move-home.

It is almost always used in combination with the -d (directory) option. Here is the breakdown of what it does:

1. Moving the Actual Files

If you use usermod -d /home/newname user without -m, Linux simply updates the "address" in the /etc/passwd file. However, the actual folder and files stay exactly where they were.

If you use usermod -m -d /home/newname user, Linux does two things:

  1. Updates the path in the system configuration (/etc/passwd).
  2. Physically moves the contents of the current home directory to the new location.

2. Automatic Creation

If the new directory doesn't exist yet, -m will create it and ensure it has the correct permissions for that user.

Comparison Example:

  • Scenario A: sudo usermod -d /home/wayne joker

    • Result: The system thinks joker's home is /home/wayne, but if you look in /home/, the folder is still called joker. If joker logs in, he might get an error because his "new" home folder doesn't actually exist yet.
    • This is what you did in the previous step.
  • Scenario B: sudo usermod -m -d /home/wayne joker

    • Result: The system updates the path AND automatically renames/moves /home/joker to /home/wayne. Everything is synced up perfectly.

Summary: Think of -d as changing your mailing address at the post office, and -m as the moving truck that actually carries your furniture to the new house!

0 Comments

no data
Be the first to share your comment!