萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux Samba 伺服器完整設定手冊:安裝、smb.conf 範例、服務管理

前言

Samba 讓 Linux 與 Windows 在區域網路無縫共享檔案,Linux 如同網路鄰居般可被存取,亦可掛載 Windows 磁碟如本地檔案。新手也能輕鬆上手。

一、安裝 Samba

若系統內建版本為 1.x,請先移除,從 官網 下載 2.0.x 版。已有 2.0 可跳過安裝。

  1. 解壓至 /tmp:tar zxvf samba-xxxxxx.tgz -C /tmp
  2. 進入原始碼目錄:cd /tmp/samba-xxxxx/src/
  3. 核心 ≥ 2.1.70:./configure --enable-smbmount,否則直接 ./configure
  4. 編譯:make
  5. Root 安裝:cp -a /tmp/samba-xxxx /usr/local → cd /usr/local/samba-xxxx/source && make install
  6. 系統將在 /usr/local/samba 建立二進制、設定、日誌目錄

二、配置 smb.conf

建立 /usr/local/samba/lib/smb.conf,最小測試設定:

[global]
workgroup = workgroup
[all]
path = /
read only = yes

關鍵:workgroup 必須與 Windows 網路工作組名稱一致。

啟動服務

/usr/local/samba/bin/nmbd -D
/usr/local/samba/bin/smbd -D

Windows 登入既有 Linux 帳號密碼即可存取。

完整生產環境設定範例

[global]
workgroup = workgroup
guest account = nobody
keep alive = 30
os level = 2
security = user
printing = bsd
printcap name = /etc/printcap
load printers = yes
wins support = no
; wins server = 192.168.1.1

[local]
path = /usr/local
read only = yes

[homes]
comment = Home Directory
browseable = no
read only = no
create mode = 0750

[cdrom]
comment = Linux CD-ROM
path = /cdrom
read only = yes
locking = no

[printers]
comment = All Printers
browseable = no
printable = yes
public = no
read only = yes
create mode = 0700
directory = /tmp

修改設定後重啟服務

  1. ps x 找出 nmbd、smbd PID
  2. kill PID 終止舊進程
  3. 重新執行上述啟動指令

若 Windows 找不到 Linux 主機,請檢查 /usr/local/samba/var/log.smb 與 log.nmb。

copyright © 萬盛學電腦網 all rights reserved