Linux usermod command - Edit or modify Linux user account information

As a Linux user, you must be able to manage user account in the Linux system. You need to know how to edit or modify a Linux user account information, such as change user password, assign groups to user account, remove group from the user account, change user login name, change password and many more. There is one command in Linux that can do all those stuff. That command is usermod command.

If you view manual page for Linux usermod command, you can see that the function of usermod command almost the same as useradd command function. Below is a synopsis and description of Linux usermod command taken from the manual page:

SYNOPSIS
usermod [-c comment] [-d home_dir [-m]]
[-e expire_date] [-f inactive_time]
[-g initial_group] [-G group [,...]]
[-l login_name] [-p passwd]
[-s shell] [-u uid [-o]] [-L|-U] login

DESCRIPTION

The usermod command modifies the system account files to reflect the changes that are specified on the command line.

As you can see from the synopsis, usermod command options offer the same task that you can do with useradd except usermod can't create a new user. Now let's see some examples on how to use usermod command to edit user account in Linux system.

First, create a new user account that we can use to practice using Linux usermod command. In the example below, we use a user account called aura. View current id for aura with Linux id command. See example below:

[email protected]:~# id aura
uid=1001(aura) gid=100(users) groups=100(users)
[email protected]:~#

If we want to add a new group called vmware to aura, we can use usermod command with -G option. Be careful though, if you use usermod command with -G option alone, all other groups the user currently belongs to will be removed. So it's better to add -a with -G option if you want to add group or append new group. See how to do it with usermod command example below:

Linux adding groups using usermod -G command example:

[email protected]:~# usermod -G users,vmware aura
[email protected]:~# id aura
uid=1001(aura) gid=100(users) groups=100(users),102(vmware)
[email protected]:~#

Linux append group using usermod -aG command example:

[email protected]:/var/www/kkcj/sites/all/themes$ id kkcj
uid=1000(kkcj) gid=1000(kkcj) groups=1000(kkcj),4(adm),20(dialout),24(cdrom),46(plugdev),112(lpadmin),120(admin),122(sambashare)
[email protected]:/var/www/kkcj/sites/all/themes$ sudo usermod -aG www-data kkcj
sudo: unable to resolve host ubuntu
[sudo] password for kkcj:
[email protected]:/var/www/kkcj/sites/all/themes$ id kkcj
uid=1000(kkcj) gid=1000(kkcj) groups=1000(kkcj),4(adm),20(dialout),24(cdrom),33(www-data),46(plugdev),112(lpadmin),120(admin),122(sambashare)
[email protected]:/var/www/kkcj/sites/all/themes$

If we want to set expired date for aura user account, we can use usermod command with -e option. Provide the final date aura user account will be alive in YYYY-MM-DD format. A complete usermod command example with the correct option and syntax is shown below:

[email protected]:~# usermod -e 2010-10-10 aura

We can also set a brief comment about user account using usermod command with -c option. This comment can be seen when we view /etc/passwd file. The example below shows the syntax:

[email protected]:~# usermod -c programmer aura
[email protected]:~# less /etc/passwd | grep aura
aura:x:1001:100:programmer:/home/aura:/bin/bash
[email protected]:~#

To change a user password with usermod command, we can use usermod -p command. We have to mention username who's password to be changed as in the usermod command example below:

[email protected]:~# usermod -p New_Password aura

If user aura is not login into the system, we can even change the login name.

[email protected]:~# usermod -l auta aura

We use usermod -l option in the example above to change login name for aura. So the username aura has been replaced with the new name auta. If we try to login with username aura now, the system will give login incorrect error because aura is not exist in the system.

You can also put all usermod options that you want to use together in one line. Here is the example on how to do that:

[email protected]:~# usermod -g users -d /home/aura -s /bin/csh -c programmer -p aurapasswd01 aura
[email protected]:~#

That covers almost everything you need to know about Linux usermod command and how to modify Linux user account.

Back to Linux basic commands main page.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.