Linux User and Group management

Source: Internet
Author: User
Tags stdin

Linux User and Group management What are users and groups

User, simply put, the user is an identity that the system administrator logs on and manages the computer.

Group, we can think of a collection of users, the group of users have the same identity, the same permissions.

User and Group classification

Centos6

user category (CENTOS6) Default ID Group Classification Default Group ID
Administrator 0 Administrative Groups 0
System users 1-499 System Group 1-499
Common use 500 or more Normal Group 500 or more

Centos7

user category (CENTOS7) Default ID Group Classification Default Group ID
Administrator 0 Administrative Groups 0
System users 1-999 System Group 1-999
Common use 1000 or more Normal Group 1000 or more

Supplemental: The default ID can be changed manually by

User and Group Management

Add Delete User

Useradd Adding users
Format:
useradd [Options] LOGIN

Options Description
-D Specify account Home Directory
-S Specifying the shell type
-G Specify the primary group (the specified group needs to exist beforehand)
-G Specify additional groups (the specified group needs to exist beforehand)
-M Do not create home directory
-M Create a home directory
-R Create SYSTEM Account---System account is used for the application
-U Specify UID
-C Account Description
-N Do not create private groups as primary groups, with the Users group as their primary group
-O Do not check UID uniqueness

...............

Userdel Deleting a user
Userdel-r LOGIN to delete users and their home directories
..................

Groupadd Adding groups
>
Options Description
-G Specify GID
-R Create a System group

Groupdel Deleting a group

练习:    1.  添加用户user1        [ [email protected] ~ ]#useradd user1    2.  添加用户用户user2,并指定家目录为/home/dir2        [ [email protected] ~ ]#useradd user2 -d /home/dir2    3. 添加组group1,group2,group3,指定group1的组id为1010    [ [email protected] ~ ]#groupadd -g 1010 group1    [ [email protected] ~ ]#groupadd group2    [ [email protected] ~ ]#groupadd group3    4.  添加用户user3,指定其主组为`group1`,附加组为`group2、group3`,UID为`1234`,无需创建家目录,默认shell类型为/sbin/nologin            [ [email protected] .mozilla ]#useradd -u 1234 -g group1 -G group2,group3 -M -s /sbin/nologin

Useradd-d
useradd-d [Options]

Common Configuration Files

/ETC/PASSWD: User account-related files, including user name: Password snippet: uid:gid: Description: Home directory: Default shell type
/etc/shadow
用户名:password(加密的口令):上次修改密码的时间:更改密码的最少间隔:<br/>密码最长有效期:警告时间:非活动时长(宽限期):账户有效期
/etc/group Group name: Password: GID: Additional group added
/etc/gshadow Group name: password: Group administrator: Add-on group added to

Relationship of users and groups

Primary Group
Additional groups

Other commands

Usermod modifying user account attribute information

  usermod -U USERNAME 解锁用户密码    usermod -Ga GROUPNAME  增加附加组  usermod -L USERNAME  锁定账户  usermod -dm  HOME   更改家目录   

ID Display ID Information
ID [oprion] NAME
-U display UID
-G display GID
-G Show additional group GID
-N Display Name

**su   切换用户的命令,switch user **
  su   不带 “-”  不完整切换

Su-Full switch
Su-Switch to root by default
The Su-C command executes when the user switches

passwd user Command related
passwd [Optiongs] USERNAME

Options Description
-D Delete User Password
-L Lock user
-U Unlock Account
-E Force user to change password at next logon
-N Mindays User minimum validity period
-X Maxdays Maximum trial period
-W Warndays Non-active period
--stdin Specify a password from standard input
Echo CentOS passwd--stdin Test6 >/dev/null
**newusers file1 **批量创建账号

Linux User and Group management

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.