20220429 144149
modify user setting
usermod
tail -5 /etc/passwd
student17a:x:1000:1000:student17a:/home/student17a:/bin/bash
student17b:x:1001:1001::/home/student17b:/bin/bash
student17c:x:1002:1002::/home/student17c:/bin/bash
manisha:x:1003:1003::/home/manisha:/bin/bash
pragati:x:1004:1003::/home/pragati:/bin/bash
usermod -c "Student17b Linux1" student17b
tail -5 /etc/passwd
student17a:x:1000:1000:student17a:/home/student17a:/bin/bash
student17b:x:1001:1001:Student17b Linux1:/home/student17b:/bin/bash
student17c:x:1002:1002::/home/student17c:/bin/bash
manisha:x:1003:1003::/home/manisha:/bin/bash
pragati:x:1004:1003::/home/pragati:/bin/bash
---------------
groupadd CTS
add user manisha to CTS group as supplimentory
id manisha
uid=1003(manisha) gid=1003(B17) groups=1003(B17)
usermod -G CTS manisha
id manisha
uid=1003(manisha) gid=1003(B17) groups=1003(B17),1004(CTS)
-----------------------------
usermod --help
Usage: usermod [options] LOGIN
Options:
-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
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
the user from other 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
-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
--------------------------------------
id student17c
uid=1002(student17c) gid=1002(student17c) groups=1002(student17c)
usermod -g CTS student17c
id student17c
uid=1002(student17c) gid=1004(CTS) groups=1004(CTS)
--------------------------------------
id student17b
uid=1001(student17b) gid=1001(student17b) groups=1001(student17b)
usermod -G CTS student17b
id student17b
uid=1001(student17b) gid=1001(student17b) groups=1001(student17b),1004(CTS)
usermod -G B17 student17b
id student17b
uid=1001(student17b) gid=1001(student17b) groups=1001(student17b),1003(B17)
usermod -a -G CTS student17b
id student17b
uid=1001(student17b) gid=1001(student17b) groups=1001(student17b),1003(B17),1004(CTS)
------------------------------------
useradd -g B17 tanuraj
tail -1 /etc/passwd
tanuraj:x:1005:1003::/home/tanuraj:/bin/bash
ls /home
manisha pragati student17a student17b student17c tanuraj
usermod -l tanu -d /home/tanu tanuraj
tail -1 /etc/passwd
tanu:x:1005:1003::/home/tanu:/bin/bash
ls /home
manisha pragati student17a student17b student17c tanuraj
usermod -d /home/tanu tanu
usermod: no changes
ls /home
manisha pragati student17a student17b student17c tanuraj
mv /home/tanuraj/ /home/tanu
ls /home
manisha pragati student17a student17b student17c tanu
-------------------------------------------------
create a user
user name: latif
uid : 1200
gid : CTS
home dir: /home/latifdata
useradd -u 1200 -g CTS -d /home/latifdata latif
useradd
-u - uid
-g - primary group gid/group name
-G - Supplementory/Secondary group
-a - append
-d - home dir
-s - login shell
-p - password
id latif
uid=1200(latif) gid=1004(CTS) groups=1004(CTS)
ls /home
latifdata manisha pragati student17a student17b student17c tanu
---------------------------------------------------
delete user
userdel username -- user will deleted , but user's home directory not deleted
userdel -r username -- user and user's profile/perminal data will deleted
useradd user1
useradd user2
tail -3 /etc/passwd
latif:x:1200:1004::/home/latifdata:/bin/bash
user1:x:1201:1201::/home/user1:/bin/bash
user2:x:1202:1202::/home/user2:/bin/bash
id user1
uid=1201(user1) gid=1201(user1) groups=1201(user1)
id user2
uid=1202(user2) gid=1202(user2) groups=1202(user2)
ls /home
latifdata manisha pragati student17a student17b student17c tanu user1 user2
userdel user1
ls /home
latifdata manisha pragati student17a student17b student17c tanu user1 user2
id user1
id: user1: no such user
tail -3 /etc/passwd
tanu:x:1005:1003::/home/tanu:/bin/bash
latif:x:1200:1004::/home/latifdata:/bin/bash
user2:x:1202:1202::/home/user2:/bin/bash
-
-------------------------------