In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to create a new Linux user manually". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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
The second field: password, where x is just an identity, and the real password encryption is stored in / etc/shadow
Third field: UID
The fourth field: GID
Fifth field: user description information, but not filled in
Sixth field: user's 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.
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.
Fifth field: the validity period of the password
The sixth field: remind the user how many days before the password expires, 7 is to remind the user a week in advance.
Seventh field: within how many days after the password expires, you can still log in, but you must change the password to log in.
Eighth field: the maximum useful life of the password
Ninth field: system reserved field
After modification, use 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
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 empty here.
Step 4: create a new user home directory
Mdkir / home/zhangsan
Step 5: copy the environment variable configuration file in the / etc/skel directory to the home directory
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.
Step 6: modify the permissions and owners 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 a mailbox file
# to create a mailbox file touch / var/spool/mail/zhangsan#, you also need to modify the owner chown zhangsan:zhangsan / var/spool/mail/zhangsan of the mailbox
Step 8: confirm that the user has created it successfully
This is the end of "how to create a new Linux user manually". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.