User and Group command in Linux

Source: Internet
Author: User

This article combs some of the common commands for Linux users and user groups.

Related configuration files:
    • /etc/group Store all user group information in the current system
    • /etc/gshadow Store passwords for all user groups in the current system
    • /ETC/PASSWD store information for all users in the current system
    • /etc/shadow Store password information for all users in the current system
Description of the content format of the configuration file:

Note: When you use Cat/etc/group to view, you will find that the group finally does not display the user list. So how to view a list of user lists for a user group, with code below.

Add, modify, delete user groups
      1. Groupadd group_name//Adding user groups
      2. Groupmod-n new_name old_name//Modify the name of the user group
      3. Groupmod-g 668 group_name//Modify Group number
      4. Groupdel group_name//Delete User and delete user group first
User's additions, modifications, deletions
    1. Useradd-g group_name user_name//User group to add users or (gpasswd-a username groupname) (user groups are created with the same user name when the user is created without a specified user group)
    2. useradd-d/home/xxx user_name//Personal Folders
    3. Usermod-c Info user_name//Add user notes information
    4. Usermod-l new_user old_name//New user occupied old user (separation)
    5. usermod-d/home/xxx user_name//Modifying a user's file path
    6. Usermod-g group_name user_name//Mobile Users
    7. Userdel user_name//Delete User (no Personal folders deleted)
    8. Userdel-r user_name//users and files are deleted together
passwd command
    1. Passwd-l user_name//Lock the user (the offending user) or precede the second field (password) in the/etc/shadow file that belongs to the user. To restore the user, remove the *.
    2. Passwd-u user_name//Unlocking user
    3. Passwd-d user_name//Clear the user's password
    4. passwd user_name//Modify or set user password
Primary Group & Satellite Group

A user can belong to multiple user groups at the same time (there must be one primary group and multiple satellite groups)

    1. Gpasswd-a user_name affiliated_group//user to add a satellite group
    2. NEWGRP affiliated_group//Temporary Switch to satellite group (password required to enter the password)
    3. gpasswd-d user_name affiliated_group//Remove a user from a satellite group
    4. Useradd-g main_group-g GROUP1,GROUP2,GROUP3//
    5. GPASSWD group_name//Modify Group password
    6. Gpasswd-d a group or remove the user from the groups, edit/etc/group find the GROUP1 line, delete a
View commands
    1. whoami//, who am I? Show currently logged on user
    2. ID username//Displays the specified user information, including number, user name, primary group number and name, satellite group list
    3. Groups user_name//View User Group
    4. id-gn//view current logged in user, group, or direct groups
    5. Id-a mark//displays detailed information, such as: uid=500 (Mark) gid=500 (teacher) group =500 (teacher)
    6. View all team members of a group grep ' groupName '/etc/group//view group ID awk-f ":" ' {print $ ' TT ' $4} '/etc/passwd | grep ' groupId '//replace groupId with ID
Set access permissions for user files
    1. chmod command, function: The chmod command is very important to change the access rights of a file or directory. Users use it to control access to files or directories.
    2. CHGRP command, Function: Change the group to which the file or directory belongs. Chgrp-r GroupName FileName
    3. Chown command, Function: changes a file or directory's owner and owner group. This command is also very common. For example, the root user copies a file of his own to the user Xu, in order for the user Xu to access the file, the root user should be the owner of the file to Xu, otherwise, the user Xu cannot access the file.
Other commands
    1. CHFN username//Set User profile, enter user data in turn
    2. Finger username//Show User Details
    3. touch/etc/nologin//temporarily prohibit all ordinary users of the login, build an empty file on it.
    4. Su username//Switch User, no parameter (username) to switch to root
    5. User is logged in, unable to delete user, Pkill-u username (rough method) then delete (not recommended)

Links to conceptual articles about users and user groups

User and Group command 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.