In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the account management commands useradd and groupadd in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Summary of content:
1. Master the user's add / delete / change commands
two。 Master the add / delete / change commands of the group
Group management
1) groupadd
Groupadd is used to add group accounts. The format is as follows: groupadd [- g GID] GROUP
Where:
GROUP: is the group name to be added
-g: used to specify GID. Default is to use the current maximum GID plus 1.
Example: add a new group leader
# groupadd leader
# grep leader / etc/group
Leader:x:504:
# grep leader / etc/gshadow
Leader:!::
2) groupmod
Groupmod is used to modify group accounts that already exist in the system. Format is as follows: groupmod [options] GROUP
Where:
GROUP: for the group account name to be modified
Common options:
-g GID: reassign GID
-n NEW_GROUP: rename the group to NEW_GROUP
Example: rename the leader group to leaders
# groupmod-n leaders leader
# grep leader / etc/group
Leaders:x:504:
Change the GID of the leaders group to 3000
# groupmod-g 3000 leaders
# grep leader / etc/group
Leaders:x:3000:
3) groupdel
Groupdel is used to delete group accounts that already exist in the system. Format is as follows: groupdel GROUP
Where: GROUP is the group account name to be deleted
For example: delete leaders group
# groupdel leaders
# grep leaders / etc/group
# grep leaders / etc/gshadow
User management
1) useradd
Useradd is used to add user accounts or to set default information for adding users. The format is as follows:
Format 1:useradd [options] LOGIN
Format 2:useradd-D
Format 3:useradd-D [options]
Description:
Format 1: used to add user accounts, and LOGIN logs in accounts for users
Format 2: used to display default information used by added users
Format 3: used to set the default information used by adding users
Add user options:
Option description
-u UID specifies the UID of the new user. The default is to use the current maximum UID plus 1
-g GROUP specifies the primary group of the new user
-G GROUP1 [, GROUP2, … [, GROUPN] specify additional groups for new users
-d HOME_DIR specifies the login directory of the new user
-s SHELL specifies the Shell used by new users, which defaults to bash
Change the user default option:
User default data is stored in the configuration files / etc/login.defs and / etc/default/useradd.
Examples of use:
1. Create a new user newuser and create your own directory
# useradd newuser
2. Create a new user tom and join the staff additional group at the same time
# useradd-G staff tom
3. Create a new user webmaster, do not create your own directory, specify the login directory / www, and join the apache additional group.
# useradd-d / www-M-G apache webmaster
2) usermod
Usermod is used to modify group accounts that already exist in the system. Format is as follows: usermod [options] LOGIN
Where:
LOGIN: for the user account name to be modified
Options:-c,-d,-e,-f,-g,-G,-s,-u have the same meaning as the useradd option
The following options have been added:
-l NEW_LOGIN: change the user login name to NEW_LOGIN
-c COMMENT describes the user's additional information, such as full name, etc.
-e EXPIRE_DATE specifies the login expiration time of the user in the format of YYYY-MM-DD
-f INACTIVE specifies how many days to close the account after the password expires. The default value is-1, that is, there is no limit.
-k SKEL_DIR specifies the skel directory, which is stored in / etc/skel/ by default
-m to create a new user's own directory, default
-M does not create a new user's own directory
Option description
-b BASE_DIR
Defines the parent directory of the directory to which the user belongs. The user name is appended to the BASE_DIR to create the directory for the new user. When
However, this option has no effect after using-d.
-e
EXPIRE_DATE
Define the expiration date of the user account.
-f INACTIVE defines how many days after the password expires, the account will be closed.
-g GROUP defines the starting group name or GID of a new account. The group name must be an existing group name. GID must also be an existing GID.
The-s SHELL defines the shell that the user uses by default.
-L: lock user account
-U: unlock the user account
For example:
1. Add newuser2 to the group staff
# usermod-G staff newuser2
2. Modify the user name of newuser to newuser1
# usermod-l newuser1 newuser
3. Lock the account newuser1
# usermod-L newuser1
4. Unlock newuser1
# usermod-U newuser1
3) userdel
Userdel is used to delete group accounts that already exist in the system. Format is as follows: userdel [- r] LOGIN
Where:
LOGIN: for the user account name to be deleted
-r: delete both the user's own directory and mail's spooled files
For example:
1. Delete user webmaster
# userdel webmaster
2. Delete the user newuser1 and delete his or her own directory
# userdel-r newuser1
Thank you for reading! On "linux account management commands useradd, groupadd how to use" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.