Summary of common commands for Linux user and group management

Summary of common commands for Linux user and group management

This article summarizes the common commands for Linux user and group management. Share with you for your reference, the details are as follows:

1. The user belongs to a user group.

2. User and User Group Profiles

1) User group configuration file

/etc/group

First column: group name of the user group Second column: group password (the real password is stored in gshadow)
The third column: User group ID, unique identifier of the user group
The group ID 0 is the super user group
Group IDs 1-499 are system user groups
Group ID greater than 500 is a user-defined group. Fourth column: Group members

2) User group password configuration file

/etc/gshadow

First column: User group name Second column: Password Third column: Group administrator Fourth column: Group member

3) User Profile

/etc/passwd

First column: User name Second column: User password, only one x placeholder, the password is stored in shadow Third column: User ID, unique identifier
User ID 0 is the super user
User IDs between 1 and 499 are system users. User IDs greater than 500 are custom users. Fourth column: Group ID of the group to which it belongs.
Fifth column: Remarks information Sixth column: User's home directory (home). When a user logs into the system, he or she is logging into home.
Column 7: Shell type

4) User password configuration file

/etc/shadow

First column: User name Second column: Password (!! means no password, login is not allowed)

3. User group management

groupadd group name to add user group
-g : Specify the group ID when adding a group

groupmod group name modifies user group information
-n: Modify group name
-g : Modify group ID

groupdel group name delete group

*If there are users under a group, the group cannot be deleted.

4. User Management

useradd [parameter] user name add user
-g group name specifies the group to which it belongs
-d directory specifies the user's home directory

*When adding a user, if you do not specify a group, the system will create a group with the same name as the user.

usermod [parameter] username
-c comment Modify the comment information
-l username Modify username
-d directory changes the user's home directory
-g group name Modify user group

userdel [parameter] user name
-r delete the user's home directory

5. Password Management

passwd [options] username
-S View user password status
-l lock the user's password (prohibit login)
-u Unlock user password
-d delete user password

6. Prohibit account login

There are two situations:
Disable an account from logging in

/etc/shadow

Modify the shadow directly and add two before the user password! No., prohibiting the user from logging in.

It is recommended to use: passwd -l username to prohibit user login.

Prohibit all accounts from logging in

/etc/nologin

Create a nologin file under /etc/ so that no users can log in.

7. Add and delete group members

*usermod -g is to modify the user's primary group

gpasswd [options] groupname
-a username: add group members
-d username: delete group members

The default identity of a user after logging in is his primary group identity.

You can use newgrp to switch the group identity to which it belongs, provided that it also belongs to this group.

The created file belongs to the group to which the current user identity switches.

I hope this article will be helpful to everyone's Linux management.

You may also be interested in:
  • How to create, modify, and delete users and groups in Linux
  • Solution to Linux cannot use userdel to delete users and groups
  • Linux user and group commands summary and detailed introduction
  • Some examples of linux search filtering and user and group management commands
  • Guide to user and group configuration management in Linux operating system
  • How to modify the group to which a user belongs in Linux
  • Implementation of effective user groups and initial user groups in Linux
  • Summary of Linux user groups and permissions
  • Summary of 4 ways to add users to groups in Linux
  • Detailed explanation of adding/deleting users and user groups in Linux
  • How to view all users and user groups in Linux (modify user groups)
  • Linux user and group command example analysis [switching, adding users, permission control, etc.]

<<:  Detailed steps to install MYSQL8.0 on CentOS7.6

>>:  SQL interview question: Find the sum of time differences (ignore duplicates)

Recommend

ElementUI implements sample code for drop-down options and multiple-select boxes

Table of contents Drop-down multiple-select box U...

MYSQL stored procedures, that is, a summary of common logical knowledge points

Mysql stored procedure 1. Create stored procedure...

JavaScript uses promise to handle multiple repeated requests

1. Why write this article? You must have read a l...

W3C Tutorial (13): W3C WSDL Activities

Web Services are concerned with application-to-ap...

js to realize web music player

This article shares simple HTML and music player ...

How to forget the root password in Mysql8.0.13 under Windows 10 system

1. First stop the mysql service As an administrat...

How to insert batch data into MySQL database under Node.js

In the project (nodejs), multiple data need to be...

Vue implements interface sliding effect

This article example shares the specific code of ...

Share CSS writing standards and order [recommended for everyone to use]

CSS writing order 1. Position attributes (positio...

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...

MySQL 5.7.21 installation and password configuration tutorial

MySQL5.7.21 installation and password setting tut...

Centos8.3, docker deployment springboot project actual case analysis

introduction Currently, k8s is very popular, and ...

12 Laws of Web Design for Clean Code [Graphic]

Beautiful code is the foundation of a beautiful we...