Linux usermod command -e Expiry Date -l Login Name -c Command -s shell User Account -G Group

Linux usermod command is used to edit the user account . We can set user account expiry date ,change user login name, set the command for particular user, Add the user to the group
[root@program ~]# groupadd redhat
[root@program ~]# useradd rhel5
[root@program ~]# useradd rhel7

Add the user to the group -G option
Using -G option we can add the user rhel5 to the group Redhat
[root@program ~]# usermod -G redhat rhel5
[root@program ~]# usermod -G redhat rhel7

#usermod -G [Group Name] [user name]
# usermod -G redhat rhel5

# cat /etc/group | grep redhat
redhat:x:504:rhel5m,rhel7

Groupname:X:Group Member
# groups username
username : group1 group2
 

Edit the shell login -s option
Remove the shell login access for the user rhel7
[root@program ~]# usermod -s /sbin/nologin rhel7
[root@program ~]# su rhel7
This account is currently not available.

Set Expiry date -e Option
[root@program ~]# su rhel5
Account has been login without any issue
set the expiry date for the user rhel5
[root@program ~]# usermod -e 2010-04-18 rhel5
After the date
$ su rhel5
Password:
Your account has expired; please contact your system administrator

Edit the comment or label for the user rhel5
[root@program ~]# usermod -c version5 rhel5
[root@program ~]# cat /etc/passwd | grep rhel5
rhel5:x:502:504:version5:/home/rhel5:/bin/bash
How to edit modify delete the user accountChange user login name -l option
[root@program ~]# usermod -l newusername oldusername[root@program ~]# usermod -l rhel55 rhel5
[root@program ~]# su rhel5
su: user rhel5 does not exist


How To Change User Home Directory
[root@bash ~]# mkdir -p /home/redhat/bashscript
[root@bash~]# usermod -d /home/redhat/bashscript rhel8
[root@bash ~]# su -  rhel8
-bash-3.1$ pwd
/home/redhat/bashscript

[root@program ~]# su rhel55
Options:

-a, --append                  append the user to the supplemental GROUPS

(use only with -G)

-c, --comment COMMENT         new value of the GECOS field

-d, --home HOME_DIR           new home directory for the user account

-e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE

-f, --inactive INACTIVE       set password inactive after expiration

to INACTIVE

-g, --gid GROUP               force use GROUP as new primary group

-G, --groups GROUPS           new list of supplementary GROUPS

-h, --help                    display this help message and exit

-l, --login NEW_LOGIN         new value of the login name

-L, --lock                    lock the user account

-m, --move-home               move contents of the home directory to the new

location (use only with -d)

-o, --non-unique              allow using duplicate (non-unique) UID

-p, --password PASSWORD       use encrypted password for the new password

-s, --shell SHELL             new login shell for the user account

-u, --uid UID                 new UID for the user account

-U, --unlock                  unlock the user account

-Z, --selinux-user    new selinux user mapping for the user account
How to edit modify delete the user account

USERADD COMMAND SYNTAX:
#useradd [-u uid][-ggid (primary Group)][ -G gid(secondary Group) [,gid,.. ]][ -d dir ][-m (if the home directory is not already present)][-s shell][-c comment]

Related post