Samba lets Ubuntu-based systems share files and printers with Windows, macOS, and other Linux machines over a local network. It implements the SMB/CIFS protocol natively, so Windows clients can browse shared folders without any extra software. This guide walks through installing Samba on Ubuntu, editing the configuration file, creating user accounts, and connecting from other devices.
Install Samba on Ubuntu
Open a terminal and update the package index before installing. This keeps you on the latest available version from the Ubuntu repositories.
sudo apt update
sudo apt install samba
Once the installation finishes, confirm it worked by checking the installed path:
whereis samba
The output should list paths like /usr/sbin/samba and /etc/samba. You can also run smbd --version to see the exact Samba version installed on your system.
The smbd daemon starts automatically after installation and handles file sharing and authentication. On current Ubuntu releases, the nmbd service for legacy NetBIOS name resolution may be disabled by default. You can verify the Samba service status with the systemctl command:
sudo systemctl status smbd
Create a Shared Directory for Samba File Sharing
Before editing the Samba configuration, create the folder you want to share. A common approach is placing it inside your home directory:
mkdir /home/username/sambashare
Replace username with your actual Linux account name. If you need to share an existing folder on another drive, make sure the directory permissions allow Samba to read and write. You can adjust ownership with the chown utility if the folder belongs to a different user.
For a publicly accessible share that doesn’t require login, create a separate directory:
sudo mkdir -p /srv/samba/public
sudo chmod 777 /srv/samba/public
Configure Samba on Ubuntu (smb.conf)
Samba stores all its settings in /etc/samba/smb.conf. Open the file in a text editor — vi or nano both work fine:
sudo nano /etc/samba/smb.conf
Scroll to the bottom and add a block for your new share:
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes
Each directive does something specific. The path points to the directory on disk. Setting read only to no grants write access. The browsable directive controls whether the share appears when clients browse the network.
If you created a public share earlier, add a second block:
[public]
comment = Public Share
path = /srv/samba/public
browsable = yes
guest ok = yes
read only = no
create mask = 0755
The guest ok = yes line allows connections without a password. The create mask sets default permissions on new files. Save and close the editor, then restart the Samba service:
sudo systemctl restart smbd
Run testparm after saving to check for syntax errors in your configuration file. It parses smb.conf and reports any problems before they cause connection failures.
Set Up Samba User Accounts
Samba maintains its own password database, separate from the system login. The user account must already exist as a Linux system user before you can add it to Samba. Create the Samba password with:
sudo smbpasswd -a username
You’ll be prompted to type and confirm a password. This is the credential clients will use when connecting to the share. To disable a Samba user later, run sudo smbpasswd -d username.
Allow Samba Through the Ubuntu Firewall
Ubuntu ships with UFW (Uncomplicated Firewall), which may block Samba traffic by default. Allow it with a single command:
sudo ufw allow samba
This opens the ports Samba needs — typically 137, 138, 139, and 445. Verify the rule was added by running sudo ufw status.
Connect to a Samba Share from Other Devices
From Ubuntu or Other Linux Desktops
Open the default file manager and click “Other Locations” at the bottom of the sidebar. In the “Connect to Server” bar at the bottom, type:
smb://server-ip-address/sambashare
Enter the Samba username and password when prompted. You can also connect from the terminal using the smbclient tool:
smbclient //server-ip-address/sambashare -U username
From Windows
Open File Explorer and type the following in the address bar:
\\server-ip-address\sambashare
Windows will ask for credentials. Enter the Samba username and password you created earlier. If you enabled a guest share, Windows may connect without prompting.
From macOS
In Finder, click Go > Connect to Server. Enter smb://server-ip-address/sambashare and provide your credentials when asked.
Troubleshooting Samba File Sharing on Ubuntu
Connection failures usually fall into a few categories. If the share doesn’t appear on the network, check that smbd is running and that your firewall rules are correct. If authentication fails, make sure the user exists in both the Linux system and the Samba password database.
Permission errors after connecting typically mean the directory on disk has restrictive ownership or permissions. Match the Linux filesystem permissions to what you configured in smb.conf. A quick test: temporarily set chmod 777 on the shared folder and retry — if it works, tighten permissions gradually until you find the right balance.
If you’re running a dual-boot setup and can’t reach the Samba server from Windows, confirm both systems are on the same network subnet.
FAQs
Does Samba work on all Ubuntu-based Linux distributions?
Yes. Samba works on Ubuntu, Linux Mint, Pop!_OS, Zorin OS, and any other distribution based on Ubuntu. The installation commands and configuration file location are identical across all of them.
Can I configure Samba file sharing without a password?
Yes. Set guest ok = yes in your share block inside smb.conf and add map to guest = Bad User under the [global] section. Restart smbd after saving the changes.
What ports does Samba use on Ubuntu?
Samba uses TCP ports 139 and 445 for file sharing. UDP ports 137 and 138 handle NetBIOS name resolution and browsing. Open all four if your firewall blocks them.
How do I share a folder with read-only access through Samba?
Set read only = yes in the share definition inside /etc/samba/smb.conf. Restart the Samba service with sudo systemctl restart smbd to apply the change.
Why can’t Windows see my Ubuntu Samba share?
Check that both devices are on the same network, the UFW firewall allows Samba traffic, and the smbd service is active. Run testparm to verify your smb.conf has no syntax errors.