1. Linux User, group management
1) user
I. Adding users
Useradd User Name
Useradd add users directly without parameters, home directory defaults to the bash shell
Example 1:
[Email protected] etc]# Useradd Testyx
[Email protected] etc]# Cd/home
[[email protected] home]# ls
Ads_yx Testyx
[Email protected] home]# passwd Testyx
Changing password for user Testyx.
New Password:
Bad Password:it is too simplistic/systematic
Bad Password:is too simple
Retype new Password:
Passwd:all authentication tokens updated successfully.
[Email protected] home]# Cat/etc/passwd|grep Testyx
Testyx:x:501:502::/home/testyx:/bin/bash
Useradd-d Home Directory-G Group name-group collection (comma interval)-p password-S shell user name
Example 2:
[Email protected] home]# useradd-d/home/test1-g test-p 123456-s/bin/bash testyx1
[Email protected] home]# Cat/etc/passwd|grep testyx1
Testyx1:x:502:501::/home/test1:/bin/bash
[Email protected] home]# Cat/etc/group|grep test
test:x:501:
testyx:x:502:
Ii. Modifying users
Usermod
-c< Notes > Modify the Notes text for the user account.
-D Login Directory > Modify user login directory.
-e< Expiration date > Modify the expiration date of the account.
-f< Buffer days > Modify the number of days after the password expires to close the account.
-g< Group > Modify the group to which the user belongs.
-g< Group > Modify the additional groups to which the user belongs.
-l< Account name > Modify user account name.
-L LOCKS the user password to invalidate the password.
-s<shell> modifies the shell used by the user when they log in.
-u<uid> Modify the User ID.
-U unlocks the password.
Note: When changing home directories, the destination home directory must exist and be an absolute path
Example 1: Modify the Testyx user name to Testyxc
# usermod-l Testyxc Testyx
Example 2: Lock account Testyxc
# usermod-l TESTYXC
Example 3: Unlocking the TESTYXC
# usermod-u TESTYXC
Iii. Deleting a user
Userdel User Name
Delete User only, do not delete home directory
Cases:
[Email protected] home]# Userdel Testyx
[Email protected] home]# Cd/home
[email protected] home]# LL
Total 12
DRWX------3 Ads_yx yxtest 4096 Sep 07:52 Ads_yx
DRWX------2 testyx1 test 4096 Sep 01:57 test1
DRWX------2 501 502 4096 Sep 01:50 Testyx
Userdel-r User Name
Delete User and home directory
Cases:
[Email protected] home]# Userdel-r testyx1
[email protected] home]# LL
Total 8
DRWX------3 Ads_yx yxtest 4096 Sep 07:52 Ads_yx
DRWX------2 501 502 4096 Sep 01:50 Testyx
You can see that the testyx1 user home directory test1 has been deleted
2) Switch User
i. su user name
Switch user's environment variables are not reloaded
Cases:
[Email protected] home]# cd/opt
[Email protected] opt]# pwd
/opt
[email protected] opt]# su Ads_yx
[Email protected] opt]$ pwd
/opt
You can see that the current directory has not changed after switching to the Ads_yx user
II. su– User name
The environment variable that will reload the switch user
[Email protected] opt]# pwd
/opt
[Email protected] opt]# Su-ads_yx
[Email protected] ~]$ pwd
/home/ads_yx
You can see that the current directory changes to Ads_yx's home directory after switching to the Ads_yx user, because the user's environment variable was reloaded when Su–ads_yx
III. sudo
Get Superuser privileges under normal user
configuration: Locate root all= (all) in the/etc/sudoers file and add and save the following:
Ads_yx all= (All) Nopasswd:all
3) view Current user
I. Viewing the UID and GID of the current user
[[email protected] home]# ID
Uid=0 (Root) gid=0 (root) groups=0 (root)
II. See who the current user is
[Email protected] home]# WhoAmI
Root
4) environment Variables
i. system Environment Variables
The system environment variable is placed in the/etc/profile file, making the environment variable effective as the source command
[Email protected] ~]# echo $PATH
/opt/lampp/bin:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/bin:/root/bin
II. User Environment variables
The user's own environment variable is placed in the. bash_profile file in the user's home directory * (the shell for this example is bash)
[Email protected] ~]# Su-ads_yx
[Email protected] ~]$ echo $PATH
/opt/lampp/bin:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr /sbin:/sbin:/home/ads_yx/bin
iii. env viewing environment variables
[[Email protected] ~]$ env
Shell=/bin/bash
Term=xterm
histsize=1000
Jre_home=/opt/jdk1.7.0_75/jre
User=ads_yx
......
Path=/opt/lampp/bin:/opt/jdk1.7.0_75/bin:/opt/jdk1.7.0_75/jre/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin :/usr/sbin:/sbin:/home/ads_yx/bin
......
5) user Group
Iv. Adding a user group
GROUPADD-G Group ID Group name
Cases:
[Email protected] ~]# groupadd-g 580 TESTCC
[Email protected] ~]# Cat/etc/group|grep TESTCC
testcc:x:580:
V. Modifying a user group
Groupmod-g New Group Id–n group new name group old name
Cases:
[Email protected] ~]# groupmod-g 581 TESTCC
[Email protected] ~]# Cat/etc/group|grep TESTCC
testcc:x:581:
Vi. Deleting a user group
Groupdel Group Name
Cases:
[Email protected] ~]# Groupdel TESTCC
[Email protected] ~]# Cat/etc/group|grep TESTCC
[[Email protected] ~]#--Query not to group information
Linux notes Linux user, group management