课堂练习:
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.178linux.com/29112