1. 程式人生 > 其它 >使用者管理與檔案許可權

使用者管理與檔案許可權

練習文件

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