用户管理与文件权限

练习文档

1.创建用户gentoo,附加组为bin和root,默认shell为/bin/csh,注释信息为"Gentoo Distribution"

useradd -s /bin/csh -G bin.root -c "Gentoo Distribution " gentoo

 

2.创建下面的用户、组和组成员关系

名字为webs的组

用户nginx,使用webs作为附加组

useradd nginx -G webs

用户varnish,使用webs作为附加组

useradd varnish -G webs

 

用户mysql,不可交互登录系统,且不是webs的成员,nginx,varnish,mysql密码都是magedu

useradd  mysql    -s /bin/nologin

 

设置三个用户密码:

echo magedu | passwd --stdin nginx

echo magedu | passwd --stdin varnish

echo magedu | passwd --stdin mysql

 

1.当用户docker对/testdir目录无执行权限时,意味着无法做哪些操作?

无法进入该目录  cd

 

2.当用户mongodb对/testdir目录无读权限时,意味着无法做哪些操作?

不能查看目录下的内容 ls 也不可以

 

 

3.当用户redis对/testdir目录无写权限时,该目录下的只读文件file1是否可修改和删除?

不能在目录下创建文件和修改

 

4.当用户zabbix对/testdir目录有写和执行权限时,该目录下的只读文件file1是否可修改和删除?

只能删文件

 

5.复制/etc/fstab文件到/var/tmp下,设置文件所有者为tomcat读写权限,所属组为apps组有读写权限,其他人无权限

cp -a /etc/fstab /var/tmp

chwon tomcat:apps

chmod 660 /var/tmp/fstab

 

 

6.误删除了用户git的家目录,请重建并恢复该用户家目录及相应的权限属性

mkdir  /home/git

cp -a /etc/skl/  /home/git/

chown -R git:git /home/git

chmod 700 /home/git

 

在/testdir/dir里创建的新文件自动属于webs组,组apps的成员如:tomcat能对这些新文件有读写权限,组dbs的成员如:mysql只能对新文件有读权限,其它用户(不属于webs,apps,dbs)不能访问这个文件夹

[19:27:41 1;33mroot@xlh /data/testdir]#chmod g+s /data/testdir/dir
[19:27:53 1;33mroot@xlh /data/testdir]#ll
total 0
drwxr-sr-x. 2 root webs 20 Oct 30 19:25 dir
-rw-r--r--. 1 root root  0 Oct 30 19:27 f1.txt
[19:28:02 1;33mroot@xlh /data/testdir]#groupadd apps;groupadd dbs

 

[19:28:36 1;33mroot@xlh ~]#groupadd apps;groupadd dbs
groupadd: group 'apps' already exists
groupadd: group 'dbs' already exists
[19:28:41 1;33mroot@xlh ~]#useradd -G apps tomcat;useradd -G dbs mysql
useradd: user 'tomcat' already exists
useradd: user 'mysql' already exists

[19:29:32 1;33mroot@xlh ~]#setfacl -d -m g:apps:rw /data/testdir/dir
[19:29:43 1;33mroot@xlh ~]#setfacl -d -m g:dbs:r /data/testdir/dir
[19:30:08 1;33mroot@xlh ~]#chmod o= /data/testdir/dir
[19:30:29 1;33mroot@xlh ~]#cd /data
[19:30:36 1;33mroot@xlh /data]#ll
total 12
-rw-r--r--. 1 www  root 31 Oct 28 21:15 all.log
-rw-r--r--. 1 root root 48 Oct 28 09:36 apple.txt
drwxr-xr-x. 3 root webs 31 Oct 30 19:27 testdir
-rw-r--r--. 1 root root 58 Oct 27 20:36 test.txt
[19:30:41 1;33mroot@xlh /data]#ls -dl
drwxr-xr-x. 3 root webs 69 Oct 30 19:24 .
[19:30:45 1;33mroot@xlh /data]#cd /data/testdir/dir
[19:30:58 1;33mroot@xlh /data/testdir/dir]#touch f2.txt
[19:31:03 1;33mroot@xlh /data/testdir/dir]#ll
total 0
-rw-r--r--. 1 root root 0 Oct 30 19:25 f1.txt
-rw-rw-r--+ 1 root webs 0 Oct 30 19:31 f2.txt

 

2.误将/bin/chmod文件的执行权限删除,如何恢复

setfacl -m u:root:w /usr/bin/chmod

ll /usr/bin/chmod

chmod a+x /usr/bin/chmod

setfacl -b /usr/bin/chmod

 

posted @   家购诗  阅读(186)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示