In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what Linux user creation commands are. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something through the detailed introduction of this article.
Linux system is a multi-user system, so user management is a very important work, in Linux system to create users can use the useradd command.
1. role
The useradd or adduser command is used to create user accounts and create a user's home directory, using permissions that are superuser.
2. format
useradd [-d home] [-s shell] [-c comment] [-m [-k template]] [-f inactive] [-e expire ] [-p passwd] [-r] name
3. main parameters
-c: Add remarks, which are stored in the remarks column of passwd.
-d: Specifies the home directory where the user logs in, replacing the system default of/home/
D: Change the default value.
-e: Specify the expiration date of the account number in MM/DD/YY format, for example 06/30/12. Default means permanent.
-f: Specifies how many days after the password expires to close the account. If 0, the account is immediately deactivated; if-1, the account is always available. The default value is-1.
-g: Specifies the group to which the user belongs. The value can be either a group name or a GID. The user group must already exist, and the default value is 100, i.e. users.
-G: Specify additional groups to which the user belongs.
-m: Automatically create user login directory.
-M: Do not automatically create user logins.
-n: Cancels the creation of a group named after the user.
R: Create a system account.
-s: Specifies the shell that the user will use after logging in. The default value is/bin/bash.
-u: Specify the user ID number. The value must be unique in the system. 0~499 is reserved for system user accounts by default, so the value must be greater than 499.
4. description
useradd can be used to create user accounts and is the same as adduser. After the account is created, use passwd to set the password for the account. The account created using the useradd command is actually stored in the/etc/passwd text file.
5. application example
Create a new user account testuser1, and set UID to 544, home directory to/usr/testuser1, belonging to users group:
code is as follows
#useradd -u 544 -d /usr/testuser1 -g users -m testuser1
add-m automatically create if home directory does not exist
6. cases
Log in to the system using an administrator account and create a password for the user tmp_3452 3sdt5:Eawhg
Add user commands:
[root@ptr228 ~]# adduser tmp_3452 Change password command: [root@ptr228 ~]# passwd tmp_3452
The system prompts you to enter your password: 3sdt5:Eawhg and then enter it again. OK added successfully.
7.useradd Add users in bulk
When useradd is used, if no parameter options are added later, for example: #sudo useradd test, the user created will be the default "three no" user: one without Home Directory, two without password, and three without System Shell.
The procedure is as follows:
(1)Create username list file username.txt (ditto)
(2)Create a user password file serc.txt in the format username:password (note the file format)
stu1:tt1 stu2:tt2 stu3:tt3 stu4:tt4 stu5:tt5 stu6:tt6
(3)Batch Added Script File aa.sh
code is as follows
##Add users and generate user directories for users under/home/. cat
Create a new useradd command. If there is no error in execution, no information will be output and no interaction with the user will occur. But users must remember those settings, otherwise added users may have unexpected results.
8. Create a new oracle user, which initially belongs to the oinstall group, and have it also belong to the dba group.
#useradd oracle -g oinstall -G dba
Create a new oracle user, which initially belongs to the oinstall group, and have it also belong to the dba group.
9. Unable to use shell with user directory to/var/servlet/service
#useradd tomcat -d /var/servlet/service -s /sbin/nologin
Unable to use shell with user directory to/var/servlet/service
Second, userdel delete user
Delete the newly created account tmp_3452
Delete user command:
code is as follows
[root@ptr228 ~]# userdel tmp_3452
Or delete it along with the user directory:
code is as follows
[root@ptr228 ~]# userdel -f tmp_3452
Note: If the user is still logged in here, it will prompt that the user is logged in and cannot be deleted. At this point, you may need to force the user to exit first.
3. Force-out logged in users
View the commands of the currently logged in user:
code is as follows
[root@ptr228 ~]# w
The following results will be entered:
code is as follows
12:10:27 up 21:13, 1 user, load average: 0.00, 0.01, 0.08 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 *..*. 11:33 0.00s 0.08s 0.00s w tmp_3254 ps1 *..*. 11:33 0.00s 0.08s 0.00s ls
Here we know that the tty of the login user is ps1 executing the forced exit command pkill:
Command prototype: pkill -kill -t [TTY]
code is as follows
[root@ptr228 ~]# pkill -kill -t ps1
Executing the name w after execution will see that the user has exited.
Repeat the Delete User command in Step 2. Delete successfully.
What are the commands for Linux to create users, and have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
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.