Linux command Details useradd command use method _linux Shell

Source: Internet
Author: User
Tags parent directory

Linux system is a multi-user multi-task operating system, any one to use system resources, users must first to the system administrator to apply for an account, and then the identity of the account into the system. The user's account can help the system administrator to track the users who use the system and control their access to the system resources, on the other hand, can help users organize files and provide security protection for users. Each user account has a unique username and password. Once the user types the correct username and password at logon, they are able to access the system and their home directory.

To achieve the user account management, the work to be done mainly has the following several aspects:
User account Add, delete and modify.
Management of user passwords.
Management of user groups.

First, the Linux system user account management

User account management is mainly related to the user account to add, modify and delete.
Adding a user account is to create a new account in the system, and then assign a user number, user group, home directory, and login shell to the new account. The account you just added is locked and cannot be used.

1, add a new user account using the Useradd command, the syntax is as follows:

Copy Code code as follows:

Useradd option User Name

The meanings of each option are as follows:

Code:
-C Comment Specifies a section of an annotation description.
The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the main catalog.
The-G user group specifies the user group to which the user belongs.
-G user group, where the user group specifies the additional group to which the user belongs.
-S Shell file specifies the user's login shell.
The-u user number specifies the user's user number, and if the-o option is available, the other user's identification number can be reused.

User name Specifies the login name of the new account.

Example 1:

Copy Code code as follows:

# useradd–d/usr/sam-m Sam

This command creates a user Sam,
Where the-D and-m options are used to generate a home directory/usr/sam (/usr as the parent directory for the default user home directory) for the login Sam.

Example 2:

Copy Code code as follows:

# useradd-s/bin/sh-g group–g adm,root Gem

This command creates a new user gem, whose login shell is/bin/sh, which belongs to the group user groups and also to the ADM and root groups, where the group groups are the primary groups.

New groups may be created here: #groupadd Group and Groupadd ADM
Adding a user account is to add a record to the new user in the/etc/passwd file, while updating other system files such as/etc/shadow,/etc/group, etc.
Linux provides an integrated system management tool, userconf, which can be used to manage user accounts uniformly.

2, delete the account

If a user's account is no longer in use, it can be removed from the system. Deleting a user account is to remove the user record from the system files such as/etc/passwd and, if necessary, delete the user's home directory. Delete an existing user account using the Userdel command, in the following format:

Copy Code code as follows:

Userdel option User Name

The commonly used option is-r, which is to delete the user's home directory together.
For example:

Copy Code code as follows:

# Userdel Sam

This command deletes the user Sam's record in the system file (mainly/etc/passwd,/etc/shadow,/etc/group, and so on) while deleting the user's home directory.

3, modify the account

Modify the user account is based on the actual situation to change the user's related properties, such as user number, home directory, user group, login shell and so on.
Modify the information of an existing user using the Usermod command, in the following format:

Copy Code code as follows:

Usermod option User Name

Common options include-C,-D,-M, G, G, S,-u, and-O, and the meanings of these options are the same as those in the Useradd command, which can specify a new resource value for the user. In addition, some systems can use the following options:

Code:
-L New User name

This option specifies a new account that will change the original username to the new username.
For example:

Copy Code code as follows:

# usermod-s/bin/ksh-d/home/z–g developer Sam

This command modifies the login shell of the user Sam to Ksh, the home directory to/home/z, and the user group to developer.

4, the User password management

One important aspect of user management is the management of user passwords. The user account was created without a password, but is locked by the system and cannot be used, and must be assigned a password before it can be used, even if a null password is specified.
The shell command that specifies and modifies a user's password is passwd. A superuser can specify a password for himself and other users, and a normal user can only use it to modify his or her password. The format of the command is:
Code:

passwd option User Name
Options you can use:

Code:
-L locks the password, that is, the account is disabled.
-u password unlock.
-D makes the account password-free.
-F forces the user to modify the password at the next logon.
If the default user name, the password for the current user is modified.

For example, if the current user is a SAM, the following command modifies the user's own password:

