The Real Problem: Files on Ubuntu That Windows Can’t See
When I first started as a sysadmin, I was handed a task: set up an Ubuntu server as a file server for the entire team. We had 15 people in the office — mostly on Windows, a few on macOS, and me on Ubuntu. The challenge: how do you let everyone access a shared folder from Windows without installing extra software?
I tried SFTP first — it worked, but required WinSCP or FileZilla. NFS was fine, but Windows only supports it natively on Enterprise editions. Samba turned out to be the answer: it mounts directly as a drive in File Explorer, just like a regular hard disk, with nothing extra to install.
How Samba Works — and Why Not NFS or SFTP?
Samba is an open-source implementation of the SMB/CIFS protocol — the same protocol Windows uses for file and printer sharing over a LAN. That network drive you see appear under “This PC”? Most of the time, it’s SMB running quietly in the background.
A quick comparison of the three options:
- NFS: Great for Linux-to-Linux, but Windows requires Enterprise edition or third-party software
- SFTP/FTP: Requires a client app and can’t be mounted as a regular drive
- Samba (SMB): Natively supported on Windows and macOS — mounts directly into File Explorer or Finder
When I switched from CentOS to Ubuntu, it took me about a week to get used to apt instead of yum. But Samba was noticeably easier to configure: the config file lives exactly where you’d expect, the package manager is clean, and most importantly — no SELinux randomly blocking you like on CentOS.
Two Ways to Set Up Samba
Option 1: GUI on Ubuntu Desktop
Nautilus has a built-in “Share Folder” feature. Right-click a folder → Properties → Share. Quick and easy, but limited control and won’t work on a headless server.
Option 2: Manual Configuration via smb.conf
Full control, works for both development and production environments. This is the approach I’ll walk through in detail below.
Step-by-Step Samba Installation and Configuration
Step 1: Install Samba
sudo apt update
sudo apt install samba samba-common -y
# Kiểm tra version
smbd --version
# Kết quả: Version 4.15.13-Ubuntu
Step 2: Create the Shared Directories
# Public share (ai cũng truy cập được)
sudo mkdir -p /srv/samba/shared
sudo chmod 0777 /srv/samba/shared
sudo chown nobody:nogroup /srv/samba/shared
# Private share (chỉ user có tài khoản)
sudo mkdir -p /srv/samba/private
sudo chmod 0755 /srv/samba/private
Step 3: Back Up and Configure smb.conf
The main configuration file lives at /etc/samba/smb.conf. Always back it up before making changes — this is a step I never skip:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo nano /etc/samba/smb.conf
Add the following to the end of the file:
# ===== Public Share (không cần đăng nhập) =====
[shared]
comment = Public Shared Folder
path = /srv/samba/shared
browsable = yes
writable = yes
guest ok = yes
read only = no
create mask = 0777
directory mask = 0777
# ===== Private Share (cần đăng nhập) =====
[private]
comment = Private Folder
path = /srv/samba/private
browsable = yes
writable = yes
guest ok = no
valid users = @samba
read only = no
create mask = 0644
directory mask = 0755
Step 4: Create a Samba User
This is where most people get confused: Samba maintains its own user database, completely separate from /etc/passwd. You must create a Linux user first, then add them to Samba — skip either step and you’ll hit errors immediately:
# Tạo Linux user (nếu chưa có)
sudo adduser sambauser
# Tạo group và thêm user vào
sudo groupadd samba
sudo usermod -aG samba sambauser
# Add vào Samba database và set password
sudo smbpasswd -a sambauser
# Hệ thống hỏi mật khẩu — khác với mật khẩu Linux
# Enable user
sudo smbpasswd -e sambauser
Step 5: Validate the Configuration and Start the Service
# Kiểm tra syntax config trước khi restart
testparm
# Restart Samba
sudo systemctl restart smbd nmbd
# Bật auto-start khi boot
sudo systemctl enable smbd nmbd
# Kiểm tra trạng thái
sudo systemctl status smbd
Step 6: Open the UFW Firewall
sudo ufw allow samba
sudo ufw reload
sudo ufw status
The allow samba rule automatically opens ports 137 and 138 (UDP) and 139 and 445 (TCP) — no need to specify each port manually.
Step 7: Connect from Other Operating Systems
From Windows — open File Explorer and type the following into the address bar:
\\192.168.1.100\shared
# Thay IP bằng địa chỉ Ubuntu server của bạn
To mount it as a persistent drive: right-click “This PC” → Map network drive → enter the UNC path above.
From macOS — open Finder → Go → Connect to Server (⌘K):
smb://192.168.1.100/shared
From another Linux machine:
sudo apt install smbclient cifs-utils
# List tất cả shares trên server
smbclient -L //192.168.1.100 -N
# Mount public share
sudo mount -t cifs //192.168.1.100/shared /mnt/samba -o guest
# Mount private share với user
sudo mount -t cifs //192.168.1.100/private /mnt/private \
-o username=sambauser,password=yourpassword
Additional Configuration for Real-World Use
Monitoring Connections
# Xem log realtime
sudo tail -f /var/log/samba/log.smbd
# Xem các kết nối đang active
sudo smbstatus
Adding Logging to the [global] Section
[global]
workgroup = WORKGROUP
log level = 1
log file = /var/log/samba/log.%m
max log size = 50
Troubleshooting Common Issues
Can’t connect even though the firewall is open? Check the workgroup setting immediately — Windows defaults to “WORKGROUP” and so does Samba, but a mismatch here is enough to break the connection entirely:
grep -i workgroup /etc/samba/smb.conf
Getting “Permission denied” when writing files? Nine times out of ten, it’s a Linux directory permission issue — not a Samba configuration problem:
ls -la /srv/samba/
# Kiểm tra ownership và permission của từng thư mục
One key difference from CentOS: Ubuntu does not have SELinux enabled by default. When you hit a permission issue, just check the Linux file permissions — no need to touch semanage or chcon.
Wrapping Up
The entire setup takes about 15–20 minutes. The sequence is: install the package → create directories → configure smb.conf → create a Samba user → open the firewall → test the connection. The most common source of confusion is that Samba’s user database is separate from Linux users, and directory permissions must be correct before any Samba configuration takes effect.
This setup is more than enough for a small internal file server with under 20 users. When you need to scale up — more complex group-based permissions, Active Directory integration, or managing dozens of users — that’s when it’s worth diving deeper into Samba ACLs and winbind.

