Users and user groups are important components of linux. therefore, to learn about linux, you must at least use the most basic commands, next I will share my learning achievements 1. it is relatively simple to create a user group. just use the command sudo
Users and user groups are important components of linux. therefore, to learn about linux, you must at least use the most basic commands, next I will share my learning achievements.
1. create a user group
The creation of a user group is relatively simple. you only need to use the sudo groupadd command or sudo groupadd-g group ID name. The first command is very simple and I won't say much about it, for the second command, we need to know that the user group mainly exists in a configuration file in linux. the location of this configuration file is/etc/group. you can view the user group created in the system by using vi.
The user group configuration file is as follows:
In this figure, we should also know that numbers such as 117, 118, 119, 700, and 1006 represent the unique ID of the user group, in this way, it is not difficult to understand the second command. without-g and subsequent parameters, linux will assign us a user group ID.
2. modify User groups
In some cases, we may need to modify the user group, mainly by modifying the user group ID and group name. the command to modify the user group name is the old name of sudo groupmod-n, as shown below
If you want to modify the user group id, you can use the new group ID group name sudo groupmod-g.
The modified configuration file is as follows:
3. user creation and modification
User creation is also a basic component. There are two commands for creating a user. The first is the sudo useradd username, and the second is the username of the group to be allocated by sudo useradd-g. I recommend using the latter. The first command not only creates a new user, but also creates a group with the same name as the user name.
This command creates a user named xiaofei and adds it to the administrator Group. at this point, we must know that linux also stores the user in a configuration file, the file location is/etc/passwd. only create a user but not set a password. linux does not allow such a user to log on to the system. next we will set a password for the user. the command is the sudo passwd user name.
The next step is to delete the user group. the command for deleting the group is the sudo groupdel group name. the command for deleting a user is the sudo userdel username. by default, the user's directory is not deleted, if you want to delete the user's directory together, use the sudo userdel-r user name.
I cannot delete the group.
Next, let's talk about how to modify the user name. to modify the user name, run the command sudo usermod-l to change the old user name, as shown in
There is also a special user-modified command sudo usermod-c description or user name annotation, which means to add a comment or description to the user.
Another operation is also very important, that is, to specify an operable Directory for the user. the command is sudo usermod-d path username.
There are so many user operations.
3. linux limits certain users to log on to the system
Sometimes, for troubleshooting purposes, it may be necessary to temporarily restrict certain users to log on to the system. linux can also implement this restriction, provided that we understand that linux puts the user's password in that configuration file, in fact, the path of the simple user password configuration file is/etc/shadow. we only need to find the user's password and open the vi editor and add one before the password! The administrator privilege is required to modify the file. because the file is read-only, it should be forcibly written. add an exclamation point after wq.
The password here is encrypted with MD5, and is located at the end of the user name, as shown in the last and third lines. let's see if the xiaofeifei user can log on normally.
4. prohibit login by other users except root users
This operation is actually the easiest. just create a nologin folder under The etc directory. the command is sudo mkdir/etc/nologin.