简介:Samba服务用于在不同平台(windows,linux)之间共享文件和打印机等。
注:本文不讨论multiuser多用户挂载的情况
1 | [root@server0 ~]# yum -y install samba samba-client |
---|
1234567891011121314 | [root@server0 ~]# firewall-cmd --add-service=samba --permanentsuccess[root@server0 ~]# firewall-cmd --reloadsuccess[root@server0 ~]# firewall-cmd --list-allpublic (default, active) interfaces: eth0 sources: services: dhcpv6-client samba ports: masquerade: no forward-ports: icmp-blocks: rich rules: |
---|
1234567891011 | [root@server0 ~]# mkdir /common[root@server0 ~]# chmod o+w /common[root@server0 ~]# semanage fcontext -a -t samba_share_t '/common(/.*)?'Full path required for exclude: net:[4026532580].Full path required for exclude: net:[4026532580].[root@server0 ~]# restorecon -RFvv /common/Full path required for exclude: net:[4026532580].Full path required for exclude: net:[4026532580].restorecon reset /common context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0[root@server0 ~]# ls -ldZ /commondrwxr-xrwx. root root system_u:object_r:samba_share_t:s0 /common |
---|
123456789 | [root@server0 ~]# vim /etc/samba/smb.confworkgroup = STAFFsecurity = user[common] path = /common browseable = yes hosts allow = 172.25.0.0/24 writable = no write list = brian |
---|
1234567891011121314 | [root@server0 ~]# useradd -s /sbin/nologin rob[root@server0 ~]# useradd -s /sbin/nologin brian[root@server0 ~]# smbpasswd -a robNew SMB password:Retype new SMB password:Added user rob.[root@server0 ~]# smbpasswd -a brianNew SMB password:Retype new SMB password:Added user brian.[root@server0 ~]# id robuid=1001(rob) gid=1001(rob) groups=1001(rob)[root@server0 ~]# id brianuid=1002(brian) gid=1002(brian) groups=1002(brian) |
---|
1 | [root@server0 ~]# systemctl restart smb nmb</pre> |
---|
1 | [root@desktop0 ~]# yum -y install cifs-utils |
---|
在客户端desktop0创建两个用户rob=1002,brian=1001
123 | [root@desktop0 ~]# tail -2 /etc/passwdbrian:x:1001:1001::/home/brian:/bin/bashrob:x:1002:1002::/home/rob:/bin/bash |
---|
服务端的uid情况:rob=1001;brian=1002
客户端的uid情况:rob=1002;brian=1001
12 | [root@desktop0 ~]# mkdir /mnt/smbrob[root@desktop0 ~]# mkdir /mnt/smbbrian |
---|
123456 | [root@desktop0 ~]# mount -t cifs -o username=rob,password=redhat //server0/common /mnt/smbrob/[root@desktop0 ~]# mount -t cifs -o username=brian,password=redhat //server0/common /mnt/smbbrian/[root@desktop0 ~]# df -hFilesystem Size Used Avail Use% Mounted on//server0/common 10G 3.1G 7.0G 31% /mnt/smbrob//server0/common 10G 3.1G 7.0G 31% /mnt/smbbrian |
---|
1234 | [root@desktop0 smbbrian]# echo 'brian' > test1[root@desktop0 smbbrian]# lltotal 1024-rw-r--r--. 1 rob rob 6 Jul 24 22:39 test1 |
---|
1234 | [root@desktop0 smbrob]# echo 'rob' > test2bash: test2: Permission denied[root@desktop0 smbrob]# cat test1brian |
---|
1234 | [root@server0 ~]# id robuid=1001(rob) gid=1001(rob) groups=1001(rob)[root@server0 ~]# id brianuid=1002(brian) gid=1002(brian) groups=1002(brian) |
---|
12 | [root@desktop0 smbrob]# userdel -r rob[root@desktop0 smbrob]# userdel -r brian |
---|
服务端的uid情况:rob=1001;brian=1002
客户端的uid情况:无rob,brian用户
smbbrian]# echo 'brian222' > test3
1234 | [root@desktop0 smbbrian]# lltotal 2048-rw-r--r--. 1 1002 1002 6 Jul 24 22:39 test1-rw-r--r--. 1 1002 1002 9 Jul 24 23:02 test3 |
---|
1234 | [root@desktop0 smbrob]# echo 'rob222' > test4bash: test4: Permission denied[root@desktop0 smbrob]# cat test3brian222 |
---|
1234 | [root@server0 ~]# id robuid=1001(rob) gid=1001(rob) groups=1001(rob)[root@server0 ~]# id brianuid=1002(brian) gid=1002(brian) groups=1002(brian) |
---|
123456 | [root@desktop0 smbrob]# useradd -u 1001 rob[root@desktop0 smbrob]# useradd -u 1002 brian[root@desktop0 smbrob]# id robuid=1001(rob) gid=1001(rob) groups=1001(rob)[root@desktop0 smbrob]# id brianuid=1002(brian) gid=1002(brian) groups=1002(brian) |
---|
服务端的uid情况:rob=1001;brian=1002
客户端的uid情况:rob=1001;brian=1002
123456 | [root@desktop0 smbbrian]# echo 'brian555' > test5[root@desktop0 smbbrian]# lltotal 3072-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5 |
---|
1234 | [root@desktop0 smbrob]# echo 'rob666' > test6bash: test6: Permission denied[root@desktop0 smbrob]# cat test5brian555 |
---|
123456789101112131415161718192021222324252627282930313233343536 | [root@desktop0 ~]# su - brian[brian@desktop0 ~]$ cd /mnt/smbbrian/[brian@desktop0 smbbrian]$ echo 'brian777' > test7[brian@desktop0 smbbrian]$ lltotal 4096-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5-rw-r--r--. 1 brian brian 9 Jul 24 23:24 test7oot@desktop0 ~]# su - rob[rob@desktop0 ~]$ cd /mnt/smbbrian/[rob@desktop0 smbbrian]$ lltotal 4096-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5-rw-r--r--. 1 brian brian 9 Jul 24 23:24 test7[rob@desktop0 smbbrian]$ echo 'rob888' > test8-bash: test8: Permission denied[rob@desktop0 smbbrian]$ cat test7brian777[root@desktop0 ~]# su - student[student@desktop0 ~]$ cd /mnt/smbbrian/[student@desktop0 smbbrian]$ eche 'student111' > file1-bash: file1: Permission denied[student@desktop0 smbbrian]$ lltotal 5120-rw-r--r--. 1 brian brian 0 Jul 24 23:35 file1-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5-rw-r--r--. 1 brian brian 9 Jul 24 23:24 test7-rw-r--r--. 1 brian brian 0 Jul 24 23:27 test8-rw-r--r--. 1 brian brian 9 Jul 24 23:29 test9 |
---|
123456789101112131415161718192021222324252627282930313233 | [root@desktop0 ~]# su - brian[brian@desktop0 ~]$ cd /mnt/smbbrian/[brian@desktop0 smbbrian]$ echo 'brian999' > test9[brian@desktop0 smbbrian]$ lltotal 5120-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5-rw-r--r--. 1 brian brian 9 Jul 24 23:24 test7-rw-r--r--. 1 brian brian 0 Jul 24 23:27 test8-rw-r--r--. 1 brian brian 9 Jul 24 23:29 test9[root@desktop0 ~]# su - rob[rob@desktop0 ~]$ cd /mnt/smbrob/[rob@desktop0 smbrob]$ echp 'rob1010' > test10-bash: test10: Permission denied[rob@desktop0 smbrob]$ cat test9brian999[root@desktop0 ~]# su - student[student@desktop0 ~]$ cd /mnt/smbrob/[student@desktop0 smbrob]$ echo 'student222' > file2-bash: file2: Permission denied[student@desktop0 smbrob]$ lltotal 5120-rw-r--r--. 1 brian brian 0 Jul 24 23:35 file1-rw-r--r--. 1 brian brian 6 Jul 24 22:39 test1-rw-r--r--. 1 brian brian 9 Jul 24 23:02 test3-rw-r--r--. 1 brian brian 9 Jul 24 23:17 test5-rw-r--r--. 1 brian brian 9 Jul 24 23:24 test7-rw-r--r--. 1 brian brian 0 Jul 24 23:27 test8-rw-r--r--. 1 brian brian 9 Jul 24 23:29 test9[student@desktop0 smbrob]$ cat file1 |
---|