"Favorites" Linux Add/Remove users and user groups

Source: Internet
Author: User

1, Build Users:
AddUser PHPQ//New PHPQ User
passwd PHPQ//Set password for PHPQ user

2. Build Working Group
Groupadd test//New test Workgroup

3, new users at the same time increase the Working group
USERADD-G test PHPQ//new PHPQ user and added to test workgroup

Note::-G belongs to the group-D home Directory-S used by the shell


4. Increase the Working Group for existing users
USERMOD-G groupname username

Or: Gpasswd-a user Group

5. Temporary shutdown: The second field (password) in the/etc/shadow file that belongs to the user is preceded by a *. To restore the user, remove the *.

Or, use the following command to close the user account:
passwd peter–l

Re-release:
passwd Peter–u

6. Permanently delete user account
Userdel Peter

Groupdel Peter

Usermod–g Peter Peter (Force delete all files and subdirectories in the user's home directory and home directory)

7. Remove users from the group
Edit/etc/group Find the GROUP1 line, delete A
or with a command.
gpasswd-d A GROUP

8. Display user Information
ID User
cat/etc/passwd

For more detailed explanations of users and user groups, please refer to
Detailed explanation of Linux users and user groups
This paper mainly describes the concepts of user and user group management in Linux system, the enumeration of user and user groups (group) commands, as well as the multi-tasking of single users and multi-user multitasking.



# 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 for the login Sam/usr/sam (/usr is the parent directory where the default user home directory resides).

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

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

Adding a user account is the addition of a record to a new user in the/etc/passwd file, as well as updating other system files such as/etc/shadow,/etc/group. The contents of these files will be described in detail later.

Linux provides an integrated system management tool, userconf, which can be used to manage user accounts uniformly.

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

Userdel option User Name

The common option is-r, which is to remove the user's home directory.

For example:

# Userdel Sam

This command deletes the records of the user Sam in the system files (primarily/etc/passwd,/etc/shadow,/etc/group, etc.) while deleting the user's home directory.

Modify user account is based on the actual situation to change the user's relevant attributes, such as user number, home directory, user group, login shell and so on.

Modify the information for an existing user using the Usermod command, which is in the following format:

Usermod option User Name

Common options include-C,-D,-M,-G,-G,-s,-u,-O, and so on, with the same meaning as the options in the Useradd command, which allows you to specify a new resource value for the user. In addition, some systems can use the following options:

-L New User name

This option specifies a new account that will change the original user name to the new one.

For example:

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

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

An important part of user management is the management of user passwords. The user account has just been created without a password, but is locked by the system, cannot be used, it must be given a password before it can be used, even if a blank password is specified.

The shell command that specifies and modifies the user's password is passwd. A superuser can specify a password for himself and another user, and a normal user can only use it to modify his or her password. The format of the command is:

passwd option User Name

Options available for use:

-L locks the password, which disables the account.

-u password to unlock.

-D make the account no password.

-F forces the user to modify the password the next time they log on.

If the default user name, the password for the current user is modified.

For example, assuming the current user is Sam, the following command modifies the user's own password:

$ passwd

Old password:******

New password:*******

Re-enter New password:*******

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

# passwd Sam

New password:*******

Re-enter New password:*******

Ordinary users to modify their own password, the passwd command will first ask the original password, verify and then ask the user to enter two times the new password, if the password two times the same, the password is assigned to the user, and the superuser to specify a password for the user, you do not need to know the original password.

For system security, the user should choose a more complex password, for example, preferably with a 8-bit long password, the password contains uppercase, lowercase letters and numbers, and should be different from name, birthday, and so on.

When you specify an empty password for a user, the following forms of command are executed:

# passwd-d Sam

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

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

# passwd-l Sam


Q: Has a user forgotten the password? Can I initialize its password? How does it work? or simply erase it, and how to do it?

A: Enter the system with the root user and then passwd the username so that the password can be re-established without entering the user's old password. If you want to delete the user, use the Userdel user name command.

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.