Complete Guide to Samba Source Compilation and Installation (Linux Systems)
This guide details how to compile and install Samba from source, covering dependency installation, configuration options, build compilation, systemd service configuration, startup management, and basic usage. Applicable to major Linux distributions including Fedora, CentOS, Rocky Linux, Ubuntu, Debian, and openSUSE.
Note: Samba’s official code repository is primarily on GitLab, but source packages can also be obtained from the Samba website or GitHub.
1. Extract Source Package
First, download and extract the Samba source package (using version x.y.z as an example):
tar -zxf samba-x.y.z.tar.gz
cd samba-x.y.z
2. Install Dependencies
2.1 Using Official Scripts (for Fedora / CentOS / Ubuntu / Debian / openSUSE)
Samba provides dependency installation scripts for common distributions:
cd <samba-source-dir>/bootstrap/generated-dists/<distro-with-version>
./bootstrap.sh
Replace
<distro-with-version>with the actual directory name, such asfedora38.
2.2 Manual Dependency Installation (Rocky Linux Example)
If your system is not covered by official scripts, manually install the following dependencies:
dnf install -y gcc libtirpc-devel glibc-devel zlib-devel gnutls-devel \
libattr-devel python3-devel lmdb-devel gpgme-devel perl-Parse-Yapp \
jansson-devel libarchive-devel libacl-devel openldap-devel pam-devel \
rpcgen libtalloc-devel libtdb-devel libtevent-devel
2.3 Additional Dependencies for Samba 4.19.3+
From Samba 4.19.3 onwards, additional Python and D-Bus related components may need to be installed:
pip install markdown dnspython3
dnf install -y dbus-c++-devel dbus-python-devel python3-markdown python3-dns
3. Configure Compilation Options
3.1 View All Configuration Options
./configure --help
3.2 Default Configuration
./configure
3.3 Custom Configuration Example
The following is a FHS-compatible configuration commonly used in production environments:
./configure \
--sbindir=/usr/sbin \
--with-piddir=/run \
--with-configdir=/etc/samba \
--bindir=/usr/bin \
--localstatedir=/var \
--enable-fhs \
--libdir=/usr/lib64 \
--with-modulesdir=/usr/lib64/samba \
--sysconfdir=/etc \
--with-lockdir=/var/lib/samba/lock \
--with-cachedir=/var/lib/samba \
--enable-debug \
--enable-pthreadpool \
--valgrind \
--valgrind-log="/var/log/samba/" \
--with-systemd
⚠️ Note: If you have made secondary development on Samba, set environment variables before
./configureto avoid linking issues, for example:export LDFLAGS="-lrt"
3.4 Common configure Parameter Explanations
| Parameter | Description |
|---|---|
--prefix=/usr/local/myinstall | Specifies unified installation prefix (default is scattered installation) |
--with-tk=/usr/local | Specifies Tk library path |
--with-php-config=/path/to/php-config | Specifies PHP configuration tool path (for module conflicts) |
--without-gnu-ld | Do not use system GNU ld linker |
3.5 Setting Compilation Environment Variables (Cross-compilation, etc.)
CC=/usr/bin/mipsel-linux-gcc
CFLAGS="-g -O2 -I/home/a/buildspace/termcap-1.3.1/install/include"
LDFLAGS="-L/home/a/buildspace/termcap-1.3.1/install/lib"
LIBS="-lpthread"
4. Compilation and Installation
Samba uses the WAF build system, but is compatible with the make interface:
make && make install
⚠️ Important: If the system’s default Python is v2, WAF may fail. Explicitly specify Python 3:
PYTHON=python3.9 make -j6 PYTHON=python3.9 make install
5. Configure systemd Services (Fedora Example)
After default installation, systemd unit files may be missing. Create the following three service files according to your system (paths may vary by distribution):
5.1 /usr/lib/systemd/system/smb.service
[Unit]
Description=Samba SMB Daemon
Documentation=man:smbd(8) man:samba(7) man:smb.conf(5)
Wants=network-online.target
After=network.target network-online.target nmb.service winbind.service
[Service]
Type=simple
PIDFile=/run/smbd.pid
LimitNOFILE=16384
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/usr/sbin/smbd --foreground --no-process-group $SMBDOPTIONS
ExecReload=/bin/kill -HUP $MAINPID
LimitCORE=infinity
Environment=KRB5CCNAME=FILE:/run/samba/krb5cc_samba
[Install]
WantedBy=multi-user.target
5.2 /usr/lib/systemd/system/nmb.service
[Unit]
Description=Samba NMB Daemon
Documentation=man:nmbd(8) man:samba(7) man:smb.conf(5)
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=simple
PIDFile=/run/nmbd.pid
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/usr/sbin/nmbd --foreground --no-process-group $NMBDOPTIONS
ExecReload=/bin/kill -HUP $MAINPID
LimitCORE=infinity
Environment=KRB5CCNAME=FILE:/run/samba/krb5cc_samba
[Install]
WantedBy=multi-user.target
5.3 /usr/lib/systemd/system/winbind.service
[Unit]
Description=Samba Winbind Daemon
After=syslog.target network.target nmb.service
[Service]
Environment=KRB5CCNAME=FILE:/run/samba/krb5cc_samba
Type=simple
NotifyAccess=all
PIDFile=/run/winbindd.pid
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/usr/sbin/winbindd --foreground --no-process-group "$WINBINDOPTIONS"
ExecReload=/usr/bin/kill -HUP $MAINPID
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
✅ Recommendation: The default configuration file uses
Type=notify. It is recommended to change it toType=simpleto avoid service failures due to startup timeouts.
5.4 Reload systemd and Start Services
systemctl daemon-reload
systemctl start smb nmb winbind
# Or use legacy aliases (supported by some systems)
systemctl start samba
5.5 Stop Samba Services
-
Method 1 (Recommended):
systemctl stop smb nmb winbind -
Method 2 (Manual kill):
ps -aux | grep smbd kill <pid1> <pid2>Note: PIDs shown by
smbstatuscan terminate specific client connections without affecting the overall service.
5.6 Check Service Status
# Method 1
systemctl status smb nmb winbind
# Method 2
smbstatus
Press
qorCtrl+Cto exitsmbstatus.
6. Basic Usage and Configuration
6.1 Create Samba Configuration File
Edit /etc/samba/smb.conf (create new if it doesn’t exist):
[global]
client max protocol = SMB3
load printers = No
map to guest = Bad User
printcap name = cups
security = USER
workgroup = SAMBA
idmap config * : backend = tdb
cups options = raw
guest ok = Yes
[homes]
comment = Home Directories
inherit acls = Yes
read only = No
valid users = %S %D%w%S
[printers]
browseable = No
comment = All Printers
create mask = 0600
path = /var/tmp
printable = Yes
[print$]
comment = Printer Drivers
create mask = 0664
directory mask = 0775
force group = @printadmin
path = /var/lib/samba/drivers
write list = @printadmin root
[myshare]
comment = public document
create mask = 0777
directory mask = 0777
path = /home/a/share
read only = No
valid users = a root smb_user
⚠️ Permission Requirements: Ensure the shared directory exists and permissions match, for example:
mkdir -p /home/a/share chmod 777 /home/a/share
6.2 Add Samba Users
# Create system user (optional)
sudo useradd username -g usergroup
# Set Samba password (required)
sudo smbpasswd -a username
6.3 Client Access to Shares
Linux Client
# Ensure mount point exists
mkdir -p /cifs
# Mount CIFS share (SMB3)
mount -t cifs \
-o username=a,password=12345678,dir_mode=0777,file_mode=0777,nounix,vers=3.0 \
//10.0.0.10/myshare /cifs
Windows Client
Enter in the taskbar search box:
\\10.0.0.10\myshare
Then enter username and password to access.
Summary
Through this guide, you have mastered the complete process of compiling and installing Samba from source, including dependency handling, custom configuration, systemd integration, and basic share configuration. This solution is suitable for production environments with high requirements for security, performance, or customization.