User and Group Management

Source: Internet
Author: User

passwd file format

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/85/70/wKiom1ejRwfQRV4tAAAQ5srJbQU500.png "title=" 11.png "alt=" Wkiom1ejrwfqrv4taaaq5srjbqu500.png "/>

Separated by a colon, divided into 7 segments:

Login Name: Login name (WANG)

passwd: Password (x)

UID: User identification Number (1000)

GID: Login Default group number (1000)

GECOS: User's full name or comment

Home directory: Household Directory (/home/wang)

Shell: The user uses the shell by default (/bin/bash)

Shadow file format

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/70/wKioL1ejR66zkFnIAAATde2Yx0s505.png "title=" 12.png "alt=" Wkiol1ejr66zkfniaaatde2yx0s505.png "/>

Separated by a colon, divided into 9 segments:

Login with Name

User password: generally with sha512 encryption

From January 1, 1970 to the time the password was last changed

The password can be changed in a few days (0 means it can be changed at any time)

The password must be changed in a few days (99999 means never expire)

The system reminds the user a few days before the password expires (default is one week)

Password expires days payback will be locked

From January 1, 1970 onwards, the number of days after the account expires.

Reserved fields

User created: Useradd

Useradd[options] LOGIN

-U UID: [Uid_min, Uid_max] defined in/etc/login.defs

-O with-u option to not check UID uniqueness

-G GID: Indicates that the user belongs to the basic group, can be a group name, or GID

-C "COMMENT": User's comment information

-D Home_dir: Home directory with the specified path (not present)

-S Shell: Indicates the user's default shell program

Available lists in the/etc/shells file

-G group1[,group2,...] : To indicate additional groups for the user, the group must exist beforehand

-N Do not create private group master group, use the Users group master Group

-r: Create System user CentOS 6:id<500,centos 7:id<1000

User Property Modification

Usermod[option] Login

-U uid: New UID

-G GID: New Basic Group

-G group1[,group2,... [, GROUPN]] : The new add-on group, the original additional group will be overwritten, if the original, you want to use the-a option at the same time, indicating append;

-S shell: new default shell;

-C ' COMMENT ': new annotation information;

-D Home: The new home directory will not be created automatically, the files in the home directory will not be moved to the new home directory at the same time, to create a new home directory and move the original home data, while using the-m option

-L login_name: new name;

-l:lock Specify the user, add in the/etc/shadow password bar!

-u:unlock Specify the user, will/etc/shadow the password bar! Take it off.

-E YYYY-MM-DD: Indicates the user account expiration date;

-F INACTIVE: set inactivity period;

Delete User

Userdel[option] ... login

-r: Delete user home directory;

Getent command:

[Email protected] ~]# getent passwd = = [email protected] ~]# CAT/ETC/PASSWD

#查看指定用户或者组信息及其属性信息

[Email protected] ~]# getent passwd user1

User1:x:1001:1001::/home/user1:/bin/bash

[Email protected] ~]# getent Group user1

USER1:X:1001:

/etc/login.defs Create user Default User password profile

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/85/70/wKiom1ejRGDwRcpmAAAxptgEXvA700.png "title=" 1.png " alt= "Wkiom1ejrgdwrcpmaaaxptgexva700.png"/>

Default settings file:

Default setting: In the/etc/default/useradd file

To display or change the default settings:

Useradd-d

Useradd–d-s Shell Specifies modify = = Vim/etc/default/useradd

[[email protected] ~]# useradd-d view

group=100

Home=/home

Inactive=-1

Expire=

Shell=/bin/bash

Skel=/etc/skel

Create_mail_spool=yes

# # #SKEL =/etc/skel is the default new user home directory configuration file, when there is no home directory, you can copy the file (it is all hidden files)

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/70/wKiom1ejRHvQJp72AAALqu-FWc4309.png "title=" 2.png " alt= "Wkiom1ejrhvqjp72aaalqu-fwc4309.png"/>

[Email protected] ~]# cp-r/etc/skel/. /home/user1


Home directories and mailboxes are not generated automatically when creating a System account (/var/spool/mail)


When the home directory does not exist, login and switch to display as:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/85/70/wKioL1ejRJCjZEnyAAAm-JlTiH4471.png "title=" 3.png " alt= "Wkiol1ejrjcjzenyaaam-jltih4471.png"/>

To create a user step in bulk:

1. Create user

VIM user.txt---formatted as/etc/passwd file

NewUsers User.txt

2. Set the password

VIM passwd.txt---Format: User name: Password

Cat Passwd.txt | chpasswd

3. Copy Home Catalogue

Create a new script jaimulu.sh---content is cp-r/etc/skel/. [^.] */home/user1

or Cp-r/etc/skel/. /home/user1#/home/user1 to User1 's home directory

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/70/wKiom1ejRKOiuk1CAAASyXtQKX8702.png "title=" 4.png " alt= "Wkiom1ejrkoiuk1caaasyxtqkx8702.png"/>

4, mail function (optional), (e-mail/var/spool/mail)

Create a new script youjan.sh---content for mail-s Hi user1 </etc/fstab #添加多个用户即可

#查看用户所在组:

[email protected] ~]# groups User1

User1:user2 Root bin Nobody #user2为主, followed by additional groups

[[email protected] ~]# ID user1

uid=2016 (user1) gid=1002 (user2) groups=1002 (User2), 0 (Root), 1 (bin), (nobody)

Empty additional groups:

[Email protected] ~]# usermod-g "" User1

[[email protected] ~]# ID user1

uid=2016 (user1) gid=1002 (user2) groups=1002 (user2)

[email protected] ~]# groups User1

User1:user2

To view user-related ID, name information:

[Email protected] ~]# Id-u user1

1001

[Email protected] ~]# Id-un user1

User1

[Email protected] ~]# Id-g user1

1001

[Email protected] ~]# ID-GN user1

User2

[Email protected] ~]# id-g user1#G (groups)

1002 0 1 99

[Email protected] ~]# ID-GN user1

User2 Root Bin Nobody

SU command:

Su[options ...] [-] [user [args ...]]

How to switch users:

Suusername: Non-logon switch, that is, does not read the target user's profile, does not change the current working directory

Su-username: Login switch, will read the target user's profile, switch to home directory, completely switch

Root Su to other users no password required, non-root user need password to switch

[Email protected] ~]$ su-root-c pwd #以root的身份去执行命令

Password:

/root




This article is from a "little progress every Day" blog, make sure to keep this source http://563349612.blog.51cto.com/11096134/1834511

User and Group Management

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.