最近與室友之間頻繁傳文件,不喜飛鴿飛秋之類的,太麻煩,就整個samba服務器。
samba安裝簡單,這裏就不說怎麼安裝了。
首先,爲samba添加幾個用戶,需要注意的是使用smbpasswd添加的用戶必須先存在於/etc/passwd.
- [root@s1 ~]# groupadd -g 30000 room
- [root@s1 ~]# for user in sheng yan qin
- > do
- > useradd -G room -s /sbin/nologin $user
- > done
- #以上爲系統添加room組及無登錄權限之用戶
- [root@s1 ~]# for user in sheng yan qin
- > do
- > echo Adding $user to the smbpasswd file...
- > smbpasswd -a $user
- > done
- #以上添加smb用戶,其中smbpasswd -a 爲添加用戶,不加參數a則爲修改用戶
創建共享文件夾/share,要求組成員只能修改自己的文件,屬組爲room
- [root@s1 ~]# mkdir -v /share
- [root@s1 ~]# chgrp room /share
- [root@s1 ~]# chmod 3775 /share
由於開啓了SELinux需要相應上下文設置,方法有二
- 方法一:
- [root@s1 ~]# setsebool -P allow_smbd_anon_write on
- [root@s1 ~]# chcon -t public_content_rw_t /share
- 方法二:
- [root@s1 ~]# chcon -t samba_share_t /share
好了,終於可以開始配置文件了,要求只有room組成員有寫權限,其他人只讀,不要求訪客訪問以及組成員不能刪除其他人文件,創建的新文件權限爲0664
- [room]
- comment = share of 405
- path = /share
- write list = @room
- read only = yes
- public = no
- create mask = 0664
- #以上添加在/etc/samba/smb.conf末尾即可
到此,可以使用testparm檢查一下配置文件的語法,如果沒有問題,便可開啓smb服務了
- [root@s1 ~]# testparm
- Load smb config files from /etc/samba/smb.conf
- ...
- [root@s1 ~]# service smb restart
window客戶端訪問此處略去不說了,linux可以在命令行下使用smbclient命令
- smbclient -U yan //10.106.6.201/room
- #回車後輸入密碼即可
本文出自 “不材神木” 博客,請務必保留此出處http://ouroboros.blog.51cto.com/2468486/562960