M20 – 1- 第三周(1):課堂練習與作業

課堂練習:

1、創建用戶gentoo,附加組為bin和root,默認shell為/bin/csh,注釋信息為"Gentoo Distribution"

[root@localhost ~]# useradd -G bin,root -s /bin/csh -c "Gentoo Distribution" gentoo
[root@localhost ~]# id gentoo
uid=1004(gentoo) gid=1004(gentoo) groups=1004(gentoo),0(root),1(bin)

2、創建下面的用戶、組和組成員關系

名字為admins 的組

用戶natasha,使用admins 作為附屬組

用戶harry,也使用admins 作為附屬組

用戶sarah,不可交互登錄系統,且不是admins 的成員,natasha,harry,sarah密碼都是centos

[root@localhost ~]# id gentoo
uid=1004(gentoo) gid=1004(gentoo) groups=1004(gentoo),0(root),1(bin)
[root@localhost ~]# 
[root@localhost ~]# groupadd admins
[root@localhost ~]# useradd -G admins natasha
[root@localhost ~]# useradd -G admins harry
[root@localhost ~]# useradd -s /bin/nologin sarah 
[root@localhost ~]# echo "centos" |passwd --stdin natasha
Changing password for user natasha.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo "centos" |passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# echo "centos" |passwd --stdin sarah
Changing password for user sarah.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# groupmems -g admins -l
natasha  harry

3.1、當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?

[root@localhost ~]# useradd xiaoming
[root@localhost ~]# mkdir -m 776 /testdir
[root@localhost ~]# touch /testdir/xiaoming.txt
[root@localhost ~]# chown xiaoming.xiaoming /testdir/xiaoming.txt
[root@localhost ~]# su - xiaoming
[xiaoming@localhost ~]$ mkdir /testdir/xiaoming
mkdir: cannot create directory ‘/testdir/xiaoming’: Permission denied
[xiaoming@localhost ~]$ ls -l /testdir/xiaoming.txt 
ls: cannot access /testdir/xiaoming.txt: Permission denied
[xiaoming@localhost ~]$ rm -rf /testdir/xiaoming.txt 
rm: cannot remove ‘/testdir/xiaoming.txt’: Permission denied
[xiaoming@localhost ~]$ echo "how are you" > /testdir/xiaoming.txt
-bash: /testdir/xiaoming.txt: Permission denied

因此用戶xiaoming對/testdir目錄均無任何權限。

3.2、當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作

[root@centos6 ~]# ls -dl /testdir
drwxrwx-wx 12 root root 4096 Aug  5 19:57 /testdir
[root@centos6 ~]# su - xiaoqiang
[xiaoqiang@centos6 ~]$ ls -l /testdir
ls: cannot open directory /testdir: Permission denied
[xiaoqiang@centos6 ~]$ echo "how are you" > /testdir/test.txt
[xiaoqiang@centos6 ~]$ rm -rf /testdir/test.txt
[xiaoqiang@centos6 ~]$ cd /testdir/
[xiaoqiang@centos6 testdir]$ ls
因此用戶xiaoqiang對目錄有寫和進入目錄的權限

3.3、當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?

[root@centos6 ~]# ls -ld /testdir
drwxrwxr-x 12 root root 4096 Aug  5 20:22 /testdir
[root@centos6 ~]# ls -l /testdir/file1 
-rwxrwxr-- 1 root root 0 Aug  5 20:22 /testdir/file1
[root@centos6 ~]# useradd wangcai
[root@centos6 ~]# su - wangcai
[wangcai@centos6 ~]$ 
[wangcai@centos6 ~]$ id wangcai
uid=3011(wangcai) gid=3011(wangcai) groups=3011(wangcai)
[wangcai@centos6 ~]$ echo "abc" >> /testdir/file1
-bash: /testdir/file1: Permission denied
[wangcai@centos6 ~]$ rm /testdir/file1
rm: remove write-protected regular empty file `/testdir/file1'? y
rm: cannot remove `/testdir/file1': Permission denied
[wangcai@centos6 ~]$

3.4、復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限

