Teach you how to add a user by using commands or manually modifying files in Linux

Source: Internet
Author: User
Tags md5 encryption

teach you how to add a user in Linux using commands or manually modifying files



Let's start with an example: Add a happy user, a basic group of happy (5200), and an additional group of Luzhi.

One, with the method of command to achieve:

groupadd-g 5200 Happy

Useradd-u 5200-g happy-g Luzhi Happy

passwd Happy

Su-happy

This will create a successful user.

Here's a demonstration:

    1. Verify that there are happy users in the system and that there is no happy user from the output.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3F/ED/wKioL1PM0aGhFx4bAAWNnwDis3U802.jpg "style=" float: none; "title=" 36020140721162224475.jpg "alt=" Wkiol1pm0aghfx4baawnnwdis3u802.jpg "/>

2. We first set up a GID group of 5,200 happy

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3F/ED/wKiom1PM0IfRpxNIAAAdHjjExa8201.jpg "style=" float: none; "title=" 36020140721162551005.jpg "alt=" Wkiom1pm0ifrpxniaaadhjjexa8201.jpg "/>

3. See if the group is successful, and from the output it is clear that it has been successfully established.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3F/ED/wKioL1PM0aLyfuqeAAArnWnKTeA024.jpg "style=" float: none; "title=" 36020140721162635506.jpg "alt=" Wkiol1pm0alyfuqeaaarnwnktea024.jpg "/>

4. Then start adding a happy user, the base group is happy (5200), and the additional group is Luzhi.

After execution to see whether the user information is added successfully, from the output is established success.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3F/ED/wKiom1PM0IfySvn0AABrRN-QXrw438.jpg "style=" float: none; "title=" 36020140721162905668.jpg "alt=" Wkiom1pm0ifysvn0aabrrn-qxrw438.jpg "/>

5, finally we also want to see if additional groups are added successfully, using the command: tail-3/etc/group

Then we see the first line of the output, followed by the happy group behind the Luzhi group, so the additional group was added successfully.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3F/ED/wKioL1PM0aLieY0zAABAOlvrHDw839.jpg "style=" float: none; "title=" 36020140721163248697.jpg "alt=" Wkiol1pm0aliey0zaabaolvrhdw839.jpg "/>

6. We can also use ID happy to view user happy information.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3F/EF/wKioL1PM18mBo6UXAABSDXIF6jk829.jpg "style=" float: none; "title=" 36020140721164603325.jpg "alt=" Wkiol1pm18mbo6uxaabsdxif6jk829.jpg "/>

7. We have achieved more than half of the success, but the Linux system does not allow users without passwords to log in, so we also set the user password

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3F/EE/wKiom1PM1q_BTRg0AACxq1Fj1NE626.jpg "style=" float: none; "title=" 36020140721165638483.jpg "alt=" Wkiom1pm1q_btrg0aacxq1fj1ne626.jpg "/>

8. All of us have been created successfully here.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3F/EF/wKioL1PM18qS37K3AADRd_SAffU351.jpg "style=" float: none; "title=" 36020140721165741720.jpg "alt=" Wkiol1pm18qs37k3aadrd_saffu351.jpg "/>



2. Believe that the novice here, may not know the above commands and the meaning of the document, then I will be the above the above command to explain:

Instruction of the command: (list only common options, more options Please use the man command query)

Groupadd grpname: Create user Group command

-G GID: Indicates the number of user groups created for GID

Useradd username; Creating user commands

-U UID: Indicates the number of users who created the UID

-G GID: Indicates which base group to belong to

-G GID: Indicates which additional group to belong to

passwd Username: Modify User password


Su-|-l username: Indicates normal user login through terminal

Explanation of documents:/etc/passwd,/etc/group,/etc/shadow

/ETC/PASSWD: Is the system to store user information files

The file format is: User name: Password: Uid:gid: Additional Comments: Home directory: Default Shell

Such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/ED/wKiom1PM0IfySvn0AABrRN-QXrw438.jpg "title=" 36020140721162905668.jpg "style=" Float:none; "alt=" wkiom1pm0ifysvn0aabrrn-qxrw438.jpg "/>

Happy:x:5200:5200::/home/happy:/bin/bash:

Indicates that the user's user name is happy: Here the password is denoted by x, because the password is in the other/etc/shadow file, this first regardless: then followed by a comment, here is not added, so it is blank: The user's home directory is/home/happy: The default shell is/ Bin/bash


/etc/group: Is the system to store user group information files

File is saved in: User group name: Password: GID: Additional Group

Such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/ED/wKioL1PM0aLieY0zAABAOlvrHDw839.jpg "title=" 36020140721163248697.jpg "style=" Float:none; "alt=" wkiol1pm0aliey0zaabaolvrhdw839.jpg "/>


/etc/shadow: Is the system to store user password files

The file is saved in the following format: Login: Password After encryption: Last time Password was modified: Minimum Age: Maximum Age: Expiration warning Time: Inactive time: Expiry time: Retention time

