Linux Users and user groups

Source: Internet
Author: User

Linux users and user groups

Linux has the concept of users and user groups. Users are divided into three categories: (1) system administrator users, root,uid=0 (2) virtual users, such as Bin,daemon, uid=1-499 (3) ordinary user,uid>=500  user and user group is a many-to-many relationship. A user can belong to more than one user group, or a user group can contain multiple users. A user can belong to more than one user group, but only one of its primary user groups.   See users can use the ID command and the finger command to view users and user groups. ID usage: ID [username], view username user's user name and user group information, omit username to view the current user's user and user group information. Finger usage: finger [username], view the information of the username user and, if not username, view the user information for the current logon host.   (switch user) SU commands the user to switch users. Usage One: Su username, which means to switch user identities, but does not switch the user's operating environment. Usage two: Su-username, which means switching user identity while switching user's running environment. Switching from a normal user to a root user or another normal user needs to enter a password for the target user and does not require a user password if switching from the root user to a normal user.   Third, create a user only the root user can create a new user. So you want to switch to the root user before you create the user. The root user can use the passwd command to set a password for other ordinary users, and the normal user can only set their own password. Method One: Useradd user1   #创建用户passwd user1   #为用户设置密码这样创建的用户的其他属性都使用系统的默认值. The UID is the uid+1 of the previous user, the home directory is/home/user1, there is no user note, the Primary user group is a new user group with the same name as the newly created user, there is no subordinate user group, and the default shell is/bin/bash.   Method Two: When creating a user to customize the user's various properties, such as user notes, the default shell, the main user group, the subordinate user group, home directory, UID and so on. Useradd-c usercomment-u uid-d/user/homedir-g maingroup-g othergroup1, othergroup2-s Defaultshell usernamepasswd use rname . The command to modify user properties for user properties is usermod. Usage such asUnder: Usermod-c newcomment-d newhomedir-g newmaingroup-g newOtherGroup1, newothergroup2-s newdefaultshell username This command can be repaired User Comments (-c) for user username, user home directory (-D), Primary user group (-g), dependent user group (-g), default shell (-s) usermod command's-u and-l option can modify the user's user name and UID as follows: Usermod-u Newuid-l Newusername Username It is important to note that when a user is logged in, the user's username and UID cannot be modified with the above command.   Alternatively, you can use the-o option to temporarily lock a user without logging on to the system, and you can unlock the user with the-u option.   Delete user Delete user's command is Userdel. Usage One: Userdel username This command can delete the user, but the user's home directory is still in, if you confirm that the user directory does not have the desired file, so that you want to continue to delete the user's home directory, you can use RM-RF manually to delete. Usage two: The USERDEL-R username plus the-r option Userdel command deletes the user's home directory while deleting the user. However, it is easier to mistakenly delete the user's files, it is generally not recommended to do so.   Create user groups only root users can create user groups. Usage one: The GID of the user group created by Groupadd NewGroup is the GID plus 1 for the previous user group. Usage II: groupadd-g GID newgroup This command allows you to specify the GID of the user group while creating the user group.   VII. The command to modify the properties of a user group is groupmod. Here's how: Groupmod-g newgid-n newgroupname groupname This command modifies the user group's GID to Newgid and modifies the user group name to Newgroupname.   Delete User group method is: Groupdel groupname if a user has this user group as its primary user group, the user group cannot be deleted.   Nine, add users to user groups, delete users by adding user groups to users to add users to the user group. Here's how: usermod-a-G groupname username The above command to add username users to the GroupName user group.   If you want to UsernaThe main user group of the Me user is set to GroupName, which can be used as follows: Usermod-g groupname username  If you want to remove a user from a user group, you can do so in the following way: gpasswd-d username groupname  

Linux Users and user groups

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.