usermod command is used to change the attribute of already exist user account. The command useradd is used to create new user in Linux system. for creating a user you can simply write the username after useradd command. In case you need to change the attribute of user than use the usermod command. The information of a user is stored in /etc/passwd file in Linux/Unix system. User information includes user ID [UID], username, Group Id [GID], shell details, location of home directory etc. you can use the different option for changing the attributes with usermod command.
Syntax:
# usermod [options] USERNAME
Usermod Options:
· -d: this option is used to change the directory of user account.
· -c : this option us used to add brief information to already exist user account.
· - e: this option is used to change the expiry date of user account.
· - g:this option is used to change the group of existing user.
· - G : adding supplementary group to user.
· - a: this option is used to adding any user of group to the secondary group.
· -L:you can lock user account.
· -l: used for changing the login name.
· -p:used to un_encrypted password for new password.
· -m: used to move the content from one [home] directory to another location.
· -s: used to create new shell for user account.
· -u: this option for set user ID for user account.
· -U: used for unlock the account of user.
Usermod commands with example:
1. Change Home Directory of User:
The home directory is found below the /home/tecmint. If you want to change the home directory of already exist user than you can use the following command. For instance you can change the directory with /var/www/. So before change the directory you have to check the current directory of user by using the given command.
Syntax:
# grep – E - - color ‘/home/tec’ /etc/passwd
After that you can change the directory using the following command
Syntax:
# usermod – d /var/www/ tecmint.
# grep – E - - color ‘/var/www’ /etc/passwd
2. Add information to User Account:
If you want to add the brief comment or information of user account then use the given command
Syntax:
# usermod – c “tecmint is name of user” tecmint.
3. Set Expiry Date of User Account:
You can set the expiry date of user account using the – e option. Before set the expiry date on the user check the current status of expiry date using the “chage” command.
# chage – 1 tecmint
It will shows the account expiry date of tecmint user for instance the expiry date of account is 25 nov 2015 then you can change it by 25 jan 2015 via using the – e option with usermod command.
Syntax:
# usermod – e 2015-01-25 tec
# chage – 1 tec
By suing the chage command you can confirm the chage expiry date.
4. Alter primary group of User:
If you want to change the primary group of user then uses the – g option with usermod command.For change the group first you have to check the current group. By use the given command.
Syntax:
# id tecmint_emp
After that you can change the group barban as a primary group using the given command. And confirm after changing that group is changed or not.
Syntax:
# usermod – g barban tecmint_emp
# id tecmint_emp
5. Add new group to Existing User:
If you want to add the new group to an existing user then uses the – G option with usermod command.
Syntax:
# usermod – G groupname username
# id username
6. Changing the login Name of User:
If you want to change the login name of existing user than you can use the – l option with usermod command.
Syntax:
# usermod – l <new login name> <old login name>
# usermod – l tecmint_admin tecmint
7. Locked User Account:
If you want to lock the user account then you can use the – L option with usermod command. When you lock the account then you can’t login and you will see the (!) sign before encrypted password.
Syntax:
# usermod –L < primary groupname>
# usermod – L barban
8. Unlock user Account:
If you want to unlock the user account you can use the – U option with usermod command.
Syntax:
# usermod – U <primary groupname>
# usermod – U barban
You can verify that you account is unlocked or not using given syntax.
# grep – E - -color ‘barban’ /etc/shadow.
9. Creating Un_encrypted password:
For creating an un_encrypted password use the –p option with usermod command.
Syntax:
# usermod – p <password> <username>
# usermod – p redhat tec
10.Changing User ID:
If you want to change the user id to existing user id than use the – u option with usermod command. You can take the user id number between 0 to 999. For instance the user id of a user is 512 and you want to change it with 789.
Syntax:
# usermod – u <new UID> <username>
# usermod – u 789 tec
# id tec
Syntax:
# usermod [options] USERNAME
Usermod Options:
· -d: this option is used to change the directory of user account.
· -c : this option us used to add brief information to already exist user account.
· - e: this option is used to change the expiry date of user account.
· - g:this option is used to change the group of existing user.
· - G : adding supplementary group to user.
· - a: this option is used to adding any user of group to the secondary group.
· -L:you can lock user account.
· -l: used for changing the login name.
· -p:used to un_encrypted password for new password.
· -m: used to move the content from one [home] directory to another location.
· -s: used to create new shell for user account.
· -u: this option for set user ID for user account.
· -U: used for unlock the account of user.
Usermod commands with example:
1. Change Home Directory of User:
The home directory is found below the /home/tecmint. If you want to change the home directory of already exist user than you can use the following command. For instance you can change the directory with /var/www/. So before change the directory you have to check the current directory of user by using the given command.
Syntax:
# grep – E - - color ‘/home/tec’ /etc/passwd
After that you can change the directory using the following command
Syntax:
# usermod – d /var/www/ tecmint.
# grep – E - - color ‘/var/www’ /etc/passwd
2. Add information to User Account:
If you want to add the brief comment or information of user account then use the given command
Syntax:
# usermod – c “tecmint is name of user” tecmint.
3. Set Expiry Date of User Account:
You can set the expiry date of user account using the – e option. Before set the expiry date on the user check the current status of expiry date using the “chage” command.
# chage – 1 tecmint
It will shows the account expiry date of tecmint user for instance the expiry date of account is 25 nov 2015 then you can change it by 25 jan 2015 via using the – e option with usermod command.
Syntax:
# usermod – e 2015-01-25 tec
# chage – 1 tec
By suing the chage command you can confirm the chage expiry date.
4. Alter primary group of User:
If you want to change the primary group of user then uses the – g option with usermod command.For change the group first you have to check the current group. By use the given command.
Syntax:
# id tecmint_emp
After that you can change the group barban as a primary group using the given command. And confirm after changing that group is changed or not.
Syntax:
# usermod – g barban tecmint_emp
# id tecmint_emp
5. Add new group to Existing User:
If you want to add the new group to an existing user then uses the – G option with usermod command.
Syntax:
# usermod – G groupname username
# id username
6. Changing the login Name of User:
If you want to change the login name of existing user than you can use the – l option with usermod command.
Syntax:
# usermod – l <new login name> <old login name>
# usermod – l tecmint_admin tecmint
7. Locked User Account:
If you want to lock the user account then you can use the – L option with usermod command. When you lock the account then you can’t login and you will see the (!) sign before encrypted password.
Syntax:
# usermod –L < primary groupname>
# usermod – L barban
8. Unlock user Account:
If you want to unlock the user account you can use the – U option with usermod command.
Syntax:
# usermod – U <primary groupname>
# usermod – U barban
You can verify that you account is unlocked or not using given syntax.
# grep – E - -color ‘barban’ /etc/shadow.
9. Creating Un_encrypted password:
For creating an un_encrypted password use the –p option with usermod command.
Syntax:
# usermod – p <password> <username>
# usermod – p redhat tec
10.Changing User ID:
If you want to change the user id to existing user id than use the – u option with usermod command. You can take the user id number between 0 to 999. For instance the user id of a user is 512 and you want to change it with 789.
Syntax:
# usermod – u <new UID> <username>
# usermod – u 789 tec
# id tec
Linux provides
usermod
command by default for the most of the distributions. This command is used to user modification. After user creation the user related information, values and policies can be changed with usermod command. In this tutorial we will look various features of usermod command with examples.- Does anyone know how to add unix groupadd command on Mac OSX 10.5? I'm trying to do man on groupadd and useradd commands but it doesn't seem to exist. Stack Exchange Network. Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest.
- The usermod command modifies the system account files to reflect the changes that are specified on the command line. OPTIONS The options which apply to the usermod command are: -a, -append Add the user to the supplementary group.
- Your USERMOD includes an object module (SRCPART), which is to be included in load module LOADMOD1 and is packaged as a MOD element with a MOD statement, as described in previous USERMOD examples. SRCPART refers to an IBM-supplied macro (IBMMAC), which was packaged in its owning product with a MAC statement.
- Usermod - Unix, Linux Command - The usermod command modifies the system account files to reflect the changes that are specified on the command line.
It seems that usermod is not used by Mac. Stack Exchange Network Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Syntax of the usermod command is like below.
User information is stored in a file named
passwd
. This file is located as /etc/passwd
. In the ancient days of Linux and Linux this file is also used to store users password. But storing user information and user credential created security problems and passwords are stored in a separate file named shadown
in the same directory etc
.![Mac Mac](/uploads/1/1/7/7/117705677/969991421.png)
There is a columns used to store information about the user. This information can be anything like First name, surname, the birthday etc.
We have set the comment for the user ismail as
İsmail Baydan
. We can check the modification with grep command by filtering line contains the user name ismail.Human users generally have home directory for storing data, file, media etc for their personal or corporate usage. This home directory is generally reside in
/home
in Linux root file system.For example user
ismail
will have the /home/ismail
directory as his own home directory for the most the Linux systems. This value can be changed after creation for some reasons like we need to set and application folder for an application user like apache
.In this example we will change the home directory of user
nick
. We will set /mnt
as nick’s home directory like below.As we can see from grep command output column number 6 is
/mnt
which is nick’s new home directory.Some users are generally created in a hurry for temporary usage and than they forgotten and resides in the system as an active account. This is an security vulnerability and should be avoided with practical solution. One of the action to take to prevent this security issue is setting account expiry date for required accounts. Expire date will be specified in
YYYY-MM-DD
format as 2017-02-28
in this example for the user nickUsermod For Mac Os
And we will check the account expire date with the following command for the user nick.
As like in the Windows operating systems in Linux operating systems user accounts are associated with groups. There are two type of user group. First type is primary group and each user account have single primary user group. Other type of group is secondary groups where each user may have more than one group. Primary groups of existing users can be changed with usermod command easily.
Previously we have printed the user group. Now we will change the user primary group more detailed information about primary group can be found previous example.
In this example we will add user nick to the root group.
![Usermod Usermod](/uploads/1/1/7/7/117705677/398960792.jpg)
Usermod For Mac Shortcut
There is two type of supplementary or secondary group addition. First we will specify the supplementary groups for the user and previous supplementary group memberships of the user will be removed if old groups do not presented. Which simply means the user will have only specified groups and all old groups will be reset.
And the second way we will add new supplementary groups to the user but old groups will be preserved. For his operations we will use extra option
-a
like below.User accounts have login names to authentication themselves. In Linux operations systems users are identified by their user ID’s. User names are used an easy way to remember and use. So A user account user ID can not be changed after creation but the user name can be changed easily. In this example we will change user name
nick
to the nick1
with option -l
.Some times we may need to lock some users for various reasons like security, holiday, test etc. User locking means the account will be inactive up to unlock operations and will be no user login for this period. In this example we will lock user
nick1
with the -L
option.As we can see from screenshot in the shadow file a
!
is added which simply symbolize the account is locked.Now in the previous example we have locked the account and we want to unlock the account named nick1. Simply provide
-U
options to the usermod command like below.In Linux user accounts are associated with shells. Shell is the application which interface with user and operating system. There are different type of shells used in Linux community. But the most popular shell is
bash
and generally used for most Linux distributions. This default shell for the user account can be changed with -s
options.In this example we will change the shell of user account nick1 with
sh
shell.Usermod For Mac Pro
User id of and account can be changed too. This change operation is done with
-u
option like below. In this example we will change the user nick1 user ID to the 1234
.