Learning records Linux user management

Article directory

Linux user management

1 user overview

1.1. Basic concept of user / group!

====================================================

Users and groups:

. Every process (running program) on the system runs as a particular user.

Every process (running program) on the system runs as a specific user

. Every file is owned by a particular user.

Each file is owned by a specific user

. Access to files and directories are restricted by user.

Access to files and directories is limited by users

. The user associated with a running process determines the files and directories accessible to that process.

The user associated with the running process determines which files and directories the process can access

#######################################################

linux learning camp 332868241

2 user management

=======================================================

groupadd ,groupdel useradd ,usermod ,userdel passwd ,chage

2.1 user groups
[root@tianyun ~]# groupadd hr

[root@tianyun ~]# groupadd it

[root@tianyun ~]# groupadd net01 -g 2000 / / add group net01 and specify gid 2000

[root@tianyun ~]# grep 'net01' /etc/group / / view the group net01 information in / etc/group

[root@tianyun ~]# groupdel net01 / / delete group net01
2.2 users

useradd creates users

= create user does not specify options =

 [root@tianyun ~]# useradd user01

‚Äč

. no primary group specified for this user

. no additional groups specified for this user

. user's HOME is not specified. User's SHELL is not specified

. no UID specified for user

[root@tianyun ~]# grep 'user01' /etc/passwd /etc/shadow /etc/group

/etc/passwd:user01:x507:512::/home/user01:/bin/bash /etc/shadow:user01:!!:16589:0:99999:7:::

/etc/group:user01: x:512:

[root@tianyun ~]# id user01

uid=507(user01) gid=512(user01) groups=512(user01)

shell[root@tianyun ~]# ls /var/spool/mail/user01 

/var/spool/mail/user01

***Summary: if no group (Primary Group or additional group) is specified when creating a user, the system will create a group with the same user name as the user's Primary Group

#####c.

2.3. Create user

Specified options

root@tianyun ~]# useradd user02 -u 503 / / create user usr02, specify uid

[root@tianyun ~]# useradd user03 -d /aaa / / create the home directory specified by user03
[root@tianyun ~]# useradd user05 -s /sbin/nologin / / create the user and specify the shell
[root@tianyun ~]# useradd user07 -G hr,it,fd / / create a user and specify an additional group
[root@tianyun ~]# useradd user10 -u 4000 -s /sbin/nologin

userdel deletes users

2.4 deleting users
[root@tianyun ~]# userdel user10 / / delete user user10, but do not delete user home directory and mail spool

[root@tianyun ~]# ll -d /home/user10/
drwx------ 3 506 510 4096 09-01 21:14 /home/user10/
[root@tianyun ~]# ll /var/spool/mail/user10 
-rw-rw---- 1 506 mail 0 09-01 21:14 /var/spool/mail/user10
[root@tianyun ~]# userdel -r user2 / / delete user2, and delete the user's home directory and mail spool

= user password =

[root@tianyun ~]# Passwd Alice / / root can set password for any user
[zhuzhu@tianyun ~]$ passwd                                      //Ordinary users can only modify their own secret

Code, and the original password must be provided

usermod modifies existing users

3 group member management

Note: only for existing users

[root@tianyun ~]# Usermod - G HR niniu2 / / overwrite the original additional group
[root@tianyun ~]# usermod -G fd,it niuniu2
[root@tianyun ~]# Usermod - Ag HR niniu2 / / add new add-on group

[root@tianyun~]# gpasswd -a jack wheel                     //usermod -aG hr zhuzhu
[root@tianyun~]# gpasswd -M zhuzhu,maomao100 hr            
[root@tianyun~]# gpasswd -d zhuzhu hr

= other options management =

[root@tianyun ~]# usermod -s /sbin/nologin niuniu2
Published 37 original articles, won praise 9, visited 5466
Private letter follow

Tags: Linux shell

Posted on Tue, 10 Mar 2020 22:29:33 -0700 by kidestranged