linux users and user groups


new user
useradd option new username


Options:
-c comment Specifies a commentary description.
-d directory Specifies the user home directory.
-g usergroup Specifies the user group to which the user belongs.
-G usergroup, specifies additional groups to which the user belongs.
-s shell file Specifies the user's login shell.

 

Such as: # useradd -s /bin/sh -g group -G adm,root hqq
This command creates a new user hqq, the user's login shell is /bin/sh, which belongs to the group user group, and also belongs to adm and root Additional groups, where group user group is its primary group.

 

In fact, adding a user account is to add a record for the new user in the /etc/passwd file, and update other system files such as /etc/shadow, /etc/group, etc.

 

change Password


-- Modify the password
passwd of the currently logged in user


-- Modify the password
passwd username of the specified user

 

-- View which users are in the system
vi /etc/passwd 


The content format is as follows:
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
uac:x:500:500::/home/uac:/bin/bash


Format description:
separated by colon, respectively username: password: uid: gid: description: home directory: Shell

 

delete user
userdel username

 

User group
Each user has a user group, and the system can centrally manage all users in a user group. Different Linux systems have different regulations on user groups. For example, a user under Linux belongs to a user group with the same name as it. This user group is created at the same time when a user is created.

The management of user groups involves the addition, deletion and modification of user groups. The addition, deletion and modification of groups are actually updates to the /etc/group file.

 

Create a new user group
groupadd
If the new user group name already exists;
[root@zh-v103 etc]# groupadd uac
groupadd: group 'uac' already exists

 

Each group has a label. The group identification number of the newly created group is based on the current largest group identification number plus 1
vi /etc/group View
mysql:x:27:
uac:x:500:
hqq:x :501:

 

delete user group
groupdel user group name

 

switch user group

If a user belongs to multiple user groups at the same time, the user can switch between user groups in order to have the permissions of other user groups. After logging in, users can use the command newgrp to switch to other user groups. The parameter of this command is the destination user group.
The newgrp root
command switches the current user to the root user group, provided that the root user group is indeed the primary or additional group of the user.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990237&siteId=291194637