linux系统运维基础3

1、显示/etc目录下,以非字母开头,后面跟了一个字母以及其它任意长度任意字符的文件或目录

[root@k8s02-master01 ~]# mkdir -p /etc/8A{:

[root@k8s02-master01 ~]# touch /etc/6a~

[root@k8s02-master01 ~]# touch /etc/445.tar

[root@k8s02-master01 ~]# ls -a  /etc/[^[:alpha:]][[:alpha:]]* -a

/etc/6a~

/etc/8A{::

.  ..

[root@k8s02-master01 ~]# ls /etc/[^[:alpha:]]* -dl

-rw-r--r-- 1 root root 0 Mar 28 20:23 /etc/445.tar

-rw-r--r-- 1 root root 0 Mar 28 20:23 /etc/6a~

drwxr-xr-x 2 root root 6 Mar 28 20:23 /etc/8A{:


2、复制/etc目录下所有以p开头,以非数字结尾的文件或目录到/tmp/mytest11目录中

[root@k8s02-master01 ~]# cp -rv /etc/p*[^[:digit:]] /tmp/mytest1

‘/etc/pam.d’ -> ‘/tmp/mytest1/pam.d’

‘/etc/pam.d/config-util’ -> ‘/tmp/mytest1/pam.d/config-util’

‘/etc/pam.d/other’ -> ‘/tmp/mytest1/pam.d/other’

‘/etc/pam.d/chfn’ -> ‘/tmp/mytest1/pam.d/chfn’

‘/etc/pam.d/chsh’ -> ‘/tmp/mytest1/pam.d/chsh’

‘/etc/pam.d/login’ -> ‘/tmp/mytest1/pam.d/login’

‘/etc/pam.d/remote’ -> ‘/tmp/mytest1/pam.d/remote’

‘/etc/pam.d/runuser’ -> ‘/tmp/mytest1/pam.d/runuser’

‘/etc/pam.d/runuser-l’ -> ‘/tmp/mytest1/pam.d/runuser-l’


3、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中

[root@k8s02-master01 ~]# cat /etc/issue

\S

Kernel \r on an \m

[root@k8s02-master01 ~]# cat /etc/issue|tr 'a-z' 'A-Z' > /tmp/issue.out

[root@k8s02-master01 ~]# cat /tmp/issue.out

\S

KERNEL \R ON AN \M


4、请总结描述用户和组管理类命令的使用方法并完成以下练习:

用户:

用户创建:useradd

用户属性修改:usermod

删除用户:userdel

查看用户相关的ID信息:id

切换用户或以其他用户身份执行命令:su

设置密码:passwd

修改用户密码策略:chage

组:

创建组:groupadd

修改组:groupmod

删除组:groupdel

更改组密码:gpasswd

更改和查看组成员:groupmems

1)创建组distro,其GID为2019;

[root@k8s02-master01 ~]# groupadd -g 2019 distro

2)创建用户mandriva,其ID号为1005;基本组为distro;

[root@k8s02-master01 ~]# useradd -u 1005 -g 2019 mandriva

3)创建用户mageia,其ID号为1100,家目录为/home/linux;

[root@k8s02-master01 ~]# useradd -u 1100 -d /home/linux mageia

4)给用户mageia添加密码,密码为mageedu,并设置用户密码7天后过期

[root@k8s02-master01 ~]# echo "mageedu"|passwd --stdin mageia

[root@k8s02-master01 ~]# passwd -x 7 mageia

[root@k8s02-master01 ~]# chage -l mageia

root@k8s02-master01 ~]# getent shadow mageia

mageia:$6$YhrmHSPu$5q2/ntwz3Ft6TLnWEDaaT7OnONH0u97v.9W4JLiQjwoiygJ19N7nnCxBh.9DyLFvpB9iEoIxiRqt8vVaJGqON0:18714:0:7:7:::

5)删除mandriva,但保留其家目录;

[root@k8s02-master01 ~]# userdel mandriva

[root@k8s02-master01 ~]# ls /home/

linux  mandriva  www

[root@k8s02-master01 ~]# id mandriva

id: mandriva: no such user

6)创建用户slackware,其ID号为2002,基本组为distro,附加组peguin;

[root@k8s02-master01 ~]# groupadd peguin

[root@k8s02-master01 ~]# useradd -u 2002 -g 2019 -G peguin slackware

