Linux user and group management (command gymnastics)

Reference Catalog for Linux learning sequence: https: //www.cnblogs.com/lv1572407/p/11815911.html

 

  First, let's look at the command associated with the user and group management.
User management commands: useradd, usermod, usedel, passwd and chage.
Group management commands: groupadd, groupdel, groups and gppasswd.

First, let's learn how to use these commands properly and commonly used techniques.

1. The user group management
[mysql1 the root @ ~] # 1000 group001 the groupadd -g
[mysql1 the root @ ~] # 2000 group002 the groupadd -g
[mysql1 the root @ ~] # 3000 group003 the groupadd -g
[mysql1 the root @ ~] # the groupadd - 4000 group004 G
[mysql1 the root @ ~] # 5000 group005 the groupadd -g
can -g parameter specifies the GID creating groups. Many large commercial software may be needed, such as: ORACLE 11G installation.
[root @ mysql1 ~] # groupdel group005
groupdel command is no help book, do not need to specify any options, you can directly specify the name of the group to be deleted.
In fact, there is a set of management commands groupmod command, but generally not used, you need to know can --help look.

2. User Management
[root @ mysql1 ~] # useradd -u 1000 user001 // specify the user UID
[root @ mysql1 ~] # useradd -d / root / user002 user002 // specify the user's home directory
[root @ mysql1 ~] # useradd -s / sbin / nologin user003 // specified login shell bash
[root @ mysql1 ~] # useradd -c 'user006 info' user006 // you Add user prompt
GID [root @ mysql1 ~] # useradd -g 1000 user004 // specified group
[root @ mysql1 ~] # useradd -G group001, group002 user005 // add subsidiary group
These are some of the options is to create a user might use, have been described using the method to actual cases.
After learning million users to create, we come to learn how to delete users.
[root @ mysql1 ~] # all the relevant information userdel -r test001 // delete the system in
this really safe? A user can be deleted, but will delete does not quite sound its associated files.
Two ways to solve this problem, one is to delete the backup files in advance, another user can delete, but do not directly delete related files.
The first way is easy to understand. So we will explain in this second way.
[root @ mysql1 ~] # userdel user001 // delete only user
[root @ mysql1 ~] # cp / home / user001 / * / bak // data backup
[root @ mysql1 ~] # rm -rf / home / user001 / / / delete files involved
[root @ mysql1 ~] # RM -rf / var / spool / mail / user001
Tips: so much trouble just to explain all human command "userdel -r test001" not casually use.

3. Add and delete user groups
to add users to the specified group when creating a user directly
[root @ mysql1 ~] # useradd -g group003 -G group001, group002 user005

addition can modify group affiliated with the usermod command.
[root @ mysql1 ~] # the usermod -g group001 user004
[root @ mysql1 ~] # group002 the usermod -G, group003, group004 user004
Tips: Be careful when using the -G specified subsidiary, will cover all existing affiliated groups. So this command is a black hole, try not to use.
[root @ mysql1 ~] # -Ag group002 the usermod, group003, group004 user004
Tips: -a combination of common use with the -G option, affiliated group will be assigned an additional operation.

In addition useradd and usermod, gpasswd command may be arranged a group of related users.
[root @ mysql1 ~] # gpasswd -d user004 group004 // remove a user from a group
[root @ mysql1 ~] # gpasswd -a user004 group004 // add users to groups

expand knowledge of how to modify the owner is a group of files :
[root@mysql1 ~]# chown mysql.mysql /dir1000/file1000
[root@mysql1 ~]# ls -l /dir1000/file1000
-rw-r--r--. 1 mysql mysql 0 Jun 13 17:38 /dir1000/file1000
[root@mysql1 ~]# chown .root /dir1000/file1000
[root@mysql1 ~]# ls -l /dir1000/file1000
-rw-r--r--. 1 mysql root 0 Jun 13 17:38 /dir1000/file1000
[root@mysql1 ~]# chown tom. /dir1000/file1000
[root@mysql1 ~]# ls -l /dir1000/file1000
-rw-r--r--. 1 tom tom 0 Jun 13 17:38 /dir1000/file100
[root@mysql1 ~]# chown mysql.mysql -R /dir1000/
[root@mysql1 ~]# ls -l -d /dir1000/
drwxr-xr-x. 2 mysql mysql 4096 Jun 13 17:38 /dir1000/
[root@mysql1 ~]# ls -l /dir1000/file1000
-rw-r--r--. 1 mysql mysql 0 Jun 13 17:38 /dir1000/file1000
tips1: When only the specified owner to modify the user belongs to the group will also change.
tips2: -R option may be used by all objects in a recursive manner catalog changes the owner and group.

Guess you like

Origin www.cnblogs.com/lv1572407/p/11816104.html