Linux commands for managing users

Time:2021-6-24

Linux user management

1)

View current user
whoami        ##View current user

2)

View of users in the system
ID # view the specified user ID information
id
    -View the user's UID
    -G # view the user's gid
    -G #######################35
    -Display name instead of ID number

User switching

Su - user name
Su - middle "-" indicates that the current user's environment is switched at the same time when the user's identity is switched
Su - during execution, the senior user does not need a password to switch to the junior user, the junior user needs to switch to the senior user, and the peer user also needs to switch
Note: every time Su switches to another user, you must exit, and then switch to another user again

Storage mode of users in the system

how to create users and groups in Linux
/etc/passwd

User information file
User name: Password: uid: GID: Description: Home Directory: default shell

/etc/group

User group information file
Group name: group password: group ID: group member

/etc/shadow

Certification information file
User name;
User password;
The last time the user password was changed;
The shortest valid period of password;
The longest valid period of password;
Password warning period;    
Password inactive period;
Password expiration date;
User defined location is not enabled at present

/etc/skel/.*

By default, the shell configuration is enabled, and the user's bone file is saved

/home/username

User's home directory

User management command

1)
how to delete users with userdel in Linux

Userdel student # # # # # # # # # # # # # # # # # # # # # # # # #
Userdel - R student # delete the user and delete the user's profile

2)
how to create user with usereadd in Linux

watch -n 1 'tail -n 3 /etc/passwd /etc/group;ls -l /home'
Useradd ###########################
Useradd - U 8888 westos? Specify user UID
Useradd - G 21 westos # specifies the initial group ID of the user, "21 user group must exist"
Useradd - G 21 westos # specifies the user additional group ID, "21 user group must exist"
Uesradd - C "DASD" westos # specify user description
Useradd - D / home / Tong westos # specifies the user's home directory
Useradd - S / bin / Sh westos # specifies the user's default shell
Groupadd create group
Groupadd - G # specifies the group ID
Goupdel delete group
[how userdel works in Linux](https://www.howtouselinux.com/post/how-userdel-works-in-linux)

3) Change user information
usermod
Usermod – L new name westos change the name of the user
Usermod – U 6666 westos # change user UID
Usermod – G 21 westos # change the user’s initial group
Usermod – G 72 westos # add additional groups for users
Usermod – G “” westos # delete all additional groups of users
Usermod – Ag 21 westos # add user additional group
Usermod – C “hahah” westos # specifies the user description
Usermod – D / home / Tong westos # change the user’s home directory to
Usermod – MD / home / Tong westos # change user directory
Usermod – S / bin / Sh westos # change user shell
Usermod – L westos # freeze users
Usermod – u westos # unlock user

User authentication information

Using passwd command in Linux to change password
/Etc / shadow authentication information file
There are nine columns in this file
User name;
User password;

Passwd student change password
Passwd - L student # add "!" before the user password
Passwd - U student # remove "!" before user password
Passwd - D student? Clear password    
Usermod - L student # add "!" before the user password
Usermod - U student # remove "!" before password

fix warning your password has expired in Linux

be careful:

When ordinary users change their passwords
1. You must know the current permanent original password
2. The password cannot be similar to the account name
3. The password cannot be pure numbers or letters
4. The password cannot be an orderly combination of letters and numbers

The last time the user password was changed;

Passwd - e westos # will change the last password change time to 0
            ##Users are forced to change their password when logging in
Chage - d 0 #, the two commands have similar functions

The shortest valid period of password;

Passwd - N 1 westos user cannot change password within 1 day
chage -m 1  westos

The longest valid period of password;

Passwd - x 30 westos # set westos must change password within 30 days
chage -M  30 westos

Password warning period;

Passwd - W 2 westos # warning output two days before password expiration
chage -W 2

Password inactive period;

Passwd - I 1 westos # the number of days after the password has expired that you can still log in
chage -I 1  westos

Password expiration date;

Chage - e November 11, 2018 westos users will be frozen on November 11, 2018

User defined location is not enabled at present

User authorization

User authorization profile

/etc/sudoers/

Authorization configuration command

visudo

Standard operation
There are about 100 lines in the file

Normal user host name = (convert to new user identity) command 1, command 2.
Normal user host name = (convert to new user identity) nopasswd: Command

Example:
Westos host name = (root) / usr / SBIN / useradd # the password is required to execute the command
Westos host name = (root) nopasswd / usr / SBIN / usradd
—————————————