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:

root@slackware:~# id aura
uid=1001(aura) gid=100(users) groups=100(users)
root@slackware:~#

If we want to add a new group called vmware to aura, we can use usermod command with -G option. See how to do it with usermod command example below:

root@slackware:~# usermod -G users,vmware aura 
root@slackware:~# id aura 
uid=1001(aura) gid=100(users) groups=100(users),102(vmware)
root@slackware:~#

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:

root@slackware:~# 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:

root@slackware:~# usermod -c programmer aura 
root@slackware:~# less /etc/passwd | grep aura 
aura:x:1001:100:programmer:/home/aura:/bin/bash
root@slackware:~#

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:

root@slackware:~# usermod -p New_Password aura 

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

root@slackware:~# 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:

root@slackware:~#  usermod -g users -d /home/aura 
-s /bin/csh -c programmer -p aurapasswd01 aura
root@hitam:~#

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

Back to Linux basic commands main page.


Post new comment

The content of this field is kept private and will not be shown publicly.
This blog uses the CommentLuv Drupal plugin which will try and parse your sites feed and display a link to your last post, please be patient while it tries to find it for you.

Custom Search