Linux-(10) users and groups in Linux, linux-linux
Like Windows, when we use Linux, we also need to log on as a user, and a process also needs to run as a user. Users can restrict the use of users or processes, resources cannot be used.
When we use Linux, we use a user name to access the system. In fact, in Linux, every user has a UserID, the operating system actually uses the user ID to differentiate users, rather than the user name we use to log on to the system.
In Linux, each user belongs to one or more affiliated groups. By default, the master group is the same as the user name. That is to say, a group with the same name is created by default when you create a user.
Like a user, each group also has a GroupID.
In Linux, each process runs as a user, and the access permission of the process is restricted by the user's permissions.
Files in Linux have a user and group.
User ID:
The User ID in Linux is 32 bits, starting from 0.
There are three types of user IDs:
Root User: user with ID 0
System User: ID 1-499
Common User: The ID is more than 500
To be compatible with legacy systems, user IDs are generally limited to less than 60000
Save user and group-related files:
/Etc/passwd this file saves user information
The/etc/shadow file saves the user password (encrypted of course)
The/etc/group file stores group information.
/Etc/passwd file structure:
The/etc/passwd file is a plain text file. One user information is saved in one row, separated.
First parameter: User Name
The second parameter is usually x, which means that the password is stored in/etc/shadow.
Third parameter: User ID
Fourth parameter: Group ID
Fifth parameter: User description. There is no requirement to enter any text.
Sixth parameter: user's home directory
Seventh parameter: the user logs on to the shell. The common user is/bin/bash.
/Etc/shadow file structure:
The structure of this file is the same as that of/etc/passwd, but there is only one thing, Two exclamation points "!" Indicates that this user has not created a password.
/Etc/group file structure:
Group Name: group password: Group ID: User
Create a user:
Useradd <User Name>
Parameters:
-D home directory
-G main family
-S logon shell
-G affiliated group (up to 31, separated by commas)
-U userId
When you execute the useradd command, the system will actually perform the following operations (in CentOS, RedHat is like this, Ubuntu seems to be slightly different)
1. Add User information to/etc/passwd
2. If you use the passwd command to create a password, save the password in/etc/shadow.
3. Create a new home directory for the user under/home. The directory name is the user name.
4. copy the files in the/etc/skel directory to the user directory. There are Documents, downloads, and desktops.
5. Create a group with the same user name, that is, create a primary group for the user.
Modify user:
Usermod <parameter> <User Name>
Parameters:
-L New User Name
-U new userId
-D New Home directory location
-G: Modify the user group
-L locking a user makes it unable to log on
-U unlock
Delete A User:
Userdel <username> only deletes users and keeps the user's home directory
Userdel-r <User Name> delete a user and delete the user's home directory
Create group:
Groupadd <Group Name>
Modify group:
Groupmod-n <New Group Name> <old group name> modify group name
Groupmod-g <new group ID> <old group ID> modify group ID
Delete group:
Groupdel <Group Name>
User-related commands:
Id: displays information about the current user.
Passwd <user> modifies the user's password. If the user is not added, the current user's password is changed.
Whoami displays the current user
Who shows which users have logged on to the system
W shows which users have logged on and what are they doing
Reprinted please indicate the source