Samba is a free, open-source implementation of the SMB/CIFS network protocol that lets Linux servers share files and printers with Windows, macOS, and other Linux machines over a local network. It is the standard way to create cross-platform file shares on Ubuntu without requiring special client software on Windows or macOS.
This guide shows you how to install Samba on Ubuntu 18.04 and configure it as a standalone file server with two users and two shares. User josh gets a private share only they can access. User sadmin gets read and write access to all shares on the server.
<strong>Prerequisite:</strong> You need sudo access.
Install Samba from the Ubuntu repositories:
bashsudo apt updatesudo apt install samba
The Samba service starts automatically after installation. Verify it is running:
bashsudo systemctl status smbd
Open the firewall. Samba uses UDP ports 137 and 138 for NetBIOS and TCP ports 139 and 445 for file sharing. The easiest way to open all of them at once with UFW is:
bashsudo ufw allow 'Samba'
Back up the default config before making any changes:
bashsudo cp /etc/samba/smb.conf{,.backup}
Open /etc/samba/smb.conf and confirm server role = standalone server. If you want to restrict Samba to your internal network only, uncomment the interfaces and bind interfaces only = yes directives and set the correct interface name.
Run testparm to validate the config for syntax errors, then restart the services:
bashsudo systemctl restart smbdsudo systemctl restart nmbd
All Samba data in this setup lives under /samba/ rather than standard home directories. Create the root directory and assign it to the sambashare group, which Samba creates during installation:
bashsudo mkdir /sambasudo chgrp sambashare /samba
Create user josh. The -M flag skips the Linux home directory since we are creating it manually. The -s /usr/sbin/nologin flag prevents shell login, and -G sambashare adds the user to the Samba group:
bashsudo useradd -M -d /samba/josh -s /usr/sbin/nologin -G sambashare joshsudo mkdir /samba/joshsudo chown josh:sambashare /samba/joshsudo chmod 2770 /samba/josh
The 2770 permission sets the setgid bit on the directory. This ensures every new file created inside inherits the sambashare group, so both josh and sadmin can always read and write each other’s files.
Add josh to the Samba user database and enable the account:
bashsudo smbpasswd -a joshsudo smbpasswd -e josh
Create the admin user sadmin following the same pattern, then create the shared /samba/users directory with sadmin:sambashare ownership and chmod 2770.
Open /etc/samba/smb.conf and append the share definitions:
ini[users] path = /samba/users browseable = yes read only = no force create mode = 0660 force directory mode = 2770 valid users = @sambashare @sadmin[josh] path = /samba/josh browseable = no read only = no force create mode = 0660 force directory mode = 2770 valid users = josh @sadmin
Setting browseable = no on the josh share hides it from the public share list while still allowing josh and sadmin to connect directly. Restart smbd and nmbd to apply the changes.
Connect from Linux using smbclient or by mounting the share with cifs-utils:
bashsmbclient //192.168.1.10/josh -U joshsudo mount -t cifs -o username=josh //192.168.1.10/josh /mnt/smbmount
Connect from macOS: Open Finder, go to Go > Connect To Server, and enter smb://server_ip/josh. Select Registered User and enter the credentials.
Connect from Windows: Open File Explorer, right-click This PC, select Add a network location, and enter \\server_ip\josh. Enter the Samba username and password when prompted.
Samba is now installed and serving files on your Ubuntu 18.04 server. Visit the Samba documentation to learn about Active Directory integration, printer sharing, and advanced access control. Leave a comment below if you run into any issues.