How To

Install Samba on Ubuntu 18.04: Configure Shares and User Access

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>&nbsp;You need sudo access.

Install Samba on Ubuntu: Package Setup, UFW, and smb.conf

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

Create Samba Users, Set Permissions, and Configure Passwords

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.

Configure Samba Shares and Connect from Linux, macOS, and Windows

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.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

4 days ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

5 days ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

6 days ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 month ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago