Add, modify, delete of Linux users

Source: Internet
Author: User
Tags stdin

Useradd [-parameter] Account

-U: After a set of numbers, assign this set of numbers as the UID of this account.

-G: After the group name, the group as the initial user group account, the user group GID will be placed in the fourth account/etc/passwd

-G: followed by the group name, this group as the account of the secondary user group, this parameter will modify the relevant data within the/etc/group.

-m: Force, do not create user home folder.

-m: Force to create the user home folder.

-C: This is the description of the fifth column of/etc/passwd.

-D: Specifies the home folder directory instead of the default directory for the system. (Must be an absolute path)

-r: Create a System account, the UID of this account will be limited.

-S: followed by a shell, which defaults to/bin/bash if not specified.

-E: followed by a date, formatted as ' YYYY-MM-DD ', shadow the eighth field, specify the expiration date of the account.

-F: followed by a shadow seventh field, specifying whether the password is invalid, 0 is immediately invalid, 1 is never invalidated (the password will only expire and is forced to reset when logging on)

Create User fds:

[Email protected]~]# useradd fds[[email protected]~]# ll-d/home/fds #默认的主文件夹路径drwx------. 2 FDS FDS 4096 Sep one 09:52/home/fds[[email protected]~]# grep fds/etc/passwd/etc/shadow/etc/group/etc/passwd:fds:x:101 1:1011::/home/fds:/bin/bash/etc/shadow:fds:!! : 17420:0:99999:7:::/etc/group:fds:x:1011:

#设置uid为700, the initial user group is hive

[Email protected]~]# useradd-u 700-g hive fds1[[email protected]~]# ll-d/home/fds1drwx------. 2 fds1 hive 4096 Sep one-09:54/home/fds1[[email protected]~]# grep fds1/etc/passwd/etc/shadow/etc/group/etc/passwd:fds1: x:700:491::/home/fds1:/bin/bash/etc/shadow:fds1:!! : 17420:0:99999:7:::

#创建一个系统用户

[[Email protected]~]# useradd-r fds2[[email protected]~]# ll-d/home/fds2ls:cannot access/home/fds2:no such fileor D Irectory[[email protected]~]# grep fds2/etc/passwd/etc/shadow/etc/group/etc/passwd:fds2:x:494:490::/home/fds2:/ bin/bash/etc/shadow:fds2:!! : 17420::::::/etc/group:fds2:x:490:

The UID of the general user is greater than 500, the user created the UID of the system account is generally greater than 100, so with the-R parameter, the system will automatically assign the account with the account name of the user group Uid/gid is less than 500, Because the system account is mainly used to run the system requires the services required to set the permissions, so the system account by default does not automatically create the home folder.

Use the-d parameter to view the default value for Useradd

[[Email protected]~]# useradd-dgroup=100 #默认的用户组HOME =/home #默认的主文件夹所在目录INACTIVE =-1 #密码的失效日期, 7th column shadow within expire= #账号的失效日期, in Shadow's 8th column Shell=/bin/bash #默认的shellSKEL =/etc/skel #用户文件夹的内容数据参考目录CREATE_MAIL_SPOOL =yes # Whether to proactively help users create mailboxes (mailbox)

Data on default settings for accounts can be viewed/etc/default/useradd/etc/shadow

About Uid/gid, the settings of the password can be viewed/etc/login.defs/etc/passwd/etc/group

passwd [-parameter] Account

--stdin: The data can be piped, as input to the password, in the common language shell.

-L: Lock means to invalidate the password.

-U: The meaning of unlocking is the anti-operation of-L.

-S: Lists the relevant parameters of the password

-N: Number of days followed, indicating how long the password cannot be changed

-x: Number of days followed, indicating how long the password must be changed

-W: Number of days before the password expires

-I: date followed, expiration date of password

Note: passwd after the account is not added is to modify the current login password.

Set the password for the FDS account:

[Email protected]~]# passwd fdschanging password for user FDS. New Password:bad Password:it is the too Shortbad password:is too simpleretype new Password:passwd:all authentication to Kens updatedsuccessfully.

The add-stdin parameter uses the pipe to set the password (here are two short bars, not a horizontal bar):

[[Email protected]~]# echo ' fds1 ' |passwd--stdin fds1changing password for user fds1.passwd:all authentication tokens UPD Atedsuccessfully.

Password locking/Unlock for specified account:

