1. Display the /etc/ directory, starting with a non-letter, followed by a letter and other files or directories of any length and any character
ls -dl /etc/^[^[:alpha:]][[:alpha:]]*
2. Copy all files or directories starting with p and ending with non-digits in the /etc/ directory to the /tmp/test1 directory
mkdir -p /tmp/test1
cp -a /etc/p*[^[:digit:]] /tmp/test1
3. Convert the content in the /etc/issue file to uppercase and save it to the /tmp/issue.out file
cat /etc/issue | tr [[:lower:]] [[:upper:]] > /tmp/issue.out
cat /tmp/issue.out
4. Please summarize and describe how to use commands for user and group management and complete the following exercises:
User name creation, modification and deletion
- useradd
- usermod
- userdel
Creating user-related files involves saving configuration files:
Related files:
/etc/default/useradd
/etc/skel/* (creating the default hidden files in the home directory)
/etc/login.def (settings related to the creation of default mailboxes and passwords)
Save the configuration file:
/etc/passwd
/etc/shadow
useradd | usermod |
---|---|
-u: UID | -u: new UID |
-g: GID indicates that the user basically belongs to the group | -g: new GID |
-G: Specify additional group | -G: new additional group, while -a retains the original additional group |
-c: user's comment information | -c: new user comment information |
-d: create a new home directory | -md: Create a new home directory and move the original home directory data |
-s: Specify the default shell program (available list in /etc/shell) | -s: new default shell |
-N: Do not create a private group as the main group | / |
-r: create system user | / |
-m: system user creates home directory | / |
-M: Non-system users do not create home directories | / |
/ | -l: new login name |
/ | -L: Lock the specified user, the effect is to increase in the etc/shadow password field! |
/ | -U: Unlock the specified user |
/ | -e YYYY-MM-DD: Specify the expiration time of the user account |
/ | -f INACTIVE: set inactive period |
userdel | effect |
---|---|
-f | Force delete user |
-r | Delete user's home directory and mailbox |
passwd | chage |
---|---|
-d delete the specified user password | / |
-l: lock the specified user | / |
-u: unlock the specified user | / |
-e: Force the user to change the password at the next login | / |
-f: mandatory operation | / |
-n mindays: minimum usage period | -m mindays: minimum usage period |
-x maxdays: the maximum use period | -M maxdays: the longest use period |
-w warndays: how many days in advance to start warning | -W warndays: How many days in advance to start warning |
-i inactivedays: inactive days | -I inactivedays: grace period after the password expires |
--Stdin: receive password from standard input | / |
/ | -d last day: modify the time of the last password change |
/ | -l: Show password policy |
For example:
/etc/passwd
gentoo:x:1002:1003:Gentoo Distribution:/home/gentoo:/bin/csh
gentoo:用户名
x:密码
1002:UID
1003:GID
Gentoo Distribution:用户的注释信息
/home/gentoo:用户家目录
/bin/csh:默认shell
/etc/shadow
test:!$6$JZaCK4kBQVirtHfY$.hN1mlk8RhJI7r/qpi3iDaRz3e2SnqSRaLWsqlz1aY4k/uk9E0H6eaH2x1Zw66j8UlpYE6K88F4h3WhpM.2Lw1:18553:7:14:6:3:18554:
test:用户名
$6$...:密码(!$6$...:用户锁定)
18553:最后一次修改密码时间,1970年计算
7:再过几天密码可以变更
14:再过几天密码必须变更
6:提前多少天开始告警
3:密码过期后多久账号会被锁定
18554:账号失效时间
chage -l test
Last password change : password must be changed
Password expires : password must be changed
Password inactive : password must be changed
Account expires : Oct 19, 2020
Minimum number of days between password change : 7
Maximum number of days between password change : 14
Number of days of warning before password expires : 6
Creation, modification and deletion of user groups
- groupadd
- groupmod
- groupdel
- gpasswd change group password
Related configuration files involved in creating user groups:
/etc/group
etc/gshadow
Exercise:
- Create a group distro with a GID of 2019
[root@centos8 data ]#groupadd -g 2019 distro
[root@centos8 data ]#getent group distro
distro:x:2019:
- Create user mandriva, whose ID number is 1005; the basic group is distro
[root@centos8 data ]#useradd -u 1005 -g distro mandriva
[root@centos8 data ]#getent passwd mandriva
mandriva:x:1005:2019::/home/mandriva:/bin/bash
[root@centos8 data ]#id mandriva
uid=1005(mandriva) gid=2019(distro) groups=2019(distro)
- Create user mageia with ID number 1100 and home directory /home/linux
[root@centos8 data ]#useradd -u 1100 -d /home/linux mageia
[root@centos8 data ]#getent passwd mageia
mageia:x:1100:1100::/home/linux:/bin/bash
- Add a password to user mageia, the password is mageedu, and set the user password to expire after 7 days
[root@centos8 data ]#echo "mageedu" | passwd --stdin > /dev/null
passwd: This option requires a user name.
[root@centos8 data ]#echo "mageedu" | passwd --stdin mageia > /dev/null
[root@centos8 data ]#passwd -x 7 mageia
Adjusting aging data for user mageia.
passwd: Success
[root@centos8 data ]#getent shadow mageia
mageia:$6$3wibG8dj1zj/wKWR$n8BwhIcU3xV1Zez8z/o7B/XFBievehJmy55FtrAvYBgZv7Dl6tQCRrRyvpI5YvzgOMFkxy.xhQ1RGFPeFiER60:18553:0:7:7:::
- Delete mandriva, but keep its home directory
[root@centos8 data ]#userdel mandriva
[root@centos8 data ]#ll /home/
total 0
drwx------. 2 1005 distro 62 Oct 18 23:14 mandriva
- Create user slackware, its ID number is 2002, the basic group is distro, and the additional group peguin
[root@centos8 data ]#groupadd peguin
[root@centos8 data ]#useradd -u 2002 -g distro -G peguin slackware
[root@centos8 data ]#id 2002
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)
- Modify the default shell of slackware to /bin/tcsh
[root@centos8 data ]#usermod -s /bin/tcsh slackware
[root@centos8 data ]#getent passwd slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh
- Add additional group admins for user slackware;
[root@centos8 data ]#groups admins
groups: ‘admins’: no such user
[root@centos8 data ]#groupadd admins
[root@centos8 data ]#usermod -aG admins slackware
[root@centos8 data ]#id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)