Linux 共享文件夹设置

要求

将用户 billkaren 加入 music 组,让其在共享文件夹 /usr/local/share/Music/ 下自由创建共享文件(夹)

准备

  • VM: CentOS 6.4
  • ssh: XShell
  • VM IP: 192.168.211.131

操作

  1. 创建用户 billkaren

    # 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.
    
  2. 创建组 music,并将用户 billkaren 加入 music

    [root@centos6 ~]# groupadd music
    [root@centos6 ~]# usermod -G music bill
    [root@centos6 ~]# usermod -G music karen
    [root@centos6 ~]#
    
  3. 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 ~]#
    
  4. 更改共享文件夹所在组、文件权限

    [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 ~]#
    
  5. 变更为超管组权限

    [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 ~]$
    
  6. 设置 umask

    [bill@centos6 ~]$ umask 0002
    
  7. 测试: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 ~]$ 
    
  8. 测试: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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值