In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the usage of Linux command useradd and userdel". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the usage of "Linux command useradd and userdel".
[root@test etc] # useradd-- help
Useradd: invalid option
Usage: useradd [- u uid [- o]] [- g group] [- G group,...]
[- d home] [- s shell] [- c comment] [- m [- k template]]
[- f inactive] [- e expire] [- p passwd] [- M] [- n] [- r] name
Useradd-D [- g group] [- b base] [- s shell]
[- f inactive] [- e expire]
When the-D parameter is not added, the useradd instruction uses the command line to specify the set value of the new account and uses the default value on the system. The new user account will generate some system files, user directory creation, copy starting files, etc., all of which can be specified by command line options. This version is available for RedHatLinux.
Parameter description:
-u the user's ID value. Must be a unique ID value unless you use the-o option. The number cannot be negative. The default is that the minimum must not be less than 999 and increase one by one. 0room999 is traditionally reserved for system accounts.
-g specifies the group to which the user belongs. Name or number as the user login starting group (group). The group name must be an existing name. The group number must also be an existing group. The default group number is 1.
-G specifies the additional group to which the user belongs. Define this consumer as a member of this pile of groups. Each group is separated by "," and cannot be mixed with blank characters. The group name is the same as the-g option. Defines the value as the starting group of the user.
-d specifies the starting directory when the user logs in. The home_dir used each time the new account logs in. The default value is the login name in default_home and is used as the directory name when logging in.
-s the shell name used by the user after login. The default is left empty, so the system will help you specify the default login shell.
-c add the remarks to the new account (the description column of the password file), and the remarks will be saved in the remarks field of passwd.
The-m user directory is automatically created if it does not exist. If you use the-k option, the files in skeleton_dir will be copied to the user directory. However, files in the / etc/skel directory will also be copied and replaced. Any directory in skele-ton_dir or/etc/skel will also be created one by one under the user directory. The-k does not establish a directory with-m and does not copy any files as default values.
-M does not create a user directory, even if the / etc/login.defs system file is set to create a user directory.
-n the default user group and user name will be the same. This option cancels this default value.
-f specifies how many days after the password expires, the account will be closed. When the value is 0, the account is suspended immediately. When the value is-1, this feature is turned off, and the default value is-1.
-e specifies the end date of the account. The specified format of the date is MM/DD/YY.
-r this parameter is used to establish a system account. The UID of the system account will be defined on the system file / etc/login.defs. The UID_MIN is small. Note that the account created by useradd does not create a user directory, nor does it care about the record in / etc/login.defs. The defined value of the If you want to have a user directory, you need to specify the-m parameter to create a system account. This is an additional option for REDHAT.
The-p user can set the password when creating the account. The-p parameter is followed by the ciphertext. The ciphertext corresponding to the password can be found in the / etc/shadow file.
-D change the default value.
Change the preset value (not tested, rarely used)
When the-D option appears, useradd shows the current default value, or updates the default value through the command line. The available options are ∶
-b default_home defines the previous directory of the directory the consumer belongs to. The user name is appended to the default_home to create the directory for the new user. Of course, this option has no effect after using-d.
-e default_expire_date user account stop date.
-f the default_inactive account will be suspended after a few days of expiration.
-g default_group new account starting group name or ID. The group name must be an existing name. The group ID must also be an existing group.
-s shell name used by default_shell users after login. All new accounts will use this shell.
If no parameters are specified, useradd displays the currently preset values.
Notes
System administrators have an obligation to place user-defined files in the / etc/skel directory. This version of "useradd" is modified by RedHat.
Warning
No new users can be added to the NIS group. You must run it on the NIS server.
archives
/ etc/passwd-user account information
/ etc/shadow-user account information encryption
/ etc/group-Group Information
/ etc/default/useradd-definition information
/ etc/login.defs-system generalized setting
/ etc/skel-the directory containing the definition file
Useradd default value:
The above example can let us know that the system has already standardized some parameters when adding users, such as I did not specify the user's home directory, nor did I specify the user's UID and GID, but the system will help us to add it for the user, and its default shell is set to / bin/bash, which also let me know that you must have root permission to use the useradd command. So, what is the default value for useradd to add new users? The default value can be displayed using the-D parameter of useradd mentioned above, and as you can see, the value is exactly the same as in the / etc/default/useradd file. When you use useradd to add users in linux, some values in / etc/passwd will refer to the file / etc/default/useradd. The contents of the file are basically as follows:
# useradd defaults file
GROUP=100 # default user group
Address of HOME=/home # home directory
The grace time for the expiration of the INACTIVE=-1 # password, corresponding to the seventh column of / etc/shadow
Expiration date of EXPIRE= # account, corresponding to column 8 of / etc/shadow
SHELL=/bin/bash # shell used by default
The content reference files in the SKEL=/etc/skel # user's home directory (it is basically full of hidden files-> with "." File at the beginning)
CREATE_MAIL_SPOOL=yes# establishes the user's mailbox
For example:
Example 1: add a mail_0001 account, which belongs to the mailuser group. The password is 1234 (\ $1\ $m3eaGHpj\ $Gs5ElcfoROkdAgwZ1j8XC0 if the ciphertext is 1234), and you do not have the permission to log in to the system:
Useradd-p\ $1\ $m3eaGHpj\ $Gs5ElcfoROkdAgwZ1j8XC0-g mailuser-s / sbin/nologin mail_0001
Example 2: create a new user chongpig by default without adding any parameters
[root@xiaoxiaozi simaopig] # useradd chongpig
Search the chongpig account in several files associated with the user.
[root@xiaoxiaozi simaopig] # grep chongpig / etc/passwd / etc/shadow / etc/group
/ etc/passwd:chongpig:x:501:501::/home/chongpig:/bin/bash
/ etc/shadow:chongpig:!!:14446:0:99999:7:::
/ etc/group:chongpig:x:501:
Example 3: create a new account simaopig2, and see that UID 888 does not exist, then assign it to simaopig2 and add it to the mysql group:
[root@xiaoxiaozi simaopig] # grep 888 / etc/passwd
[root@xiaoxiaozi simaopig] # useradd-u 888-g mysql simaopig2
[root@xiaoxiaozi simaopig] # grep simaopig2 / etc/passwd / etc/shadow / etc/group
/ etc/passwd:simaopig2:x:888:27::/home/simaopig2:/bin/bash
/ etc/shadow:simaopig2:!!:14446:0:99999:7:::
Userdel command:
Function description: delete user account.
Syntax: userdel [options] [user account]
Supplementary note: userdel can delete user accounts and related files. If no parameters are added, only the user account will be deleted, not the related files.
Parameters:
-f Delete the user login directory and all files in the directory.
-r Files in the user directory will be removed, and files in other locations will be found and deleted one by one.
Thank you for your reading, the above is the content of "the usage of Linux command useradd and userdel". After the study of this article, I believe you have a deeper understanding of the usage of Linux command useradd and userdel, and the specific usage needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.