[root@centos6 ~]# cp /etc/fstab /var/tmp/
[root@centos6 ~]# groupadd sysadmins
[root@centos6 ~]# chown wangcai.sysadmins /var/tmp/fstab 
[root@centos6 ~]# chmod 660 /var/tmp/fstab
[root@centos6 ~]# ls -l /var/tmp/fstab 
-rw-rw---- 1 wangcai sysadmins 921 Aug  5 20:31 /var/tmp/fstab

3.5、誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性

[root@centos6 ~]# rm -rf /home/wangcai
[root@centos6 ~]# su - wangcai
su: warning: cannot change directory to /home/wangcai: No such file or directory
-bash-4.1$ exit
logout
[root@centos6 ~]# mkdir /home/wangcai
[root@centos6 ~]# cp -r /etc/skel/.[^.]* /home/wangcai/
[root@centos6 ~]# su - wangcai
[wangcai@centos6 ~]$

作業:

1、創建testuser uid 1234,主組:bin,輔助組:root,ftp,shell:/bin/csh home:/testdir/testuser

[root@localhost ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/testuser testuser
[root@localhost ~]# id testuser
uid=1234(testuser) gid=1(bin) groups=1(bin),0(root),50(ftp)
[root@localhost ~]# getent passwd testuser
testuser:x:1234:1::/testdir/testuser:/bin/csh

2、修改testuser uid:4321,主組:root,輔助組:nobody,loginname:test,home:/home/test 家數據遷移

[root@localhost ~]# usermod -u 4321 -g root -G nobody -l test -m -d /home/test testuser

3、批量創建帳號:user1…user10,uid:3000-3009,shell:/bin/csh,home:/testdir/username,passwd:usernamepass(注意家目錄相關配置,使用戶正常登錄)

[root@centos6 ~]# cat user.txt
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/user10:/bim/csh
[root@centos6 ~]# cat passwd.txt 
user1:usernamepass
user2:usernamepass
user3:usernamepass
user4:usernamepass
user5:usernamepass
user6:usernamepass
user7:usernamepass
user8:usernamepass
user9:usernamepass
user10:usernamepass
[root@centos6 ~]# newusers user.txt 
[root@centos6 ~]# getent passwd user{1..10}
user1:x:3000:3000::/testdir/user1:/bin/csh
user2:x:3001:3001::/testdir/user2:/bin/csh
user3:x:3002:3002::/testdir/user3:/bin/csh
user4:x:3003:3003::/testdir/user4:/bin/csh
user5:x:3004:3004::/testdir/user5:/bin/csh
user6:x:3005:3005::/testdir/user6:/bin/csh
user7:x:3006:3006::/testdir/user7:/bin/csh
user8:x:3007:3007::/testdir/user8:/bin/csh
user9:x:3008:3008::/testdir/user9:/bin/csh
user10:x:3009:3009::/testdir/user10:/bin/csh
[root@centos6 ~]# getent shadow user{1..10}
user1:$6$El26Odcy7S4$b5VjVn2XhTsDygdoFN7fCfAuiCGcgf02VXJGYm10qnj./94d909pSU24Jdsi3WMxNNAVn6XsnvZ5QFq1h91K00:17018:0:99999:7:::
user2:$6$Y4PXMYWRdI/j.c$Pgvk/nJ8ncZ7HLmE99A0MJET/d.1jt/auHh.tMJ3YjFJeRloWU3.JOj8UbgFxYwCotCkn7lP/dHbGTHToqYIC.:17018:0:99999:7:::
user3:$6$j1/1Q8YOCZzfCxX/$NdH3CGdInvBnkEGt8LBhLLkLkeiQUpRMA64O8i0.T0fqEa2Wy5G7CsWDhbivo00RE6E1MzHI8A0.J3WX3P0rQ1:17018:0:99999:7:::
user4:$6$YuINr/86B$X4snXO.H2Cg4zLQgEVzIrJEhq.AzoKZOh3O5xgJEGcMgPw6pmlOCjhd.tMwjbMi7w9qPGxHI6j/3uENnv48YU/:17018:0:99999:7:::
user5:$6$/S228pttn$ixljO8TNEI1fWKO1h/j3G2WyXSr3/sb//B7qpUnBFQavSn0sKbYd92TsGL7VBU.4hnlivAARhvbSDzeUQHcwB0:17018:0:99999:7:::
user6:$6$U1oCWrUS2B/z$gZtLmxjxZBSM0i0HYTF3LnolktyT5lBTcr0oN.KSP7G2MU8MkXvig1MRi1QLVOtyaxmZ8O7kwvghz4IAfNF35.:17018:0:99999:7:::
user7:$6$2HjNN/zyh6HIl$bL6omBq0QOpDa91JUORXQYFZQKA8I0enoT6zO1yhCP9hedK4tiwT/qM7tVSpE4rjvbuoFKQ413.gCEwyQWwbY1:17018:0:99999:7:::
user8:$6$gMp80/mS3KZoXt$rqY7KLDTBr7XZC4bPiTIojaG4LvlcY9iwXY59XLoz8a5X/CBmgNPq/6aO9RrNTL.7Vb.veOopprJ9EfM3kNZv0:17018:0:99999:7:::
user9:$6$TZFCR/3J$l9Cl5wrJg/NOsNvXcdT1lYXgGOdYGhyXpB5/UjW3C6WaaN1GzAO0knEYS/2hpWoCSQvRwBHFLY4xSixL1qL9I1:17018:0:99999:7:::
user10:$6$ag9YmxePEy$yJ18/ePBDJATJm1km.tpAnHyMDLbLs4VqRoSDrQpoL80nfNQWWfPQqlaheEn5pdlp1E175eJD888yjHLcBUMb/:17018:0:99999:7:::
[root@centos6 ~]# cp -r /etc/skel/.[^.]* /testdir/user1
[root@centos6 ~]# su - user1
[user1@centos6 ~]$ 
...
其他用戶也運行該命令,cp -r /etc/skel/.[^.]* /testdir/user#,即可切換到該用戶下,均屬于正常登陸。

原創文章,作者:Aleen,如若轉載,請注明出處:http://www.www58058.com/29112

(0)
AleenAleen
上一篇 2016-08-08 16:16
下一篇 2016-08-08 16:16

相關推薦

  • sed使用小結

    sed使用小結 Stream EDitor  行編輯器       sed是一種流編輯器,它一次處理一行內容。處理時,把當前處理的行存儲在臨時緩沖區中,稱為“模式空間”( pattern space),接著用sed命令處理緩沖區中的內容,處理完成后,…

    Linux干貨 2016-08-12
  • 磁盤文件系統基礎(一)

    磁盤的主要硬件單元有:     1、磁頭:通過電磁感應的方式對磁盤數據進行讀寫。     2、磁道:在磁盤自傳過程中磁頭劃過的圓形軌跡,這些軌跡是肉眼看不見的特色磁化區域。     3、扇區:磁盤上的每個磁道被等分為若干個圓弧,這些圓弧被稱…

    Linux干貨 2016-10-27
  • 馬哥Linux第二周學習筆記

    文件管理,用戶管理,權限管理

    Linux干貨 2017-12-23
  • 馬哥教育網絡班22期第2周課程作業

    一、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。     1、cp 文件復制 [選項]源文件 目標文件         -r 遞歸復制    …

    Linux干貨 2016-08-31
  • DNS服務器搭建示例

    DNS服務器搭建示例 負責解析magedu.com域名,能夠對一些主機名進行正向解析和逆向解析 配置主配置文件 [root@slave1 etc]# vim /etc/named.conf options { listen-on port 53 { 192.168.91.132; }; // listen-on-v6 port 53 { ::1; }; di…

    2017-09-16
  • Linux GRUB legacy

    Linux GRUB Linux GRUB Linux GRUB 單用戶模式(密碼破解) 救援模式 實例 GRUB菜單 GRUB命令行接口 GRUB簡介 GRUB 菜單組成 GRUB配置文件 GRUB安裝及修復 GRUB單用戶及救援模式 GRUB簡介 了解grub之前,需要理解linux的啟動流程,如果之前有對linux啟動流程不了解的可以看:http://…

    Linux干貨 2016-04-25
欧美性久久久久