Copy Code code as follows:

$ passwd
Old password:******
New password:*******
Re-enter New password:*******

If you are a superuser, you can specify any user's password in the following form:

Copy Code code as follows:

# passwd Sam
New password:*******
Re-enter New password:*******

Ordinary users modify their own password, the passwd command will ask the original password, verify that the user input two times after the new password, if the password entered two times, the password will be assigned to the user, and the root user to specify the password, you do not need to know the original password.

For the sake of system security, users should choose a more complex password, for example, preferably with a 8-bit long password, which contains uppercase, lowercase letters, and numbers, and should be different from names, birthdays, and so on.

When you specify a blank password for the user, the following form of command is performed:

Copy Code code as follows:

# passwd-d Sam

This command deletes the password for the user Sam so that the system will no longer ask for the password the next time the user Sam logs on.

The passwd command can also lock a user with the-l (lock) option so that it cannot log on, for example:

Copy Code code as follows:

# passwd-l Sam New User exception:
useradd-d/usr/hadoop-u 586-m hadoop-g Hadoop

1 Creating mailbox file: Files already exist
Delete to rm-rf/var/spool/mail/user name
2 useradd:invalid numeric argument ' Hadoop '
This is because the Hadoop group does not exist please build the Hadoop group first
You can view the pass of a user through CAT/ETC/PASSWD
Cat/etc/shadow can view user names
Cat/etc/group can view groups

Create users under Linux (ii)

Second, the Linux System user Group management

Each user has a group of users that the system can centrally manage for all users in a user group. Different Linux systems provide a different set of user groups, such as users under Linux who belong to a user group with the same name, which is created at the same time as the user group.
The management of a user group involves adding, deleting, and modifying user groups. The addition, deletion, and modification of groups is actually an update to the/etc/group file.

1, add a new user group to use the Groupadd command. The format is as follows:

Copy Code code as follows:

Groupadd Option User Group

The options you can use are:
Code:
-G GID Specifies the group identification number (GID) of the new user group.
-O is commonly used concurrently with the-G option, which means that the GID for the new user group is the same as the GID of the system already has a user group.

Example 1:

Copy Code code as follows:

# Groupadd Group1

This command adds a new group group1 to the system, and the group identification number of the new group is based on the currently existing maximum group identification number plus 1.

Example 2:

Copy Code code as follows:

#groupadd-G-group2

This command adds a new group group2 to the system and specifies that the group identification number for the new group is 101.

2, if you want to delete an existing user group, use the Groupdel command, the format is as follows:

Copy Code code as follows:

Groupdel User Group

For example:

Copy Code code as follows:

#groupdel group1

This command deletes the group group1 from the system.

3, modify the properties of the user group using the groupmod command. The syntax is as follows:

Copy Code code as follows:

Groupmod Option User Group

The common options are:
Code:
-G GID Specifies a new group identification number for the user group.
With the-O and-g option, the new GID for the user group can be the same as the GID for the system already has a user group.
-N New user group to change the name of the user group to a new name

Example 1:

Copy Code code as follows:

# GROUPMOD-G 102 Group2

This command modifies the group identification number of the group group2 to 102.

Example 2:

Copy Code code as follows:

# groupmod–g 10000-n Group3 group2

This command changes the identification number of the group group2 to 10000 and the group name to Group3.

4. If a user belongs to more than one user group at the same time, the user can switch between user groups to have other user group permissions. The user can switch to another user group after logging in using the command newgrp, and the command's parameter is the destination user group. For example:

Copy Code code as follows:

$ NEWGRP Root

This command switches the current user to the root group, provided that the root group is indeed the user's primary or additional group. Similar to user account management, user group management can also be accomplished through integrated system management tools.

assigning permissions

Copy Code code as follows:


Chown-r hadoop:hadoop/usr/hadoop/

Let the average user have root privileges

1.root Login

2.adduser User Name

3.PASSWD User Name

Confirm Password

4. Modify/etc/passwd to change the ID and ID Group of the username to 0.

Related Article

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.