[Email protected]~]# passwd-s fds1fds1 PS 2017-09-11 0 99999 7-1 (passwordset, SHA512 Crypt.)  [[Email protected]~]# passwd-l fds1locking password for user fds1.passwd:success[[email protected]~]# passwd-s fds1fds1 LK 2017-09-11 0 99999 7-1 (passwordlocked.) [Email protected]~]# grep fds1/etc/shadowfds1:!! $6$dhuswtsf$ds9wlnzlcwhifp3aj8lpqart8s6cbgmtgzizykwin4lzpd1lcjspw2cmeowhvnznldkftr0ztqfucuc8qhkyp. : 17420:0:99999:7:::[[email protected]~]# passwd-u fds1unlocking password for user fds1.passwd:success[[email protected ]~]# grep fds1/etc/shadowfds1:$6$dhuswtsf$ ds9wlnzlcwhifp3aj8lpqart8s6cbgmtgzizykwin4lzpd1lcjspw2cmeowhvnznldkftr0ztqfucuc8qhkyp.:17420:0:99999:7:::[[ Email protected]~]#

Passwd-s simply lists simple information, to see more detailed information you can use the change command,

chage [-parameter] Account

-L: Lists detailed password parameters for the account

-D: Date followed, last modified polygon time, formatted as YYYY-MM-DD

-E: After date, account expiration date, format ibid.

-I: date followed, password expiration date,

-m: Number of days to save, minimum password

-M: After the number of days, how long the password needs to be modified

-W: Number of days followed, warning date before password expires

Use Chage to view the original account information:

[[email protected]~]# chage -l fds1last password change                                      : Sep  11,2017password expires                                          : neverPassword inactive                                         :  neverAccount expires                                           :neverMinimum number of days between passwordchange           : 0Maximum number of days  Between passwordchange          : 99999number  of days of warning before passwordexpires        : 7

Change the last modified time of password:

[[email protected]~]#  chage -d  ' 2017-09-12 '  fds1[[email protected]~]#  chage -l fds1Last password change                                      : sep 12, 2017password expires                                           : neverPassword inactive                                         : neveraccount expires                                           : neverminimum number of days between passwordchange           : 0maximum number of days between passwordchange           : 99999Number of days of  Warning before passwordexpires       : 7

usermod [-parameter] Account

-C: followed by account description

-D: The home folder followed by the account, absolute path

-E: Date followed, formatted as YYYY-MM-DD

-F: followed by days

-G: followed by the initial user group

-G: Followed by secondary user group

-A: Use with-g to increase support for secondary users instead of setting

-L: followed by new account name

-S: The actual file followed by the shell

-U: followed by uid number

-L: Temporarily freezes the user and locks the user's password so that it cannot log on.

-U: unfreeze the user, unlock the user password, is frozen account recovery use

Add notes to FDS1 account:

[Email protected]~]# usermod-c "Just a test account" Fds1[[email protected]~]# grep fds1/etc/passwdfds1:x:700:491:just A testaccount:/home/fds1:/bin/bash[[email protected]~]# usermod-e ' 2019-12-31 ' fds1[[email protected]~]# grep fds1/etc /shadowfds1:$6$dhuswtsf$ds9wlnzlcwhifp3aj8lpqart8s6cbgmtgzizykwin4lzpd1lcjspw2cmeowhvnznldkftr0ztqfucuc8qhkyp. : 17421:0:99999:7::18261:


Modify FDS1 's account number to Fds1_new:

[[email protected] ~]# usermod-l fds1_new fds1[[email protected] ~]# grep FDS1/ETC/SHADOWFDS1_NEW:$6$DHUSWTSF$DS9WLNZLC whifp3aj8lpqart8s6cbgmtgzizykwin4lzpd1lcjspw2cmeowhvnznldkftr0ztqfucuc8qhkyp.:17421:0:99999:7::18261:

Userdel [-parameter] Account

-R: Delete together with home folder

Delete the Fds2 and his home folder:

[[Email protected]~]# userdel-r fds2userdel:fds2 Mail spool (/VAR/SPOOL/MAIL/FDS2) not found[[email protected]~]# Userde L-r fds2userdel:user ' fds2 ' does not exist


This article is from the "Dark Shun" blog, please make sure to keep this source http://mjal01.blog.51cto.com/12140495/1964269

Add, modify, delete of Linux users

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.