[root@k8s02-master01 ~]# id slackware

uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

7)修改slackware的默认shell为/bin/tcsh;

[root@k8s02-master01 ~]# usermod -s /bin/tcsh slackware

[root@k8s02-master01 ~]# getent passwd slackware

slackware:x:2002:2019::/home/slackware:/bin/tcsh

8)为用户slackware新增附加组admins,并设置不可登陆

[root@k8s02-master01 ~]# groupadd admins

[root@k8s02-master01 ~]# getent group admins || groupadd admins;usermod -aG admins -s /sbin/nologin slackware

[root@k8s02-master01 ~]# id slackware

uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)


5、创建用户user1、user2、user3,在/data目录下创建目录test

1)目录/data/test属主、属组为user1

[root@k8s02-master01 ~]# echo user{1..3}|xargs -n1 useradd

[root@k8s02-master01 ~]# mkdir -p /data/test

[root@k8s02-master01 ~]# chown -R user1:user1 /data/test

[root@k8s02-master01 ~]# ll /data

total 0

drwx--x--x 14 root  root  182 Feb 23 09:04 docker

drwxr-xr-x  2 user1 user1  6 Mar 28 21:06 test

2)在目录属主、属组不变的情况下,user2对文件有读写权限

[root@k8s02-master01 ~]# setfacl -m u:user2:rw- /data/test

[root@k8s02-master01 ~]# getfacl /data/test

getfacl: Removing leading '/' from absolute path names

# file: data/test

# owner: user1

# group: user1

user::rwx

user:user2:rw-

group::r-x

mask::rwx

other::r-x

3)user1在/data/test目录下创建文件a1.sh,a2.sh,a3.sh,a4.sh,设置所有用户都不可删除1.sh,2.sh文件、除了user1及root之外,所有用户都不可删除a3.sh,a4.sh

[root@k8s02-master01 ~]# cd /data/test/

[root@k8s02-master01 test]# su user1

[user1@k8s02-master01 test]$ touch a{1..4}.sh

[user1@k8s02-master01 test]$ ll

total 0

-rw-rw-r-- 1 user1 user1 0 Mar 28 21:10 a1.sh

-rw-rw-r-- 1 user1 user1 0 Mar 28 21:10 a2.sh

-rw-rw-r-- 1 user1 user1 0 Mar 28 21:10 a3.sh

-rw-rw-r-- 1 user1 user1 0 Mar 28 21:10 a4.sh

[user1@k8s02-master01 test]$ chattr +i a1.sh a2.sh

chattr: Operation not permitted while setting flags on a1.sh

chattr: Operation not permitted while setting flags on a2.sh

[user1@k8s02-master01 test]$ exit

exit

[root@k8s02-master01 test]# chattr +i a1.sh a2.sh

[root@k8s02-master01 test]# lsattr

----i----------- ./a1.sh

----i----------- ./a2.sh

---------------- ./a3.sh

---------------- ./a4.sh

[root@k8s02-master01 test]# cd ..

[root@k8s02-master01 data]# chmod o+t test

[root@k8s02-master01 data]# ll -d test/

drwxrwxr-t+ 2 user1 user1 58 Mar 28 21:10 test/

4)user3增加附加组user1,同时要求user1不能访问/data/test目录及其下所有文件

[root@k8s02-master01 data]# id user3

uid=2005(user3) gid=2005(user3) groups=2005(user3)

[root@k8s02-master01 data]# usermod -aG user1 user3

[root@k8s02-master01 data]# id user3

uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)

[root@k8s02-master01 data]# setfacl -m u:user1:- /data/test/

[root@k8s02-master01 data]# getfacl /data/test/

getfacl: Removing leading '/' from absolute path names

# file: data/test/

# owner: user1

# group: user1

# flags: --t

user::rwx

user:user1:---

user:user2:rw-

group::r-x

mask::rwx

other::r-x

5)清理/data/test目录及其下所有文件的ad权限

[root@k8s02-master01 data]# setfacl -b /data/test*

[root@k8s02-master01 data]# getfacl /data/test/

getfacl: Removing leading '/' from absolute path names

# file: data/test/

# owner: user1

# group: user1

# flags: --t

user::rwx

group::r-x

other::r-x

你可能感兴趣的:(linux系统运维基础3)