Such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/F4/wKiom1PM4ICyAW5rAAB7H1rak3A447.jpg "title=" 36020140721174104149.jpg "alt=" Wkiom1pm4icyaw5raab7h1rak3a447.jpg "/>






Second, manually modify the file add User: Add a happy1 user, the basic group is happy1 (5201), the additional group is happy.

1), Prepared documents

/etc/passwd,/etc/group,/etc/shadow

2), the command to use

Nano File: Document Editor

OpenSSL passwd: Generate MD5 Password

-1-salt: Add 8-bit impurities after MD5 encryption password


Chown-r username.grpname file,...: Recursive modification of the directory and its contents of the owner and owner group


3), Operation step Demonstration: Add a happy1 user, basic Group is happy1 (5201), additional group is happy.

1, first add the gid=5201 named Happy1 to the/etc/group file, and the additional group is the Happy user group

#nano/etc/group

At the end of the file, add a line format: happy1:x:5201:

and add happy1 at the end of the user group happy (indicates adding additional groups)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/F9/wKioL1PM7sTxz-ygAAAnlM7_jIA323.jpg "title=" 36020140721182109246.jpg "style=" Float:none; "alt=" wkiol1pm7stxz-ygaaanlm7_jia323.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/3F/F8/wKiom1PM7amjvOiqAAGCo9BT8Yg541.jpg "title=" 36020140721182037885.jpg "style=" Float:none; "alt=" wkiom1pm7amjvoiqaagco9bt8yg541.jpg "/>



2. Add happy1 user to/etc/passwd file

#nano/etc/passwd

At the end of the file, add a line in the format: Happy1:x:5201:5201:happy1:/home/happy1:/bin/bash

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/F8/wKiom1PM7aqAEW5BAABAq1p8U0I795.jpg "title=" 36020140721182159268.jpg "style=" Float:none; "alt=" wkiom1pm7aqaew5baabaq1p8u0i795.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/F9/wKioL1PM7siQs1axAAIpR6H0DjU949.jpg "title=" 36020140721182438372.jpg "style=" Float:none; "alt=" wkiol1pm7siqs1axaaipr6h0dju949.jpg "/>


3. Add the Happy1 user's password to the/etc/shadow file

first we want to generate MD5 password cipher string: OpenSSL passwd-1-salt "12345678"

#nano/etc/shadow

Then add the format to the last line of the/etc/shadow file: happy1:!! : 16272:0:99999:7::: (!! means to keep the password, then use the encryption string instead)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/3F/F8/wKiom1PM7a7jv1rGAAB_phZJTy4142.jpg "title=" 36020140721182717062.jpg "style=" Float:none; "alt=" wkiom1pm7a7jv1rgaab_phzjty4142.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/F9/wKioL1PM7siQ1CdsAAAtLwmSTmw793.jpg "title=" 36020140721182753167.jpg "style=" Float:none; "alt=" wkiol1pm7siq1cdsaaatlwmstmw793.jpg "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/3F/F8/wKiom1PM7a_hkgzUAAHaEcjTfDs862.jpg "title=" 36020140721183002586.jpg "style=" Float:none; "alt=" wkiom1pm7a_hkgzuaahaecjtfds862.jpg "/>

4. Add home directory files for the user, and copy the/etc/skel files to the home directory/home/happy1,/etc/skel is the shell environment variables, is the login shell must have

#cp-R/etc/skel/home/happy1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/3F/F9/wKioL1PM7srg5-JLAAEtWyGbigc092.jpg "title=" 36020140721183214728.jpg "style=" Float:none; "alt=" wkiol1pm7srg5-jlaaetwygbigc092.jpg "/>

5. Finally, we want to modify the owner and owner group of the home directory

#chown-R happy1.happy1/home/happy1

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3F/F8/wKiom1PM7bHgOxPOAAFQQcOWF0c266.jpg "title=" 36020140721183354734.jpg "style=" Float:none; "alt=" wkiom1pm7bhgoxpoaafqqcowf0c266.jpg "/>

6. Check if you can log in

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3F/F9/wKioL1PM7s3y93pwAAE2XfTh_JA740.jpg "style=" float: none; "title=" 36020140721183801707.jpg "alt=" Wkiol1pm7s3y93pwaae2xfth_ja740.jpg "/>



Third, finally we summarize the user management, group management, rights management commonly used commands

User management: Useradd userdel usermod passwd chsh chfn figer ID chage

Group Management: Groupadd Groupdel groupmod gpasswd

Rights Management: Chown chgrp chmod

Interested to check the use of these commands, I am not listed here.

If you read this article feel that there is a problem, welcome to come, also welcome everyone to discuss together, improve together!










This article is from the "lost the year of the Sao" blog, please be sure to keep this source http://8855546.blog.51cto.com/8845546/1441060

Teach you how to add a user by using commands or manually modifying files in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.