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

Summary of basic commands of user Management in Linux system

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

Share

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

This article mainly introduces "basic command summary of user management in Linux system". In daily operation, I believe that many people have doubts about the basic command summary of user management in Linux system. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "basic command summary of user management in Linux system". Next, please follow the editor to study!

Know that the rights management of linux actually recognizes not your user name and password but your UID and GID, that is, your user ID and group ID.

The code is as follows:

> cat / etc/passwd

Root:x:0:0:root:/root:/bin/bash

Daemon:x:1:1:daemon:/usr/sbin:/bin/sh

The 0 above is the user id, and so is the group id. Of course, it is my current user root.

When a user logs in, he will log in according to your user name, such as whether there is a user in my root / etc/passwd. If he does not jump out, go to / etc/shadow to find the password of the corresponding uid, and finally log in.

The code is as follows:

Root: x: 0: 0: root: / root: / bin/bash

Root # user name

X # stands for password and is now stored in / etc/shadow

0 # user's Uid

# among them, root,1-100is created automatically by the distribution, and can be created when it is required by the system.

0 # user's GId

Root # user Information Bar description

/ root # Home directory

/ bin/bash # supports shell

# / etc/shadow

> cat / etc/shadow

Root:$6 $5SjcaJASqueEH0r0LsApaWsmpoz5Zoz4iSavI7nr.According to VVmUi5GnFYLsScVS7fTWz9JK7E8.. bNajM7jV2qBn9fck5oiGzx0N1UL 16147FYLsScVS7fWz9oiGzx0N1V147FYLsScVS7fWz9JK7E8.. bNajM7jV2qBn9fck5oiGzx0N1V147LsApaWsmpoz5Zoz4iSavI7nr.GVmUi5GnFYLsScVS7fTWz9JK7

Root # user name

$. 1 # it's very long. That's the password.

16147 # date when the password was changed

The date on which the 0 # password can be changed is relative to the previous 16147 change date, and 0 is changed at any time.

99999 # days of password re-change

7 # password warning, that is, the password is about to expire, windows users should have seen it

The seventh has no value # this is the password expiration date

Eighth field # account expiration date

Ninth field # reserved

General use of commands

Useradd-G user secondary group

The code is as follows:

> usermod-G users xiaowei

> grep xiaowei / etc/shadow / etc/passwd / etc/group

/ etc/shadow:xiaowei:!:16147:0:99999:7:::

/ etc/passwd:xiaowei:x:1001:1001::/home/xiaowei:/bin/sh

/ etc/group:users:x:100:xiaowei

/ etc/group:xiaowei:x:1001:

Groups supported by groups

The code is as follows:

> groups

Root xiaowei

Newgrp switching group

The code is as follows:

> newgrp xiaowei

> id

Uid=0 (root) gid=1001 (xiaowei) groups=0 (root), 1001 (xiaowei)

Useradd add account

Useradd [- u UID] [- g initial group] [- G secondary group] [- mM] [- c description column] [- d home directory absolute path] [- s shell] user account name

Options and parameters:

-u: followed by UID, a set of numbers. Directly assign a specific UID to this account

-g: the group name that follows is the initial group we mentioned above.

The GID of the group is placed in the fourth field of / etc/passwd.

-G: the group name that follows is the group that this account can also join.

This option and parameters will modify the relevant data in / etc/group!

-M: force! Do not create a user's home directory! (default value of system account)

-m: mandatory! To create a user's home directory! (default value of general account)

-c: this is the description of the fifth column of / etc/passwd. We can configure it as we like.

-d: specify a directory to be the home directory instead of using the default value. Be sure to use an absolute path!

-r: create a system account whose UID is limited (see / etc/login.defs)

-s: followed by a shell. If it is not specified, it defaults to / bin/bash ~

-e: followed by a date in the format "YYYY-MM-DD" this item can be written to the eighth field of shadow

That is, the configuration items of the account expiration date.

-f: followed by the seventh field entry of shadow, which specifies whether the password will expire or not. 0 means immediate invalidation

