{"id":13562,"date":"2019-04-03T10:41:09","date_gmt":"2019-04-03T10:41:09","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13562"},"modified":"2019-04-03T10:41:09","modified_gmt":"2019-04-03T10:41:09","slug":"a-complete-guide-to-usage-of-usermod-command-15-practical-examples-with-screenshots","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/a-complete-guide-to-usage-of-usermod-command-15-practical-examples-with-screenshots\/","title":{"rendered":"A Complete Guide to Usage of \u2018usermod\u2019 command \u2013 15 Practical Examples with Screenshots"},"content":{"rendered":"<p>In Unix\/Linux distributions, the command \u2018<b>usermod<\/b>\u2018 is used to modify or change any attributes of a already created user account via command line. The command \u2018<strong>usermod<\/strong>\u2018 is similar to that \u2018<strong>useradd<\/strong>\u2018 or \u2018<strong>adduser<\/strong>\u2018 but the login granted to an existing user.<\/p>\n<div id=\"attachment_9733\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/usermod-command.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9733\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/usermod-command.png\" alt=\"usermod Command Examples\" width=\"442\" height=\"317\" aria-describedby=\"caption-attachment-9733\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9733\" class=\"wp-caption-text\">15 usermod Command Examples<\/p>\n<\/div>\n<p>The command \u2018<strong>useradd<\/strong>\u2018 or \u2018<strong>adduser<\/strong>\u2018 is used for creating user accounts in Linux systems. To know more about on how to create system users, read our complete guide at:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/add-users-in-linux\/\" target=\"_blank\" rel=\"noopener\">A Complete Guide to \u201cuseradd\u201d Command in Linux<\/a><\/li>\n<\/ol>\n<p>After creating user accounts, in some scenarios where we need to change the attributes of an existing user such as, change user\u2019s home directory, login name, login shell, password expiry date, etc, where in such case \u2018usermod\u2019 command is used.<\/p>\n<p>When we execute \u2018usermod\u2018 command in terminal, the following files are used and affected.<\/p>\n<ol>\n<li><b>\/etc\/passwd<\/b>\u00a0\u2013 User account information.<\/li>\n<li><b>\/etc\/shadow<\/b>\u00a0\u2013 Secure account information.<\/li>\n<li><b>\/etc\/group<\/b>\u00a0\u2013 Group account information.<\/li>\n<li><b>\/etc\/gshadow<\/b>\u00a0\u2013 Secure group account information.<\/li>\n<li><b>\/etc\/login.defs<\/b>\u00a0\u2013 Shadow password suite configuration..<\/li>\n<\/ol>\n<p>Basic syntax of command is:<\/p>\n<pre>usermod [options] username\r\n<\/pre>\n<h4>Requirements<\/h4>\n<ol>\n<li>We must have existing user accounts to execute usermod command.<\/li>\n<li>Only superuser (root) is allowed to execute usermod command.<\/li>\n<li>The usermod command can be executed on any Linux distribution.<\/li>\n<li>Must have basic knowledge of usermod command with options<\/li>\n<\/ol>\n<h4>Options of Usermod<\/h4>\n<p>The \u2018<strong>usermod<\/strong>\u2018 command is simple to use with lots of options to make changes to an existing user. Let us see how to use usermod command by modifying some existing users in Linux box with the help of following options.<\/p>\n<ol>\n<li><b>-c<\/b>\u00a0= We can add comment field for the useraccount.<\/li>\n<li><b>-d<\/b>\u00a0= To modify the directory for any existing user account.<\/li>\n<li><b>-e<\/b>\u00a0= Using this option we can make the account expiry in specific period.<\/li>\n<li><b>-g<\/b>\u00a0= Change the primary group for a User.<\/li>\n<li><b>-G<\/b>\u00a0= To add a supplementary groups.<\/li>\n<li><b>-a<\/b>\u00a0= To add anyone of the group to a secondary group.<\/li>\n<li><b>-l<\/b>\u00a0= To change the login name from tecmint to tecmint_admin.<\/li>\n<li><b>-L<\/b>\u00a0= To lock the user account. This will lock the password so we can\u2019t use the account.<\/li>\n<li><b>-m<\/b>\u00a0= moving the contents of the home directory from existing home dir to new dir.<\/li>\n<li><b>-p<\/b>\u00a0= To Use un-encrypted password for the new password. (NOT Secured).<\/li>\n<li><b>-s<\/b>\u00a0= Create a Specified shell for new accounts.<\/li>\n<li><b>-u<\/b>\u00a0= Used to Assigned UID for the user account between 0 to 999.<\/li>\n<li><b>-U<\/b>\u00a0= To unlock the user accounts. This will remove the password lock and allow us to use the user account.<\/li>\n<\/ol>\n<p>In this article we will see \u2018<strong>15 usermod commands<\/strong>\u2018 with their practical examples and usage in Linux, which will help you to learn and enhance your command-line skills using these options.<\/p>\n<h3>1. Adding Information to User Account<\/h3>\n<p>The \u2018<b>-c<\/b>\u2018 option is used to set a brief comment (information) about the user account. For example, let\u2019s add information on \u2018<strong>tecmint<\/strong>\u2018 user, using the following command.<\/p>\n<pre># usermod -c \"<b>This is Tecmint<\/b>\" tecmint\r\n<\/pre>\n<p>After adding information on user, the same comment can be viewed in\u00a0<strong>\/etc\/passwd<\/strong>\u00a0file.<\/p>\n<pre># grep -E --color 'tecmint' \/etc\/passwd\r\n\r\ntecmint:x:500:500:<b>This is Tecmint<\/b>:\/home\/tecmint:\/bin\/sh\r\n<\/pre>\n<div id=\"attachment_9717\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Information-to-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9717\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Information-to-User.png\" alt=\"Add User Information in Linux\" width=\"479\" height=\"137\" aria-describedby=\"caption-attachment-9717\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9717\" class=\"wp-caption-text\">Add Information to User<\/p>\n<\/div>\n<h3>2. Change User Home Directory<\/h3>\n<p>In the above step we can see that our home directory is under\u00a0<b>\/home\/tecmint\/<\/b>, If we need to change it to some other directory we can change it using\u00a0<b>-d<\/b>\u00a0option with usermod command.<\/p>\n<p>For example, I want to change our home directory to\u00a0<b>\/var\/www\/<\/b>, but before changing, let\u2019s check the current home directory of a user, using the following command.<\/p>\n<pre># grep -E --color '\/home\/tecmint' \/etc\/passwd\r\n\r\ntecmint:x:500:500:This is Tecmint:<b>\/home\/tecmint<\/b>:\/bin\/sh\r\n<\/pre>\n<p>Now, change home directory from\u00a0<strong>\/home\/tecmint<\/strong>\u00a0to\u00a0<strong>\/var\/www\/<\/strong>\u00a0and confirm the home director after changing.<\/p>\n<pre># usermod -d \/var\/www\/ tecmint\r\n# grep -E --color '\/var\/www\/' \/etc\/passwd\r\n\r\ntecmint:x:500:500:This is Tecmint:<b>\/var\/www<\/b>:\/bin\/sh\r\n<\/pre>\n<div id=\"attachment_9719\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Home-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9719\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Home-Directory.png\" alt=\"Change User Home Directory\" width=\"484\" height=\"189\" aria-describedby=\"caption-attachment-9719\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9719\" class=\"wp-caption-text\">Change User Home Directory<\/p>\n<\/div>\n<h3>3. Set User Account Expiry Date<\/h3>\n<p>The option \u2018<strong>-e<\/strong>\u2018 is used to set expiry date on a user account with the date format\u00a0<strong>YYYY-MM-DD<\/strong>. Before, setting up an expiry date on a user, let\u2019s first check the current account expiry status using the \u2018<strong>chage<\/strong>\u2018 (change user password expiry information) command.<\/p>\n<pre># chage -l tecmint\r\n\r\nLast password change\t\t\t\t\t: Nov 02, 2014\r\nPassword expires\t\t\t\t\t: never\r\nPassword inactive\t\t\t\t\t: never\r\nAccount expires\t\t\t\t\t\t: <b>Dec 01, 2014<\/b>\r\nMinimum number of days between password change\t\t: 0\r\nMaximum number of days between password change\t\t: 99999\r\nNumber of days of warning before password expires\t: 7\r\n<\/pre>\n<p>The expiry status of a \u2018<strong>tecmint<\/strong>\u2018 user is\u00a0<b>Dec 1 2014<\/b>, let\u2019s change it to\u00a0<b>Nov 1 2014<\/b>\u00a0using \u2018<strong>usermod -e<\/strong>\u2018 option and confirm the expiry date with \u2018<strong>chage<\/strong>\u2018 command.<\/p>\n<pre># usermod -e 2014-11-01 tecmint\r\n# chage -l tecmint\r\n\r\nLast password change\t\t\t\t\t: Nov 02, 2014\r\nPassword expires\t\t\t\t\t: never\r\nPassword inactive\t\t\t\t\t: never\r\nAccount expires\t\t\t\t\t\t: <b>Nov 01, 2014<\/b>\r\nMinimum number of days between password change\t\t: 0\r\nMaximum number of days between password change\t\t: 99999\r\nNumber of days of warning before password expires\t: 7\r\n<\/pre>\n<div id=\"attachment_9720\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Set-User-Account-Expiry-Date.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9720\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Set-User-Account-Expiry-Date.png\" alt=\"Add User Expiry Date in Linux\" width=\"576\" height=\"422\" aria-describedby=\"caption-attachment-9720\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9720\" class=\"wp-caption-text\">Set User Account Expiry Date<\/p>\n<\/div>\n<h3>4. Change User Primary Group<\/h3>\n<p>To set or change a user primary group, we use option \u2018<strong>-g<\/strong>\u2018 with usermod command. Before, changing user primary group, first make sure to check the current group for the user\u00a0<b>tecmint_test<\/b>.<\/p>\n<pre># id tecmint_test\r\n\r\nuid=501(tecmint_test) gid=502(<b>tecmint_test<\/b>) groups=502(tecmint_test)\r\n<\/pre>\n<p>Now, set the\u00a0<b>babin<\/b>\u00a0group as a primary group to user\u00a0<b>tecmint_test<\/b>\u00a0and confirm the changes.<\/p>\n<pre># usermod -g babin tecmint_test\r\n# id tecmint_test\r\n\r\nuid=501(tecmint_test) gid=502(<b>babin<\/b>) groups=502(tecmint_test)\r\n<\/pre>\n<div id=\"attachment_9721\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Primary-Group.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9721\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Primary-Group.png\" alt=\"Change User Group in Linux\" width=\"554\" height=\"229\" aria-describedby=\"caption-attachment-9721\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9721\" class=\"wp-caption-text\">Change User Primary Group<\/p>\n<\/div>\n<h3>5. Adding Group to an Existing User<\/h3>\n<p>If you want to add a new group called \u2018<strong>tecmint_test0<\/strong>\u2018 to \u2018<strong>tecmint<\/strong>\u2018 user, you can use option \u2018<strong>-G<\/strong>\u2018 with usermod command as shown below.<\/p>\n<pre># usermod -G tecmint_test0 tecmint\r\n# id tecmint\r\n<\/pre>\n<div id=\"attachment_9722\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Group-to-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9722\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Group-to-User.png\" alt=\"Add Group to User in Linux\" width=\"537\" height=\"155\" aria-describedby=\"caption-attachment-9722\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9722\" class=\"wp-caption-text\">Add Group to User<\/p>\n<\/div>\n<p><strong>Note<\/strong>: Be careful, while adding a new groups to an existing user with \u2018<strong>-G\u2019<\/strong>\u00a0option alone, will remove all existing groups that user belongs. So, always add the \u2018<strong>-a<\/strong>\u2018 (append) with \u2018<strong>-G<\/strong>\u2018 option to add or append new groups.<\/p>\n<h3>6. Adding Supplementary and Primary Group to User<\/h3>\n<p>If you need to add a user to any one of the supplementary group, you can use the options \u2018<strong>-a<\/strong>\u2018 and \u2018<strong>-G<\/strong>\u2018. For example, here we going to add a user account\u00a0<b>tecmint_test0<\/b>\u00a0with the\u00a0<b>wheel<\/b>\u00a0user.<\/p>\n<pre># usermod -a -G wheel tecmint_test0\r\n# id tecmint_test0\r\n<\/pre>\n<p>So, user\u00a0<b>tecmint_test0<\/b>\u00a0remains in its primary group and also in secondary group (<strong>wheel<\/strong>). This will make my normal user account to execute any root privileged commands in Linux box.<\/p>\n<pre>eg : sudo service httpd restart\r\n<\/pre>\n<div id=\"attachment_9723\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Multiple-Groups-to-User.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9723\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Add-Multiple-Groups-to-User.png\" alt=\"Add Multiple Groups to User\" width=\"567\" height=\"129\" aria-describedby=\"caption-attachment-9723\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9723\" class=\"wp-caption-text\">Add Multiple Groups to User<\/p>\n<\/div>\n<h3>7. Change User Login Name<\/h3>\n<p>To change any existing user login name, we can use \u2018<strong>-l<\/strong>\u2018 (new login) option. In the example below, we changing login name\u00a0<strong>tecmint<\/strong>\u00a0to\u00a0<strong>tecmint_admin<\/strong>. So the username\u00a0<strong>tecmint<\/strong>\u00a0has been renamed with the new name\u00a0<strong>tecmint_admin<\/strong>.<\/p>\n<pre># usermod -l tecmint_admin tecmint\r\n<\/pre>\n<p>Now check for the\u00a0<strong>tecmint<\/strong>\u00a0user, It will not be present because we have changed it to\u00a0<strong>tecmint_admin<\/strong>.<\/p>\n<pre># id tecmint\r\n<\/pre>\n<p>Check for the\u00a0<strong>tecmint_admin<\/strong>\u00a0account it will be there with same\u00a0<strong>UID<\/strong>\u00a0and with existing group what we have added before.<\/p>\n<pre># id tecmint_admin\r\n<\/pre>\n<div id=\"attachment_9724\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Login-Name.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9724\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Login-Name.png\" alt=\"Change User Login Name in Linux\" width=\"432\" height=\"202\" aria-describedby=\"caption-attachment-9724\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9724\" class=\"wp-caption-text\">Change User Login Name<\/p>\n<\/div>\n<h3>8. Lock User Account<\/h3>\n<p>To Lock any system user account, we can use \u2018<strong>-L<\/strong>\u2018 (lock) option, After the account is locked we can\u2019t login by using the password and you will see a\u00a0<b>!<\/b>\u00a0added before the encrypted password in\u00a0<strong>\/etc\/shadow<\/strong>\u00a0file, means password disabled.<\/p>\n<pre># usermod -L babin\r\n<\/pre>\n<p>Check for the locked account.<\/p>\n<pre># grep -E --color 'babin' cat \/etc\/shadow\r\n<\/pre>\n<div id=\"attachment_9725\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Lock-User-Account.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9725\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Lock-User-Account.png\" alt=\"Lock User Account in Linux\" width=\"594\" height=\"205\" aria-describedby=\"caption-attachment-9725\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9725\" class=\"wp-caption-text\">Lock User Account<\/p>\n<\/div>\n<h3>9. Unlock User Account<\/h3>\n<p>The \u2018<strong>-U<\/strong>\u2018 option is used to unlock any locked user, this will remove the\u00a0<b>!<\/b>\u00a0before the encrypted password.<\/p>\n<pre># grep -E --color 'babin' \/etc\/shadow\r\n# usermod -U babin\r\n<\/pre>\n<p>Verify the user after unlock.<\/p>\n<pre># grep -E --color 'babin' \/etc\/shadow\r\n<\/pre>\n<div id=\"attachment_9726\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Unlock-User-Account.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9726\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Unlock-User-Account.png\" alt=\"Unlock User Account in Linux\" width=\"584\" height=\"267\" aria-describedby=\"caption-attachment-9726\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9726\" class=\"wp-caption-text\">Unlock User Account<\/p>\n<\/div>\n<h3>10. Move User Home Directory to New location<\/h3>\n<p>Let\u2019s say you\u2019ve a user account as \u2018<strong>pinky<\/strong>\u2018 with home directory \u2018<strong>\/home\/pinky<\/strong>\u2018, you want to move to new location say \u2018<strong>\/var\/pinky<\/strong>\u2018. You can use the options \u2018<strong>-d<\/strong>\u2018 and \u2018<strong>-m<\/strong>\u2018 to move the existing user files from current home directory to a new home directory.<\/p>\n<p>Check for the account and it\u2019s current home directory.<\/p>\n<pre># grep -E --color 'pinky' \/etc\/passwd\r\n<\/pre>\n<p>Then list the files which is owned by user pinky.<\/p>\n<pre># ls -l \/home\/pinky\/\r\n<\/pre>\n<p>Now we have to move the home directory from\u00a0<strong>\/home\/pinky<\/strong>\u00a0to\u00a0<strong>\/var\/pinky<\/strong>.<\/p>\n<pre># usermod -d \/var\/pinky\/ -m pinky\r\n<\/pre>\n<p>Next, verify the directory change.<\/p>\n<pre># grep -E --color 'pinky' \/etc\/passwd\r\n<\/pre>\n<p>Check for the files under \u2018<strong>\/home\/pinky<\/strong>\u2018. Here we have moved the files using<strong>\u00a0-m<\/strong>\u00a0option so there will be no files. The pinky user files will be now under\u00a0<strong>\/var\/pinky<\/strong>.<\/p>\n<pre># ls -l \/home\/pinky\/\r\n# ls -l \/var\/pinky\/\r\n<\/pre>\n<div id=\"attachment_9727\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Move-User-Home-Directory.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-9727\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Move-User-Home-Directory-391x450.png\" sizes=\"auto, (max-width: 391px) 100vw, 391px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Move-User-Home-Directory-391x450.png 391w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Move-User-Home-Directory.png 472w\" alt=\"Move User Home Directory in Linux\" width=\"391\" height=\"450\" aria-describedby=\"caption-attachment-9727\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9727\" class=\"wp-caption-text\">Move User Home Directory<\/p>\n<\/div>\n<h3>11. Create Un-encrypted Password for User<\/h3>\n<p>To create an un-encrypted password, we use option \u2018<strong>-p<\/strong>\u2018 (password). For demonstration purpose, I\u2019m setting a new password say \u2018<strong>redha<\/strong>t\u2019 on a user\u00a0<strong>pinky<\/strong>.<\/p>\n<pre># usermod -p redhat pinky\r\n<\/pre>\n<p>After setting password, now check the shadow file to see whether its in encrypted format or un-encrypted.<\/p>\n<pre># grep -E --color 'pinky' \/etc\/shadow\r\n<\/pre>\n<div id=\"attachment_9728\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Create-Unencrypted-User-Password.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9728\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Create-Unencrypted-User-Password.png\" alt=\"Create Unencrypted User Password in Linux\" width=\"427\" height=\"191\" aria-describedby=\"caption-attachment-9728\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9728\" class=\"wp-caption-text\">Create Unencrypted User Password<\/p>\n<\/div>\n<p><strong>Note<\/strong>: Did you see in the above image, the password is clearly visible to everyone. So, this option is not recommended to use, because the password will be visible to all users.<\/p>\n<h3>12. Change User Shell<\/h3>\n<p>The user login shell can be changed or defined during user creation with\u00a0<strong>useradd<\/strong>\u00a0command or changed with \u2018<strong>usermod<\/strong>\u2018 command using option \u2018<strong>-s<\/strong>\u2018 (shell). For example, the user \u2018<strong>babin<\/strong>\u2018 has the\u00a0<strong>\/bin\/bash<\/strong>\u00a0shell by default, now I want to change it to\u00a0<strong>\/bin\/sh<\/strong>.<\/p>\n<pre># grep -E --color 'babin' \/etc\/passwd\r\n# usermod -s \/bin\/sh babin\r\n<\/pre>\n<p>After changing user shell, verify the user shell using the following command.<\/p>\n<pre># grep -E --color 'babin' \/etc\/passwd\r\n<\/pre>\n<div id=\"attachment_9729\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Login-Shell.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9729\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-Login-Shell.png\" alt=\"Change User Login Shell in Linux\" width=\"425\" height=\"178\" aria-describedby=\"caption-attachment-9729\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9729\" class=\"wp-caption-text\">Change User Login Shell<\/p>\n<\/div>\n<h3>13. Change User ID (UID)<\/h3>\n<p>In the example below, you can see that my user account \u2018<strong>babin<\/strong>\u2018 holds the UID of\u00a0<strong>502<\/strong>, now I want to change it to\u00a0<strong>888<\/strong>\u00a0as my UID. We can assign UID between\u00a0<strong>0<\/strong>\u00a0to\u00a0<strong>999<\/strong>.<\/p>\n<pre># grep -E --color 'babin' \/etc\/passwd\r\nOR\r\n# id babin\r\n<\/pre>\n<p>Now, let\u2019s change the UID for user\u00a0<strong>babin<\/strong>\u00a0using \u2018<strong>-u<\/strong>\u2018 (uid) option and verify the changes.<\/p>\n<pre># usermod -u 888 babin\r\n# id babin\r\n<\/pre>\n<div id=\"attachment_9730\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-UID.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9730\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-UID.png\" alt=\"Change User UID in Linux\" width=\"414\" height=\"263\" aria-describedby=\"caption-attachment-9730\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9730\" class=\"wp-caption-text\">Change User UID<\/p>\n<\/div>\n<h3>14. Modifying User Account with Multiple Options<\/h3>\n<p>Here we have a user\u00a0<b>jack<\/b>\u00a0and now I want to modify his home directory, shell, expiry date, label, UID and group at once using one single command with all options as we discussed above.<\/p>\n<p>The user\u00a0<b>Jack<\/b>\u00a0has the default home directory\u00a0<b>\/home\/jack<\/b>, Now I want to change it to\u00a0<b>\/var\/www\/html<\/b>\u00a0and assign his shell as\u00a0<b>bash<\/b>, set expiry date as December 10th 2014, add new label as\u00a0<b>This is jack<\/b>, change UID to 555 and he will be member of apple group.<\/p>\n<p>Let we see how to modify the jack account using multiple option now.<\/p>\n<pre># usermod -d \/var\/www\/html\/ -s \/bin\/bash -e 2014-12-10 -c \"This is Jack\" -u 555 -aG apple jack\r\n<\/pre>\n<p>Then check for the UID &amp; home directory changes.<\/p>\n<pre># grep -E --color 'jack' \/etc\/passwd\r\n<\/pre>\n<p>Account expire check.<\/p>\n<pre># chage -l jack\r\n<\/pre>\n<p>Check for the group which all jack have been member.<\/p>\n<pre># grep -E --color 'jack' \/etc\/group\r\n<\/pre>\n<div id=\"attachment_9731\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Usermod-Command-Options.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9731\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Usermod-Command-Options.png\" alt=\"Using Multiple Options with usermod\" width=\"595\" height=\"382\" aria-describedby=\"caption-attachment-9731\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9731\" class=\"wp-caption-text\">Using Multiple Options with usermod<\/p>\n<\/div>\n<h3>15. Change UID and GID of a User<\/h3>\n<p>We can change UID and GID of a current user. For changing to a New GID we need an existing group. Here already there is an account named as\u00a0<b>orange<\/b>\u00a0with GID of\u00a0<b>777<\/b>.<\/p>\n<p>Now my jack user account want to be assigned with UID of\u00a0<b>666<\/b>\u00a0and GID of Orange (<b>777<\/b>).<\/p>\n<p>Check for the current UID and GID before modifying.<\/p>\n<pre># id jack\r\n<\/pre>\n<p>Modify the UID and GID.<\/p>\n<pre># usermod -u 666 -g 777 jack\r\n<\/pre>\n<p>Check for the changes.<\/p>\n<pre># id jack\r\n<\/pre>\n<div id=\"attachment_9732\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-GID.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9732\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2014\/11\/Change-User-GID.png\" alt=\"Change User GID\" width=\"489\" height=\"197\" aria-describedby=\"caption-attachment-9732\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-9732\" class=\"wp-caption-text\">Change User UID and GID<\/p>\n<\/div>\n<h3>Conclusion<\/h3>\n<p>Here we have seen how to use usermod command with its options in very detailed fashion, Before knowing about usermod command, one should must know \u2018useradd\u2019 command and its options to use the usermod. If I\u2019ve missed any point in the article do let me know via comments and don\u2019t forget to add your valuable comments.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/usermod-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Unix\/Linux distributions, the command \u2018usermod\u2018 is used to modify or change any attributes of a already created user account via command line. The command \u2018usermod\u2018 is similar to that \u2018useradd\u2018 or \u2018adduser\u2018 but the login granted to an existing user. 15 usermod Command Examples The command \u2018useradd\u2018 or \u2018adduser\u2018 is used for creating user &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/a-complete-guide-to-usage-of-usermod-command-15-practical-examples-with-screenshots\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Complete Guide to Usage of \u2018usermod\u2019 command \u2013 15 Practical Examples with Screenshots&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13562","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13562"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13562\/revisions"}],"predecessor-version":[{"id":13563,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13562\/revisions\/13563"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}