Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Management of Linux user accounts and groups

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Taking the Linux system as an example, this paper analyzes how to manage user accounts and groups with commands in the Linux system. After reading the complete article, I believe you have a certain understanding of the use of managing user accounts and group commands.

Managing user accounts 1. Overview of user accounts

Linux controls access to resources based on the user's identity.

2. User account management 1) user account

Super user (root)

Ordinary user

Program user

UID (User IDentify) user identification number; ① user account file / etc/passwd

The / etc/passwd file is used to store basic information such as user name, host directory, login Shell, etc.; each line corresponds to a user's account record. As shown below:

② user account file / etc/shadow

/ etc/shadow file is used to save the user's password, account validity and other information, and each line corresponds to a user's password record. As shown below:

3. Add user account

The commands and common options for adding user accounts are in the following format:

Application examples:

[root@centos01] # useradd-d / bob-g root-G root bob [root@centos01] # tail-2 / etc/passwddhcpd:x:177:177:DHCP server:/:/sbin/nologinbob:x:1001:0::/bob:/bin/bash [root@centos01] # useradd-M-s / sbin/nologin tom [root@centos01] # tail-2 / etc/passwdbob:x:1001:0::/bob:/bin/bashtom:x:1002:1002::/home/tom:/sbin/nologin4, Set / change user password passwd

The basic command format syntax and common options for setting / changing a user's password are as follows:

Application examples:

[root@centos01 ~] # passwd bob changes the password of the user bob. New password: invalid password: password failed dictionary check-oversimplified / systematic re-entry of the new password: passwd: all authentication tokens have been successfully updated. [root@centos01 ~] # passwd-l bob locks the password of the user bob. Passwd: operation succeeded [root@centos01 ~] # passwd-S bob bob LK 2020-01-11 0 99999 7-1 (password is locked.) [root@centos01 ~] # passwd-u bob unlocks the password of user bob. Passwd: operation succeeded [root@centos01 ~] # passwd-S bob bob PS 2020-01-11 0 99999 7-1 (password has been set, use SHA512 algorithm.) [root@centos01 ~] # passwd-d bob clears the user's password bob. Passwd: operation succeeded [root@centos01 ~] # userdel-r bob [root@centos01 ~] # tail-2 / etc/passwddhcpd:x:177:177:DHCP server:/:/sbin/nologintom:x:1002:1002::/home/tom:/sbin/nologin5, initial configuration file of user account

When the file comes from the new user account, it is copied from the / etc/skel directory. The main user initial configuration files are as follows:

~ / .bash_profile: executed every time you log in.

~ / .bashrc: executes every time you enter a new Bash environment.

~ / .bash_logout: executed every time you log out. 2. Management group account 1. Overview of group account

Basic group (private group)

Additional groups (public groups)

GID: group ID 1) Group account file / etc/group

/ etc/group file is used to save the basic information of the group account, as shown below:

[root@centos01 ~] # cat / etc/grouproot:x:0:bin:x:1:daemon:x:2:sys:x:3:adm:x:4:tty:x:5:. 2) Group account file / etc/gshadow

The / etc/gshadow file is used to save the password information of the group account, as shown below:

[root@centos01 ~] # cat / etc/gshadowroot:::bin:::daemon:::sys:::adm:::tty:::. 2. Add group account groupadd

The basic format of the command to add a group account is as follows:

Application examples:

[root@centos01 ~] # groupadd-g 200 accp [root@centos01 ~] # tail-3 / etc/grouptcpdump:x:72:test:x:1000:accp:x:200: [root@centos01 ~] # groupadd benet [root@centos01 ~] # tail-3 / etc/groupdhcpd:x:177:tom:x:1002:benet:x:1003:3, add and delete group member gpasswd

Set the group account password and add / delete group members. The basic format and common options of the command are as follows:

Application examples:

[root@centos01 ~] # gpasswd-a bob benet is adding user "bob" to the "benet" group [root@centos01 ~] # tail-2 / etc/grouptom:x:1002:benet:x:1003:bob [root@centos01 ~] # gpasswd-M tom,lisi benet [root@centos01 ~] # tail-2 / etc/groupbenet:x:1003:tom Lisilisi:x:1004: [root@centos01 ~] # gpasswd-d tom benet is deleting the user "tom" from the "benet" group [root@centos01 ~] # tail-2 / etc/groupbenet:x:1003:lisilisi:x:1004:4, deleting the group account groupdel

The basic format of the command to delete a group account is as follows:

Application examples:

[root@centos01 ~] # groupdel benet 5. Specify a group when adding a user account

The "- g" option in the useradd command specifies the user's base group name (or GID number), and the "- G" option specifies the user's additional group name (or GID number).

Application examples:

[root@centos01 ~] # useradd-d / bob-g root-G root bob [root@centos01 ~] # tail-2 / etc/passwddhcpd:x:177:177:DHCP server:/:/sbin/nologinbob:x:1001:0::/bob:/bin/bash6, query account information 1) id command

Id is used to query the user identity. The basic syntax format of the command is as follows:

Application examples:

[root@centos01 ~] # id bob uid=1003 (bob) gid=0 (root) group = 0 (root), 1005 (benet) 2) groups command

The groups command is used to query the group to which the user belongs. The basic syntax format of the command is as follows:

Application examples:

[root@centos01 ~] # groups bob bob: root benet3) finger command

The finger command is used to query the details of a user account. The basic syntax format of the command is as follows:

4) users, w, and who commands

The users, w, and who commands are used to query user information that is logged in to the host. Examples of applications are as follows:

[root@centos01 ~] # usersroot [root@centos01 ~] # w 01:57:23 up 53 min, 1 user, load average: 0.00,0.01 0.01USER TTY FROM LOGIN@ IDLE JCPU PCPU WHATroot pts/0 192.168.100.254 01:04 3.00s 0.05s 0.00s w [root@centos01] # [root@centos01] # whoroot pts/0 2020-01-17 01:04 (192.168.100.254)

So much for the management of Linux user accounts and groups. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report