"Go" under Ubuntu Users and user groups

Source: Internet
Author: User

User and user groups in Ubuntu under the original link http://blog.sina.com.cn/s/blog_4e4ee8ed0100tr4j.html

Create group: $sudo addgroup CCache

Create User: $sudo useradd ccache-g ccache-m

Innovate WFZ user and create home directory, specify user group as CCache $sudo useradd wfz-g ccache-m

Add an existing user to the specified group $sudo adduser $USER CCache

$sudo adduser dbh ccache $sudo adduser Paul CCache $sudo adduser WFZ CCache

Display User ID and group information: ~$ ID uid=1001 (DBH) gid=1001 (DBH) groups=115 (admin), 1001 (DBH) $ cat/etc/group CCACHE:X:1002:DBH,PAUL,WFZ

1. Management of users and user groups:

The multi-user concept of Linux means that multiple users can use the system at the same time.

(1) User account file--passwd

passwd is a text file (each line identifies 1 users) and defines the system's user account, which is located in the "/etc" directory. The file contains a list of system accounts that contain useful information for each account, such as User ID, group ID, home directory, Shell, etc. (separated by ":"). Only the user account is defined, not the password (denoted by "X", if there is no sun:: It means no password). The real password in the shadow file, the ordinary user can not read, encrypted ciphertext can not read to improve the security of the user account.

For example:

[Email protected] root]# HEAD/ETC/PASSWD

Root:x:0:0:root:/root:/bin/bash indicates that there are 7 fields: Login: Password: User id: Group ID: Account Note information: User home directory: User shell name at logon (Superuser has permission to modify)

(2) User password file--shadow

Each row defines a user information, in which the fields in the row are separated for further security, and the password file holds the password that the user has encrypted: *, special symbols

[Email protected] root]# Head/etc/shadow

Login Name: encrypted password (denoted by * or other special characters): Number of days that the password was last changed from 1970.1.1: number of days after password change: Number of days that must be changed after a password change: The number of days to warn the user before the password expires: The number of days after the password has been blocked from the account: the number of hours that the account was sealed from 1970.1.1: Reserved.

(3) User group account file--group

User groups: A logical way to organize a collection of user accounts, where users are allowed to share files within their group, and each file in the system has a user and an attached user group. Use the Ls-l command to view the properties and groups for each file.

[Email protected] root]# Head/etc/group

Root:x:0:root,tom,mary (group name: Group Encryption Password: GID: Group member list (with, separated by each group user name))

(4) User group password file--gshadow

Used to define user group password, user group administrator information. This file can only be read by Superuser Root

Record information per line:

[Email protected] root]# Head/etc/gshadow

User group: User group Encryption Password: Group Administrator account (Admin has the right to delete account): Group member List

2. Commands for user and user group account maintenance:

(1) Add user account: Useradd user name

The USERADD–G group name User name specifies the private group name that the user uses, and by default is a private group with the same name as the user account.

useradd–d [-G group][-b base][-s shell][-f inactive][-e expire] is used to display and set the default value used by the Useradd command.

Example: #useradd Sun//Create user account

#tail-L/etc/passwd//query information for user accounts added in passwd

#tail –l/etc/shadow

#ls/home//View the main directory of the account you have created

(2) Modify user account properties: usermod [-lu][-c][-d][-e][-f][-g][-g][-l][-s][-u][user Account]

(3) Delete user account: Userdel [-r][user Account]//If you do not add parameters, only delete the user account, do not delete the file, or both are deleted.

Userdel [-r][user account]//-r used to delete all files from the login directory and directory of the account

Example: #grep sun/etc/passwd//query user account whether Sun exists

#userdel Sun/delete user account Sun

#grep SUN/ETC/PASSWD//re-query the user account whether Sun exists

#ll –d/home//Querying the presence of the user's Sun home directory

#userdel –r Sun//delete users, delete their working home directory

(4) Add user group account number: Groupadd [-r][Group account]

"Note" The account ID is unique, the value cannot be negative, the default minimum value must not be less than 500, and each additional, the group account ID is incremented by 1. Where the-r parameter is used to set up the system account. 0~499 is prepared for the system account.

Example: #groupadd Magicsun//Set up a group account Magicsun

#grep Magicsun/etc/group//Querying the group file for Magicsun set account creation

#groupadd –r Syswang//Set up System group account Syswang

#grep Syswang/etc/group//query group file Syswang System group account is established

(5) Modify group account number: Groupmod [-G][-n][Group name]

Where-o indicates repeated use of the group ID

(6) Delete group account: Groupdel [group name]

Note You must delete a user in the group before you can delete the group

(7) Password maintenance: passwd [-s][-l][-u][-d][user name] Superuser can set a password for each new user, the normal user can only use the passwd command without parameters to modify their own password. Where the parameter-s is used to query the status of the specified user account,-l user Lock account password,-u unlock account password,-d delete the password of the specified account.

(8) Group User maintenance: Add an account to a group, or delete an account from a group, and set an account as a group administrator.

Add user to group: Gpasswd–a user account name group account name

Remove a user from a group: Gpasswd–d user account name group account name

Set user as group administrator: Gpasswd–a Group Administrator user List User group

(9) Status commands for users and groups:

ID [options] [user name] is used to display the list of groups that the user currently Uid,gid and which group they belong to

The [options] parameters are:

-G: Displays the ID of the group to which the user belongs

-G: Displays the ID of the additional group to which the user belongs

-N: Displays the name of the group or additional group to which the user belongs

-R: Show actual ID

-U: Show user ID

WHOAMI is used to display the name of the person who is the login (=id-un)

su [-FLMP] [-][-c][-s][user Account]//used to convert the current user to another user identity, temporarily change their login identity, with the identity of other people to log on to the system. The premise is that you must know the other person's password. Where parameter-C indicates that the original identity was restored after executing the specified instruction. -F for CSH and Tsch, so that the shell does not have to read the boot file. -Changes the working directory while changing the identity, as well as the home,shell,user,logname, and also changes the PATH environment variable. -m,-p change the identity without changing the environment variables. -s Specifies the shell to execute. If you do not specify a user account to change, then the default is root Superuser.

Groups [user name] is used to display the group to which the specified user belongs, and displays the group to which the current user belongs if no user is specified

"Go" under Ubuntu 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.