Linux系统管理初学者指南——基于CentOS7.6 第三章习题

1.Linux 中的用户管理主要涉及用户账号文件________、用户密码文件________、用户组文件___________。

	1./ect/passwd
	2./ect/shadow
	3./ect/group 、 /ect/gshadow

2.通过id命令查看 student 用户的身份信息,并将命令执行后的信息全部重定向到黑洞文件中。

	[root@localhost ~]# id student 2> /dev/null 
	uid=1011(student) gid=1011(student) groups=1011(student)

3.显示系统中用户账号的个数。

	[root@localhost home]# grep -v '^$' /etc/passwd | wc -l
	42

4.将 student 用户的家目录复制到 /tmp 目录中,并保持源文件的属性不变。

	[root@localhost home]# cp -rp /home/student /tmp/

5.创建一个名为 financial 的组。

	[root@localhost home]# groupadd financial

6.创建一个名为 test1 的用户,指定其 UID 为 1600, 将 financial 组设置为 test1 用户的基本组。

	#前提是已有financial这个用户组
	[root@localhost home]# useradd -u 1600 -g financial test1
	[root@localhost home]# id test1
	uid=1600(test1) gid=2001(financial) groups=2001(financial)

7.通过非交互方式为用户 test1 设置密码 123。

	[root@localhost home]# echo "123" | passwd --stdin test1
	Changing password for user test1.
	passwd: all authentication tokens updated successfully.

8.另外打开一个终端,以 test1 用户的身份登录系统。在 test1 的家目录中创建一个名为 test1.txt 的文件,并查看 test1.txt 文件的权限设置。

	[root@localhost ~]# su - test1 
	[test1@localhost ~]$ touch test1.txt /home/test1/
	[test1@localhost ~]$ ls -l /home/test1/test1.txt 
	-rw-r--r-- 1 test1 financial 0 03-16 22:37 /home/test1/test1.txt

9.首先对文件 test1.txt 进行权限设置,要求文件所有者具有读写权限,所属组和其他用户具有只读权限。然后,使 test1用户退出登录。

	[test1@localhost ~]$ chmod 644 /home/test1/test1.txt 
	[test1@localhost ~]$ exit
	logout

10.将 test1 用户锁定,禁止其登录。再次打开一个终端,尝试能否以 test1 用户的身份登录。

	[root@localhost ~]# passwd -l test1
	Locking password for user test1.
	passwd: Success

	# root 用户可通过 su 切换到锁定用户下,其他普通用户不可通过 su 切换到锁定用户下。
	#无论是普通用户还是超级用户 root 都无法通过 ssh 连接到锁定用户下。

11.将 test1 用户解锁,在终端中尝试能否以 test1 用户的身份登录。

	[root@localhost ~]# passwd -u test1
	Unlocking password for user test1.
	passwd: Success.
	[root@localhost ~]# su - test1
	[test1@localhost ~]$ 

12.将用户 test1 家目录中的 test1.txt 文件的所有者改为 root,所属组改为 users。

	[root@localhost ~]# chown root:users /home/test1/test1.txt 
	[root@localhost ~]# ll -l /home/test1/test1.txt 
	-rw-r--r-- 1 root users 0 03-16 22:37 /home/test1/test1.txt

13.将 test1 用户连同家目录一并删除。

	[root@localhost ~]# userdel -r test1

14.创建用户 test2,要求没有家目录,并且禁止其登录。

	[root@localhost ~]# useradd -s /sbin/nologin -M test2

15.创建用户 test3,并指定其家目录为 /test3。

	[root@localhost ~]# useradd -d /test3 test3
	[root@localhost ~]# ls -a /test3/
	.  ..  .bash_logout  .bash_profile  .bashrc  .emacs  .mozilla

16.将 test3 用户加入 root 组,使 root 组成为其附加组。

	[root@localhost ~]# usermod -a -G root test3
	[root@localhost ~]# id test3
	uid=1013(test3) gid=1013(test3) groups=1013(test3),0(root)

17.将用户 test3 的基本组修改为 users 。

	[root@localhost ~]# usermod -g users test3
	[root@localhost ~]# id test3
	uid=1013(test3) gid=100(users) groups=100(users),0(root)

