Linux架設samba伺服器

本文章使用的環境ubuntu 16.0.4
安裝samba

sudo apt-get install -y samba samba-common python-glade2 system-config-samba

備份文件

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

配置文件

vim /etc/samba/smb.conf

設定[global]
啟用smb2.0

在[global]底下加入
min protocol = SMB2

更改netbios name,這個事網路探索時顯示的名子,可以隨便取

netbios name = KING

設定Windows 用戶端的編碼為 big5 編碼

dos charset = cp950

在頁面最後加入

[king]
comment = need share
browseable = yes
path = /samba/anonymous
create mask = 0777
directory mask = 0777
valid users = king
force user = king
force group = king
public = yes
writable = yes
available = yes

變更欲分享資料夾的權限

cd /samba
chmod -R 0770 anonymous
chown -R king:king /samba/anonymous

加入使用者

sudo smbpasswd -a 帳號

firewalld防火牆設定

暫時開通 samba 服務

firewall-cmd --zone=public --add-service samba

永久開通 samba 服務

firewall-cmd --zone=public --permanent --add-service samba 

ufw防火牆設定

ufw allow Samba

重啟samba

systemctl restart smbd.service

查看狀態

systemctl status smbd.service

底下為實際完整配置

[global]
    dos charset = cp950
    netbios name = KING
    server string = %h server (Samba, Ubuntu)
    server role = standalone server
    map to guest = Bad User
    obey pam restrictions = Yes
    pam password change = Yes
    passwd program = /usr/bin/passwd %u
    passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
    unix password sync = Yes
    log file = /var/log/samba/log.%m
    max log size = 1000
    max protocol = SMB3
    protocol = SMB3
    server min protocol = SMB2
    min protocol = SMB2
    load printers = No
    dns proxy = No
    usershare allow guests = Yes
    panic action = /usr/share/samba/panic-action %d
    idmap config * : backend = tdb


[king]
    comment = need share
    path = /samba/anonymous
    valid users = king
    force user = king
    force group = king
    group = king
    read only = No
    create mask = 0777
    directory mask = 0777
    directory mode = 0777
    guest ok = Yes

驗證是否有語法錯誤

testparm

解決 rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384) 錯誤
解決方法:
修改 /etc/security/limits.conf 設定檔

vim /etc/security/limits.conf

在最底下加入

*                -       nofile          16384

然後重啟系統
這個錯誤訊息會根據不同的使用者而出現,像我使用root看的到,使用king使用者就看不到。

windows 7 測試
新增網路磁碟
使用帳密登錄
填寫如下

//IP/king

上面的king跟我們的設定檔有關

Last modification:May 19th, 2018 at 11:32 pm