🖥️ How to Install and Configure Samba on Ubuntu
Samba is an open-source implementation of the SMB/CIFS networking protocol, allowing Linux systems to share files and printers with Windows and other clients.
This guide walks through installing Samba, configuring a share, creating users, and troubleshooting.
1. Update and Install Samba
First, update your package list and install Samba:
sudo apt update
sudo apt install samba -y
Check that the installation was successful:
smbd --version
2. Backup the Default Samba Configuration
Always back up the original configuration before making changes:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bkp
View the backup (optional):
cat /etc/samba/smb.conf.bkp
3. Configure Samba Share
Open the Samba configuration file:
sudo nano /etc/samba/smb.conf
At the bottom, add a new share definition:
[Share]
comment = Shared Folder
path = /
browseable = yes
writable = yes
guest ok = no
valid users = smbadmin
admin users = smbadmin
delete readonly = yes
inherit permissions = yes
create mask = 0664
directory mask = 0775
⚠️ Important:
The path = / gives access to the root filesystem. For security, replace / with a specific directory, e.g., /srv/samba/share.
4. Test Configuration
Run the following command to validate the config file:
testparm
5. Create Samba User
Samba uses its own user accounts (mapped to system users).
Create a system account for Samba (no login shell, no home dir):
bashsudo adduser --no-create-home --shell /usr/sbin/nologin smbadminEnable the Samba user:
bashsudo smbpasswd -e smbadminAdd this user to Samba:
bashsudo smbpasswd -a smbadmin
6. Restart Samba Services
After making changes, restart Samba services:
sudo systemctl restart smbd nmbd
sudo systemctl enable smbd
Check service status:
sudo systemctl status smbd
7. Configure Firewall
Allow Samba through the firewall:
sudo ufw allow samba
sudo ufw status
You can confirm Samba is listening on port 445:
nmap -p 445 localhost
8. Access the Samba Share
From a Windows or Linux client, access the share using:
\\<server-ip>\Share
Log in with:
- Username:
smbadmin - Password: (the one you set with
smbpasswd)
✅ Summary
- Installed Samba (
smbd&nmbd) - Backed up and edited
/etc/samba/smb.conf - Created a dedicated user
smbadmin - Tested configuration with
testparm - Restarted and enabled services
- Allowed Samba in the firewall
You now have a working Samba file server.