18.将用户 test3 的家目录 /test3 移动到 /home 目录中,然后将其家目录改为 /home/test3 。

	[root@localhost ~]# usermod -m -d /home/test3 test3

19.当用户对目录有写权限,但对目录下的文件没有写权限时,能否修改此文件内容? 能否删除此文件?

	#不可以修改文件内容,可以删除文件。

20.Linux文件的权限位 x 对目录和文件有何不同?

	#对文件来说,具有执行文件的权限;对目录来说,该用户具有进入目录的权限

21.新建目录 /tmp/mike,并设置如下权限。

● 将此目录的所有者设置为 mike,并设置读、写和执行权限。

● 将此目录的所属组设置为 sales,并设置读和执行权限。

● 其他用户没有任何权限。

	[root@localhost ~]# mkdir /tmp/mike
	[root@localhost ~]# groupadd sales
	[root@localhost ~]# useradd mike
	[root@localhost ~]# chmod 750 /tmp/mike
	[root@localhost ~]# chown mike:sales /tmp/mike
	[root@localhost ~]# ls -ld /tmp/mike/
	drwxr-x--- 2 mike sales 4096 03-17 01:03 /tmp/mike/

22.创建 /var/test 目录,要求在此目录中任何用户都可以创建文件或目录,但只有用户自身和 root 用户可以删除用户所创建的文件或目录。

	[root@localhost ~]# mkdir /var/test
	[root@localhost ~]# chmod o+t /var/test
	[root@localhost ~]# ll -d /var/test/
	drwxr-xr-t 2 root root 4096 03-17 01:13 /var/test/

23.新建一个名为 manager 的用户组,创建两个用户账号: natasha 和 harry,并将 manager 组设为这两个用户的附加组。复制文件 /etc/fstab 到 /var/tmp 目录中,对文件 /var/tmp/fstab 进行权限设置。

	[root@localhost ~]# groupadd manager
	[root@localhost ~]# useradd natasha
	[root@localhost ~]# useradd harry
	[root@localhost ~]# usermod -a -G manager natasha
	[root@localhost ~]# usermod -a -G manager harry
	[root@localhost ~]# cp -rp /etc/fstab /var/tmp/

● 添加 ACL 条目,使 manager 组具有读取权限。

	[root@localhost ~]# setfacl -m g:manager:r-- /var/tmp/fstab 

● 添加 ACL 条目,使用户 harry 具有读写权限。

	[root@localhost ~]# setfacl -m u:harry:rw- /var/tmp/fstab 

● 添加 ACL 条目,使用户 natasha 没有任何权限。

	[root@localhost ~]# setfacl -m u:natasha:--- /var/tmp/fstab 

● 删除 manager 组的 ACL 条目。

	[root@localhost ~]# setfacl -x g:manager /var/tmp/fstab 

● 删除所有附加的 ACL 条目。

	[root@localhost ~]# setfacl -b /var/tmp/fstab 

24.假设 /var/test 目录的所属组是 users,要求对 /var/test 目录进行权限设置,使得任何用户在该目录中所创建的文件或子目录的所属组都自动使用 users 组。

	[root@localhost ~]# chmod g+s /var/test/
	[root@localhost ~]# touch /var/test/ceshi.txt
	[root@localhost ~]# ll /var/test/
	总计 0
	-rw-r--r-- 1 root users 0 03-17 01:49 ceshi.txt

25.假设普通用户 student 已经被授权,要求以该用户身份将系统的IP地址修改为 192.168.80.10/24。

26.为 /etc/passwd 文件添加只读属性。

	[root@localhost ~]# chattr +i /etc/passwd
	[root@localhost ~]# lsattr /etc/passwd
	----i-------- /etc/passwd

27.将 /var/log/messages 文件设置为只能向其中追加写人数据,但不能删除原有数据。

	[root@localhost ~]# chattr +a /var/log/messages
	[root@localhost ~]# lsattr /var/log/messages
	-----a------- /var/log/messages

28.在系统中查找所有人都有写权限的目录。

	[root@localhost ~]# find / -perm -007 -type d 
	#或者
	[root@localhost ~]# find / -perm 007 -type d 

仅供参考,如有错误,欢迎指点

  • 29
    点赞
  • 96
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值