Modify an Existing User

Modify an Existing User

The assistant's account already exists, but its description is missing. You do not need to delete the person and start again to change a record field. usermod updates selected properties of an existing Linux account, using options that identify exactly what should change.

Let's update the descriptive comment while keeping the login name the same. This is a small example of a larger habit: decide the field you mean before reaching for an administrative command. A comment, username, home path and group list are different properties with different consequences.

What you’ll learn

  • Change an account comment or another specified field with usermod.
  • Choose the appropriate option without accidentally renaming the account.

A comment can change while the username stays

  1. Before

    The practice account already exists.

    school-assistant
  2. Edit

    usermod -c selects the descriptive comment field.

    School assistant
  3. Verify

    getent displays the account record; the login name is unchanged.

    school-assistant remains
Modify the smallest account property needed for the task.

Change the assistant’s account comment

Prepare the example

Use the practice VM and the existing school-assistant account from the account-creation lesson. Verify it with getent before making changes. You need appropriate administrative authorization. The comment contains a space, so keep its quoted text together as one argument.

Bash · Linux terminal

sudo usermod -c 'School assistant' school-assistant
getent passwd school-assistant

Expected behavior; machine-dependent details

The account record contains the new comment.

usermod -c 'School assistant' school-assistant selects the comment field with -c. The final argument identifies the existing account to update. The words inside the quotes become one field value; they are not a proposed replacement username.

The following getent command lets you inspect the new record. The username should still be school-assistant, while the descriptive field has changed. Compare that with -l, which requests a login-name change, or passwd, which changes authentication credentials. Similar-looking commands can act on very different parts of the account.

Select the account field that needs changing

The usermod command changes properties of an existing Linux account. Because usernames, home directories and groups can be referenced by running processes and files, make changes deliberately.

1. Change a User’s Username

Let’s change the username from john to johnny:

sudo usermod -l johnny john
username 'john' is now changed to 'johnny'

Note: This doesn’t rename the home directory. It just changes the login name.

2. Rename the User’s Home Directory

If you’ve changed the username, it’s a good idea to rename the home directory too. Here’s how:

sudo usermod -d /home/johnny -m johnny
home directory is now /home/johnny and all files are moved

-d specifies the new home directory and -m moves the files.

3. Change a User’s Primary Group

Let’s assign the user to a different primary group, say developers:

sudo usermod -g developers johnny
user 'johnny' is now part of the primary group 'developers'

4. Add the User to Additional Groups

Want to give the user access to other groups like sudo or docker?

sudo usermod -aG sudo,docker johnny
user 'johnny' has been added to groups: sudo, docker

Important: Always use the -a (append) flag when adding to groups. Without it, the user will be removed from all other groups!

5. Lock or Unlock a User Account

If you need to temporarily disable a user without deleting them:

sudo usermod -L johnny   # Lock
sudo usermod -U johnny   # Unlock
account 'johnny' is now locked/unlocked

Change user properties carefully with usermod

Here's what we learned today:

  • How to change usernames
  • How to move and rename home directories
  • How to update primary and secondary groups
  • How to lock or unlock accounts

And that’s it! You’ve now mastered the basics of modifying users in Linux. Keep practicing and you’ll feel confidently in no time. Don’t forget to check out the next topic in our Linux course on user permissions.

Try it, then check the worked answer

Your task: Change the descriptive comment without renaming the account.

Use the practice VM and the existing school-assistant account from the account-creation lesson. Verify it with getent before making changes. You need appropriate administrative authorization. The comment contains a space, so keep its quoted text together as one argument.

Bash · complete example for this question

sudo usermod -c 'School assistant' school-assistant
getent passwd school-assistant

Expected behavior; machine-dependent details

The account record contains the new comment.

Worked answer

usermod -c 'School assistant' school-assistant

Choose the -c option for the comment. A phrase describing a person is not the same thing as their login identifier. Verify the field afterward, and avoid using a renaming option merely because both operations involve account text.

Check your decision

Change the descriptive comment without renaming the account.
Choose one answer. You can try again.

Answer and explanation

usermod -c 'School assistant' school-assistant

Choose the -c option for the comment. A phrase describing a person is not the same thing as their login identifier. Verify the field afterward, and avoid using a renaming option merely because both operations involve account text.

Change the intended field, not the account identity

Modify the smallest account property needed for the task. Read options as field selections, not interchangeable administrative shortcuts. Some other changes, such as moving a home or altering groups, involve resources and sessions beyond the record, so review those operations separately.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Delete an Account Deliberately →