顯示具有 samba 標籤的文章。 顯示所有文章
顯示具有 samba 標籤的文章。 顯示所有文章

2021年11月4日 星期四

在 Fedora 上安裝 Samba Server

1. 安裝相關套件

sudo dnf upgrade
sudo dnf install samba
其中,libnss-winbind 可讓 Linux 解析 Windows 的主機名。

2. 相關設定檔

2.1. smb.conf

/etc/samba/smb.conf

2.1.1. 一般使用者「家」目錄設定

[global]
    workgroup = WORKGROUP
    server string = Samba Server Version %v
    netbios name = CY
    security = user
    passdb backend = tdbsam

[homes]
    comment = Home Directories
    valid users = %S, %D%w%S
    browseable = Yes
    read only  = No
    inherit acls = Yes


3. 資源管理

3.1. 新增使用者

sudo pdbedit -a -u user_name
其中,user_name為你要給定的使用者帳號名稱。
實作範例:
cy@cy:~$ sudo pdbedit -a -u cy
retype new password:
Unix username:        cy
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-21-3922602909-3884501703-394166850-1000
Primary Group SID:    S-1-5-21-3922602909-3884501703-394166850-513
Full Name:            CY
Home Directory:       \\CY\cy
HomeDir Drive:
Logon Script:
Profile Path:         \\CY\cykuo\profile
Domain:               CY
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          三, 06  2月 2036 23:06:39 CST
Kickoff time:         三, 06  2月 2036 23:06:39 CST
Password last set:    三, 03 11月 2021 20:14:20 CST
Password can change:  三, 03 11月 2021 20:14:20 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


4. 測試

4.1. 測試 smb.conf 設定是否正確

testparm
實作範例:
cy@cy:~$ testparm
Load smb config files from /etc/samba/smb.conf
lpcfg_do_global_parameter: WARNING: The "encrypt passwords" option is deprecated
Loaded services file OK.
Weak crypto is allowed

Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        security = USER
        server string = Samba Server Version %v
        idmap config * : backend = tdb


[homes]
        comment = Home Directories
        inherit acls = Yes
        read only = No
        valid users = %S %D%w%S


5. 安全設定

5.1. 防火牆

firewall-cmd --get-active-zones
sudo firewall-cmd --permanent --zone=FedoraWorkstation --add-service=samba
sudo firewall-cmd --reload

5.2. Selinux

setsebool -P samba_enable_home_dirs=1


6. 服務管理

systemctl status smb.service nmb.service
systemctl restart smb.service nmb.service
systemctl enable smb.service nmb.service


2017年1月24日 星期二

在 Ubuntu 上安裝 Samba Server

1. 安裝相關套件

sudo apt update
sudo apt upgrade
sudo apt install samba
sudo apt install libnss-winbind
其中,libnss-winbind 可讓 Linux 解析 Windows 的主機名。

2. 相關設定檔

2.1. smb.conf

/etc/samba/smb.conf

2.1.1. 一般使用者「家」目錄設定

[homes]
   comment = Home Directories
   browseable = yes
   read only  = no
   create mode    = 0600
   directory mode = 0700

2.2. nsswitch.conf

/etc/nsswitch.conf

2.2.1. 讓 Linux 解析 Windows 的主機名

hosts:          files mdns4_minimal [NOTFOUND=return] dns wins
在 hosts 後面多加一個 wins。

3. 資源管理

3.1. 新增使用者

sudo pdbedit -a -u user_name
其中,user_name為你要給定的使用者帳號名稱。
實作範例:
cy@cyvm:~$ sudo pdbedit -a -u cy
new password:
retype new password:
Unix username:        cy
NT username:
Account Flags:        [U          ]
User SID:             S-1-5-12-12345678-123456789-123456789-1234
Primary Group SID:    S-1-5-12-12345678-123456789-123456789-321
Full Name:            CY
Home Directory:       \\cyvm\cy
HomeDir Drive:
Logon Script:
Profile Path:         \\cyvm\cy\profile
Domain:               CYVM
Account desc:
Workstations:
Munged dial:
Logon time:           0
Logoff time:          三, 06  二  2036 23:06:39 CST
Kickoff time:         三, 06  二  2036 23:06:39 CST
Password last set:    二, 24  一  2017 23:46:36 CST
Password can change:  二, 24  一  2017 23:46:36 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


4. 測試

4.1. 測試 smb.conf 設定是否正確

testparm
實作範例:
cy@cyvm:~$ testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
WARNING: The "syslog" option is deprecated
Processing section "[homes]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        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
        syslog = 0
        log file = /var/log/samba/log.%m
        max log size = 1000
        dns proxy = No
        usershare allow guests = Yes
        panic action = /usr/share/samba/panic-action %d
        idmap config * : backend = tdb


[homes]
        comment = Home Directories
        read only = No
        create mask = 0600
        directory mask = 0700
        directory mode = 0700


5. 服務管理

systemctl status smbd.service
systemctl restart smbd.service
systemctl enable smbd.service