一起來samba

   最近與室友之間頻繁傳文件,不喜飛鴿飛秋之類的,太麻煩,就整個samba服務器。

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

本文出自 “不材神木” 博客,請務必保留此出處http://ouroboros.blog.51cto.com/2468486/562960

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章