要求
将用户 bill
、karen
加入 music
组,让其在共享文件夹 /usr/local/share/Music/
下自由创建共享文件(夹)
准备
- VM:
CentOS 6.4
- ssh:
XShell
- VM IP:
192.168.211.131
操作
-
创建用户
bill
、karen
# add user bill, karen (use root to login) [root@centos6 ~]# useradd bill [root@centos6 ~]# passwd bill Changing password for user bill. New password: BAD PASSWORD: it is WAY too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully. [root@centos6 ~]# useradd karen [root@centos6 ~]# passwd karen Changing password for user karen. New password: BAD PASSWORD: it is WAY too short BAD PASSWORD: is too simple Retype new password: passwd: all authentication tokens updated successfully.
-
创建组
music
,并将用户bill
、karen
加入music
组[root@centos6 ~]# groupadd music [root@centos6 ~]# usermod -G music bill [root@centos6 ~]# usermod -G music karen [root@centos6 ~]#
-
用
bill
登录,创建共享文件夹[C:\~]$ ssh bill@192.168.211.131 22 Connecting to 192.168.211.131:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. [bill@centos6 ~]$ mkdir /usr/local/share/Music mkdir: cannot create directory `/usr/local/share/Music': Permission denied [bill@centos6 ~]$ su - Password: [root@centos6 ~]# mkdir /usr/local/share/Music [root@centos6 ~]#
-
更改共享文件夹所在组、文件权限
[root@centos6 ~]# ll -d /usr/local/share/Music drwxr-xr-x 2 root root 4096 Oct 27 14:03 /usr/local/share/Music [root@centos6 ~]# chown :music /usr/local/share/Music/ [root@centos6 ~]# ll -d /usr/local/share/Music drwxr-xr-x 2 root music 4096 Oct 27 14:03 /usr/local/share/Music [root@centos6 ~]# chmod 775 /usr/local/share/Music/ [root@centos6 ~]# ll -d /usr/local/share/Music drwxrwxr-x 2 root music 4096 Oct 27 14:03 /usr/local/share/Music [root@centos6 ~]#
-
变更为超管组权限
[root@centos6 ~]# chmod g+s /usr/local/share/Music/ [root@centos6 ~]# ll -d /usr/local/share/Music drwxrwsr-x 2 root music 4096 Oct 27 14:03 /usr/local/share/Music [root@centos6 ~]# exit logout [bill@centos6 ~]$
-
设置
umask
[bill@centos6 ~]$ umask 0002
-
测试:
bill
创建共享测试文件、共享测试文件夹[bill@centos6 ~]$ > /usr/local/share/Music/bill_file [bill@centos6 ~]$ mkdir /usr/local/share/Music/bill_dir [bill@centos6 ~]$ ll /usr/local/share/Music/ total 4 drwxrwsr-x 2 bill music 4096 Oct 27 14:07 bill_dir -rw-rw-r-- 1 bill music 0 Oct 27 14:06 bill_file [bill@centos6 ~]$
-
测试:
karen
创建共享测试文件、共享测试文件夹[C:\~]$ ssh karen@192.168.211.131 22 Connecting to 192.168.211.131:22... Connection established. To escape to local shell, press 'Ctrl+Alt+]'. [karen@centos6 ~]$ id uid=502(karen) gid=502(karen) groups=502(karen),503(music) [karen@centos6 ~]$ > /usr/local/share/Music/karen_file [karen@centos6 ~]$ mkdir /usr/local/share/Music/karen_dir [karen@centos6 ~]$ ll /usr/local/share/Music/ total 8 drwxrwsr-x 2 bill music 4096 Oct 27 14:07 bill_dir -rw-rw-r-- 1 bill music 0 Oct 27 14:06 bill_file drwxrwsr-x 2 karen music 4096 Oct 27 14:17 karen_dir -rw-rw-r-- 1 karen music 0 Oct 27 14:17 karen_file [karen@centos6 ~]$
注意事项
若需反复练习上述设置,需依次执行:
# 1. Logout bill, karen
# 2. Use root to login
[C:\~]$ ssh root@192.168.211.131 22
Connecting to 192.168.211.131:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Sun Oct 27 13:38:54 2019 from 192.168.211.1
[root@centos6 ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@centos6 ~]#
# 3. Remove shared directory 'Music' recursively
[root@centos6 ~]# rm -rf /usr/local/share/Music/
# 4. Delete user bill
[root@centos6 ~]# userdel bill
# 5. Remove bill's home directory
[root@centos6 ~]# rm -rf /home/bill
# 6. Remove bill's mailbox directory
[root@centos6 ~]# rm -rf /var/spool/mail/bill
# 7. Delete user karen
[root@centos6 ~]# userdel karen
# 8. Remove karen's home directory
[root@centos6 ~]# rm -rf /home/karen/
# 9. Remove karen's mailbox directory
[root@centos6 ~]# rm -rf /var/spool/mail/karen
# 10. Delete group 'music'
[root@centos6 ~]# groupdel music
[root@centos6 ~]#
出处
The Linux Command Line v13.07, July 6, 2013, Second Internet Edition.(Chapter 9, P127: Exercising Our Privileges)