How to Set Up a Samba Server on Ubuntu: Secure File Sharing Guide
Accessing File in Same Network using LAN

Samba lets an Ubuntu computer share files with Windows, Linux and macOS devices over a local network. It implements the SMB file-sharing protocol, so other computers can connect to shared folders through their normal file managers.
This guide walks through a standalone Samba file server on Ubuntu. It covers a password-protected share as the recommended option and an optional read-only guest share for non-sensitive files on a trusted network. It also explains Linux folder permissions, firewall restrictions, testing and common connection problems.
Security first: avoid making a guest share writable by everyone. The old combination of chmod 0777, guest ok = yes and writable = yes allows unauthenticated network users to change or delete shared files. The examples below use narrower permissions.
What you need
- An Ubuntu desktop or server with a supported release and an administrator account that can use
sudo. - A working local network connecting the Ubuntu computer and the client devices.
- The Ubuntu computer’s IP address or a hostname that other devices can resolve.
- A Linux user account for anyone who needs authenticated access to the private share.
The examples use the placeholder account shareuser. Replace it with your own Linux username and change paths or share names if you prefer. This is a simple standalone file-server setup, not an Active Directory domain-controller configuration.
1. Install Samba on Ubuntu
Open a terminal and refresh the package index:
sudo apt update
Install the Samba server package:
sudo apt install samba
You do not need to run a full distribution upgrade just to install Samba. If you want to apply normal system updates, review those separately according to your maintenance process.
Check the installed Samba version and the file-sharing service:
smbd --version
sudo systemctl status smbd
The smbd daemon provides SMB file and print services. Ubuntu’s server guide also documents the nmbd service for NetBIOS name services. If you connect directly by IP address, you do not need network browsing to work.
2. Create a folder for the password-protected share
Use an existing Linux account or create a dedicated account for file sharing. Skip the first command if the account already exists:
sudo adduser shareuser
Create a directory outside the user’s home folder. Ubuntu’s server documentation uses /srv/samba for site-specific shared data:
sudo mkdir -p /srv/samba/private
sudo chown shareuser:shareuser /srv/samba/private
sudo chmod 0700 /srv/samba/private
These permissions give the shareuser account access to this directory while denying access to other local users. Samba access is still subject to the underlying Linux file and directory permissions; a Samba share definition cannot grant more filesystem access than the connected Unix account has.
3. Add the Linux account to Samba
Samba maintains its own password database. A Linux account is not automatically available for Samba authentication, so add the account with:
sudo smbpasswd -a shareuser
Enter and confirm a Samba password when prompted. It can be different from the Linux account password. If you use a different Linux username, substitute it in this command and in the share configuration below.
4. Configure the private share
Before changing the configuration, make a backup of the current file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo nano /etc/samba/smb.conf
Add this section at the end of /etc/samba/smb.conf:
[PrivateShare]
path = /srv/samba/private
browsable = yes
read only = no
guest ok = no
valid users = shareuser
create mask = 0600
directory mask = 0700
What these settings mean:
pathpoints to the Linux directory being shared.browsable = yesmakes the share visible when a client browses available shares.read only = nopermits write operations, provided the Linux filesystem permissions also allow them.guest ok = norequires an authenticated connection.valid users = shareuserlimits this share to the named Samba account.create maskanddirectory masklimit the permissions assigned to new files and directories.
This example is intentionally for one user. If several people need access, use a dedicated Linux group and matching filesystem permissions rather than making the directory world-writable.
Optional: allow a group of users
For a multi-user share, create a group if it does not already exist, add each approved Linux account to it, and give the group access to the directory. For example:
getent group sambashare || sudo groupadd sambashare
sudo usermod -aG sambashare shareuser
sudo chown root:sambashare /srv/samba/private
sudo chmod 2770 /srv/samba/private
Repeat the usermod command for each approved account. Add a Samba password for every account with sudo smbpasswd -a username. Then change the private share’s access and creation settings to:
valid users = @sambashare
create mask = 0660
directory mask = 2770
The set-group-ID bit on the directory helps new items inherit the shared group. Test access with each account; both Samba’s allowed-user list and Linux filesystem permissions must permit the operation.
5. Optional: create a read-only public share
A guest share does not ask clients for a username and password. Only use one for files that every device on the trusted local network may read. Do not put private documents, backups or confidential information in it.
Create a separate directory and make it readable but not writable by the guest account:
sudo mkdir -p /srv/samba/public
sudo chown root:nogroup /srv/samba/public
sudo chmod 0755 /srv/samba/public
Add this optional section to /etc/samba/smb.conf:
[PublicReadOnly]
path = /srv/samba/public
browsable = yes
guest ok = yes
read only = yes
Unlike the private share, this section allows unauthenticated access. It is deliberately read-only, and the Linux directory permissions also prevent the guest account from changing the files.
Windows compatibility note: modern Windows versions restrict or block insecure SMB guest logons by default. Microsoft warns that guest access lacks protections such as normal SMB signing and encryption. Do not weaken Windows security settings or disable SMB signing just to make a guest share connect. Use the password-protected PrivateShare instead when a Windows client rejects guest access.
6. Validate the configuration and restart Samba
Check the configuration for syntax and internal consistency before restarting the service:
sudo testparm -s
Resolve any reported errors before continuing. A successful testparm check confirms that Samba can parse the configuration; it does not prove that every client can connect or that the filesystem permissions are correct.
Restart the Samba services to apply the changes:
sudo systemctl restart smbd.service nmbd.service
sudo systemctl status smbd.service
If your setup does not use NetBIOS name services, direct connections to the server can still work without network browsing. Check the status of nmbd separately if you rely on that feature.
7. Allow Samba through the Ubuntu firewall
If UFW is active, first check its status and the installed Samba application profile:
sudo ufw status
sudo ufw app info Samba
Allow Samba only from your local network. For example, if your LAN uses 192.168.1.x, the subnet may be 192.168.1.0/24:
sudo ufw allow from 192.168.1.0/24 to any app Samba
Replace that example subnet with your actual LAN range. If you manage the server remotely, make sure your administration connection remains allowed before changing firewall rules. If another firewall or router controls access, create an equivalent rule there.
Never expose SMB directly to the public internet. In particular, block unsolicited inbound TCP port 445 at the network perimeter. Use a properly secured VPN or another managed remote-access method when remote file access is required.
8. Connect from Windows, Linux or macOS
Windows
- Find the Ubuntu computer’s IP address. You can run
hostname -Iin its terminal and identify the address on your LAN. - Open File Explorer on Windows.
- Enter the private share path in the address bar, replacing the example IP address with your server’s address:
\\192.168.1.10\PrivateShare
When prompted, enter the Samba username shareuser and the Samba password you created earlier. For the optional guest share, use \\192.168.1.10\PublicReadOnly, but remember that Windows may reject guest authentication by design.
Linux
In your file manager, choose the option to connect to a server or network location and enter:
smb://192.168.1.10/PrivateShare
Alternatively, if the Samba client utility is installed, list the shares from a terminal:
smbclient -L //192.168.1.10 -U shareuser
If the command is not found, install the client utility with sudo apt install smbclient.
macOS
Open Finder, choose Go > Connect to Server, and enter:
smb://192.168.1.10/PrivateShare
Choose to connect as a registered user and enter the Samba username and password.
9. Test the share and troubleshoot common problems
If a client cannot connect, work through these checks rather than changing permissions to 0777:
- Check the service: run
sudo systemctl status smbdand confirm that the file-sharing service is running. - Validate the configuration: run
sudo testparm -sagain after every edit tosmb.conf. - Check the Samba account: confirm that the Linux account exists and that it has a Samba password. You can set or reset it with
sudo smbpasswd shareuser. - Check directory permissions: run
namei -l /srv/samba/privateto inspect permissions on the share directory and its parent directories. The account must be able to traverse every parent directory and access the final directory. - Check the firewall: use
sudo ufw statusand confirm that the client’s subnet is allowed. Also check any router or network firewall between the devices. - Inspect logs: view recent service messages with
sudo journalctl -u smbd -n 50 --no-pager. Samba log files may also be available under/var/log/samba/. - Check the share name and address: verify the exact share name in
smb.confand make sure the client is using the correct server IP address or resolvable hostname.
For an overview of current connections, run:
sudo smbstatus
Remember that successful configuration parsing is only one part of the test. Confirm that an approved user can read and write where intended, that an unauthorised user is denied access to the private share, and that the guest share (if enabled) remains read-only.
Frequently asked questions
Is a Samba password the same as the Ubuntu login password?
Not necessarily. Samba stores its own credentials. The Linux account must exist, and you add it to Samba with sudo smbpasswd -a username. You can choose a separate Samba password.
Why can Windows not open a guest share?
Windows blocks insecure guest logons by default in many current editions and configurations. This is a security feature, not necessarily a Samba configuration error. Prefer an authenticated share rather than enabling insecure guest logons.
Why does a user authenticate but still get “Access denied”?
Samba authentication and Linux filesystem permissions are separate checks. Confirm that the user is listed in valid users, can traverse the parent directories, and has the required read or write permissions on the shared folder.
Should I use chmod 0777 for a Samba folder?
No, not as a routine fix. It grants read, write and execute permissions to every local user and can make a writable guest share especially risky. Assign access to a specific account or group and grant only the permissions that are needed.
Conclusion
Samba provides a practical way to share files between Ubuntu and other operating systems. For everyday use, start with a password-protected share, a dedicated account and restrictive Linux permissions. Add a guest share only when there is a clear need, keep it read-only, and limit it to non-sensitive files on a trusted network.
Validate every configuration change with testparm, restrict firewall access to the local network, and test both permitted and denied access before storing important files on the server.
Official documentation
- Ubuntu Server: Set up Samba as a file server
- Ubuntu Server: Samba share access controls
- Ubuntu Server: Firewall and UFW guidance
- Samba: Current smb.conf reference
- Samba: testparm manual
- Microsoft: Insecure SMB guest logons
- Microsoft: Secure SMB traffic






