02-4用戶和組管理類命令的練習

(1)葫盼、創(chuàng)建組distro残腌,其GID為2019;

[root@centos8 etc]# groupadd -g2019 distro

(2)贫导、創(chuàng)建用戶mandriva, 其ID號為1005抛猫;基本組為distro;

useradd -u1005 -gdistro mandriva

(3)脱盲、創(chuàng)建用戶mageia邑滨,其ID號為1100,家目錄為/home/linux;

useradd -u1100 -d/home/linux mageia

(4)钱反、給用戶mageia添加密碼掖看,密碼為mageedu,并設置用戶密碼7天后過期

passwd mageia
passwd -x 7 mageia

(5)面哥、刪除mandriva哎壳,但保留其家目錄;

[root@centos8 etc]# userdel mandriva
[root@centos8 etc]# cd /home/mandriva/
[root@centos8 mandriva]# 

(6)尚卫、創(chuàng)建用戶slackware归榕,其ID號為2002,基本組為distro吱涉,附加組peguin刹泄;

[root@centos8 etc]# useradd -u 2002 -g distro slackware
[root@centos8 etc]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro)
[root@centos8 etc]# groupmems -a slackware -g peguin
groupmems: group 'peguin' does not exist in /etc/group
[root@centos8 etc]# groupadd peguin
[root@centos8 etc]# groupmems -a slackware -g peguin
[root@centos8 etc]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin)

(7)外里、修改slackware的默認shell為/bin/tcsh;

[root@centos8 etc]# usermod -s /bin/tcsh slackware
[root@centos8 etc]# cat /etc/passwd|grep slackware
slackware:x:2002:2019::/home/slackware:/bin/tcsh

(8)特石、為用戶slackware新增附加組admins盅蝗,并設置不可登陸。

[root@centos8 etc]# groupadd admins
[root@centos8 etc]# groupmems -a slackware -g admins
[root@centos8 etc]# id slackware
uid=2002(slackware) gid=2019(distro) groups=2019(distro),2020(peguin),2021(admins)
[root@centos8 etc]# usermod -s /sbin/nologin slackware #不可登陸

5姆蘸、創(chuàng)建用戶user1墩莫、user2、user3逞敷。在/data/下創(chuàng)建目錄test

[root@centos8 data]# ll
total 0
drwxr-xr-x. 2 root root 6 Dec  2 11:37 test

(1)狂秦、目錄/data/test屬主、屬組為user1

[root@centos8 data]# chown user1 test
[root@centos8 data]# chgrp user1 test
[root@centos8 data]# ll 
total 0
drwxr-xr-x. 2 user1 user1 6 Dec  2 11:37 test

(2)推捐、在目錄屬主裂问、屬組不變的情況下,user2對文件有讀寫權限

[root@centos8 data]# chmod o+rw test
[root@centos8 data]# ll
total 0
drwxr-xrwx. 2 user1 user1 6 Dec  2 11:37 test

(3)玖姑、user1在/data/test目錄下創(chuàng)建文件a1.sh, a2.sh, a3.sh, a4.sh愕秫,設置所有用戶都不可刪除a1.sh,a2.sh文件焰络、除了user1及root之外戴甩,所有用戶都不可刪除a3.sh, a4.sh

[root@centos8 test]# touch a{1..4}.sh #創(chuàng)建文件
[root@centos8 test]# ls
a1.sh  a2.sh  a3.sh  a4.sh
[root@centos8 test]# chattr +i a1.sh #設置特殊權限
[root@centos8 test]# chattr +i a2.sh 
#facl設置特殊權限
[root@centos8 test]# setfacl -m u:user1:rw a3.sh 
[root@centos8 test]# setfacl -m u:user1:rw a4.sh 
[root@centos8 test]# getfacl a3.sh 
# file: a3.sh
# owner: root
# group: root
user::rw-
user:user1:rw-
group::r--
mask::rw-
other::r--

(4)、user3增加附加組user1闪彼,同時要求user1不能訪問/data/test目錄及其下所有文件

[root@centos8 test]# groupmems -a user3 -g user1 #為user3增加附加組
[root@centos8 test]# id user3
uid=2005(user3) gid=2005(user3) groups=2005(user3),2003(user1)
[root@centos8 test]# setfacl -m user1:0 /data
[root@centos8 test]# su - user1
[user1@centos8 ~]$ cd /data
-bash: cd: /data: Permission denied

(5)甜孤、清理/data/test目錄及其下所有文件的acl權限

[root@centos8 test]# setfacl -b a3.sh 
[root@centos8 test]# setfacl -b a4.sh
[root@centos8 test]# chattr -i a1.sh a2.sh
[root@centos8 test]# setfacl -b /data
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市畏腕,隨后出現(xiàn)的幾起案子缴川,更是在濱河造成了極大的恐慌,老刑警劉巖描馅,帶你破解...
    沈念sama閱讀 211,884評論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件把夸,死亡現(xiàn)場離奇詭異,居然都是意外死亡铭污,警方通過查閱死者的電腦和手機恋日,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,347評論 3 385
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來嘹狞,“玉大人岂膳,你說我怎么就攤上這事“跬” “怎么了谈截?”我有些...
    開封第一講書人閱讀 157,435評論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我簸喂,道長毙死,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,509評論 1 284
  • 正文 為了忘掉前任娘赴,我火速辦了婚禮规哲,結果婚禮上,老公的妹妹穿的比我還像新娘诽表。我一直安慰自己,他們只是感情好隅肥,可當我...
    茶點故事閱讀 65,611評論 6 386
  • 文/花漫 我一把揭開白布竿奏。 她就那樣靜靜地躺著,像睡著了一般腥放。 火紅的嫁衣襯著肌膚如雪泛啸。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,837評論 1 290
  • 那天秃症,我揣著相機與錄音候址,去河邊找鬼。 笑死种柑,一個胖子當著我的面吹牛岗仑,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播聚请,決...
    沈念sama閱讀 38,987評論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼荠雕,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了驶赏?” 一聲冷哼從身側(cè)響起炸卑,我...
    開封第一講書人閱讀 37,730評論 0 267
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎煤傍,沒想到半個月后盖文,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,194評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡蚯姆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,525評論 2 327
  • 正文 我和宋清朗相戀三年五续,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片蒋失。...
    茶點故事閱讀 38,664評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡返帕,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出篙挽,到底是詐尸還是另有隱情荆萤,我是刑警寧澤,帶...
    沈念sama閱讀 34,334評論 4 330
  • 正文 年R本政府宣布,位于F島的核電站链韭,受9級特大地震影響偏竟,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜敞峭,卻給世界環(huán)境...
    茶點故事閱讀 39,944評論 3 313
  • 文/蒙蒙 一踊谋、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧旋讹,春花似錦殖蚕、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,764評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至鞭呕,卻和暖如春蛤育,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背葫松。 一陣腳步聲響...
    開封第一講書人閱讀 31,997評論 1 266
  • 我被黑心中介騙來泰國打工瓦糕, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人腋么。 一個月前我還...
    沈念sama閱讀 46,389評論 2 360
  • 正文 我出身青樓咕娄,卻偏偏與公主長得像,于是被迫代替她去往敵國和親党晋。 傳聞我的和親對象是個殘疾皇子谭胚,可洞房花燭夜當晚...
    茶點故事閱讀 43,554評論 2 349

推薦閱讀更多精彩內(nèi)容