In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to create users manually in the Linux system. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The way to create a user in a Linux system is very simple, as long as you use the useradd command, but do you know how to create a new user manually?
Environment: CentOS8
Requirements: manually create a new user with the user name zhangsan,uid set to 1024 (provided that the uid is not occupied), gid is also set to 1024, the group name is the same as the user name, the home directory is / home/zhangsan, and the default shell is / bin/bash
Note: the following steps are performed with the root user, and some commands and operations are authorized only by the root user.
Step 1: modify the / etc/passwd file
Vim opens / etc/passwd file and appends one line of information
Each line of the / etc/passwd file represents a user's information, and each field separated by a colon represents a different meaning.
First field: user name second field: password, where x is just an identity, real password encryption is saved in / etc/shadow third field: UID fourth field: GID fifth field: user description information, but do not fill in the sixth field: user home directory location seventh field: default shell
The modification is complete, save and exit.
Step 2: modify the / etc/shadow file
Open the / etc/shadow file with vim, enter input mode, and the system gives a warning. It tells you that you are planning to modify a read-only file (which actually does not have read permission).
You can take a look. The shadow file does not have any permissions.
Teach you how to manually create Linux users teach you how to manually create new Linux users
But it doesn't matter, our root users can do whatever they want. Press Enter to continue.
Append a line of information to the end of the shadow file.
The shadow file is also a line of user information, and each field has a different meaning.
First field: user name, second field: password. Users with passwords are all encrypted characters here. Here I fill in two exclamation marks to indicate that there is no password. The third field: the elapsed time, in days, from 1970-01-01 to the last password change. The fourth field: how long the password can be changed. 0 means it can be changed at any time. The fifth field: the period of validity of the password the sixth field: how many days before the password expires to remind the user, 7 is a week's advance reminder. Seventh field: within how many days after the password expires, you can still log in, but you must change the password to log in. The eighth field: the maximum useful life of the password. The ninth field: the system reserved field has been modified, using wq! Save exit, otherwise it will give a warning and cannot be saved. Step 3: modify the / etc/group file
Add the following information at the end
The group file has four fields on one line
The first field is the group name, and the second field is the group password, where the x is similar to the password field of / etc/passwd. The third field is GID. The fourth field is the user in the group. If the group is the primary group of a user, then the user will not be displayed in this field, so I am blank here. Step 4: create a new user home directory mdkir / home/zhangsan step 5: copy the environment variable configuration file under the / etc/skel directory to the home directory to teach you how to manually create Linux users teach you how to manually create new Linux users
These files contain the user's environment variable configuration information, and the new user using the useradd command will also copy these files to the user's home directory.
Teach you how to create a new Linux user manually step 6: modify the permissions and ownership of the home directory
Up to now, the user zhangsan's home directory and all the files in it belong to the root user
Assign the ownership of these files to zhangsan and modify the file permissions
# modify the owner and group of user zhangsan's home directory / home/zhangsan to the permission of zhangsanchown-R zhangsan:zhangsan / home/zhangsan# to modify the file. Only the owner is allowed to read and write, and other users and groups do not have any permissions chmod 700 / home/zhangsan
The modified results are as follows
Step 7: create the mailbox file # create the mailbox file touch / var/spool/mail/zhangsan# also need to modify the mailbox owner chown zhangsan:zhangsan / var/spool/mail/zhangsan step 8: confirm that the user created successfully thank you for reading! This is the end of the article on "how to create users manually in the Linux system". 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 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.
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.