-1 to never expire (passwords only expire and are forced to be reconfigured when logging in.)

The code is as follows:

# add a widuuweb user. Uid forces the creation of a home directory for the 800group id1001, which is described as test home directory / root/test does not allow login

> useradd-U800-g 1001-m-c test-d / root/test-s / sbin/nologin widuuweb

> grep widuuweb / etc/passwd

Widuuweb:x:800:1001:test:/root/test:/sbin/nologin

Passwd change password

Passwd [- l] [- u] [--stdin] [- S] [- n days] [- x days] [- w days] [- I date] account passwd-l xiaowei # cannot be logged in at this time

> passwd-u xiaowei # unlocked and ready to log in

> passwd xiaowei # enter password to change password

# chage with the same function as passwd-S

Options and parameters:

-l: list the detailed password parameters of the account

-d: followed by the date, modify the third field of shadow (the date of the last password change), format YYYY-MM-DD

-E: followed by the date, modify the eighth field of shadow (account expiration date), format YYYY-MM-DD

-I: for the following days, modify the seventh field of shadow (password expiration date)

-m: following the number of days, modify the fourth field of shadow (minimum number of days of password retention)

-M: modify the fifth field of shadow for the following days (how long does the password need to be changed)

-W: following the number of days, modify the sixth field of shadow (warning date before password expires)

Usermod modifies user parameters

-c: followed by the account description, that is, the description column in the fifth column of / etc/passwd, you can add some account description.

-d: followed by the home directory of the account, that is, modify the sixth column of / etc/passwd

-e: the date is followed by the date, and the format is YYYY-MM-DD, which is the eighth field data in / etc/shadow!

-f: the number of days followed by the seventh field of shadow.

-g: followed by the initial group, modify the fourth field of / etc/passwd, which is the field of GID!

-G: this is followed by a secondary group. Modify the group that the user can support. The modification is / etc/group ~

-a: in conjunction with-G, you can "add secondary group support" instead of "configuration"!

-l: followed by the account name. That is, modify the account name, the first column of / etc/passwd!

-s: followed by the actual file of Shell, such as / bin/bash or / bin/csh, etc.

-u: followed by the UID number! That is, the data in the third column of / etc/passwd

-L: temporarily freeze the user's password so that he can't log in. Actually only change the password bar of / etc/shadow.

-U: set / etc/shadow password bar! Take it off! it's thawing!

The code is as follows:

> usermod-c nihao xiaowei

Xiaowei:x:1001:1001:nihao:/home/xiaowei:/bin/sh

> usermod-d / root/xiaowei xiaowei # xiaowei home directory is this location

> usermod-s / sbin/nologin xiaowei

> su xiaowei

# unable to log in

Cannot execute / sbin/nologin: No such file or directory

Userdel Delete user

The code is as follows:

> userdel widuuweb # Delete user userdel-r widuuweb along with the home directory

Id

I used it before.

The code is as follows:

> id xiaowei # displays user group information for users

Uid=1001 (xiaowei) gid=1001 (xiaowei) groups=1001 (xiaowei), 100 (users)

Groupadd add Group

The code is as follows:

> groupadd-g 102-r xiaowei #-g group id optional-r group name

> groupadd widuuweb

> grep widuuweb / etc/group

# widuuweb:x:1003:

Groupmod modify group information

The code is as follows:

Groupmod [- g gid] [- n group_name] group name

> groupmod-g 201-n widuu xiaowei

Groupdel delete group

The code is as follows:

> groupdel widuu

Gpasswd group management

Options and parameters:

: if there are no parameters, give groupname a password (/ etc/gshadow)

-A: hand over the control of groupname to the later users (the administrator of this group)

-M: add some accounts to this group!

-r: remove the password for groupname

-R: invalidate groupname's password bar

The code is as follows:

> gpasswd-A xiaowei widuu # xiaowei join the widuu group

> gpasswd widuu # set password

> gpasswd widuu xiaowei1 # talk about xiaowei1 joining the group

At this point, the study on the "summary of basic commands for user management in the Linux system" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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