Setting up Samba shares on an Ubuntu server allows you to share files and directories with other computers on your network, including Windows and Linux systems. Here's a step-by-step guide:

1. Install Samba

First, install the Samba package if it's not already installed.

sudo apt update
sudo apt install samba -y

2. Create a Directory to Share

Create a directory that you want to share.

sudo mkdir -p /srv/samba/share

Set permissions for the directory:

sudo chmod 777 /srv/samba/share
sudo chown your_user:your_user /srv/samba/share

Replace your_user with the username you want to have ownership of the directory.

3. Configure Samba

Edit the Samba configuration file.

sudo vim /etc/samba/smb.conf

Add a section at the bottom of the file to define the share:

[Public]
path = /srv/samba/share
browseable = yes
writable = yes
guest ok = yes
read only = no
Info

The name mentioned in the square brackets will be broadcasted as the share name. Changed it to your liking, for example, Photos

[Private]
path = /srv/samba/share
browseable = yes
writable = yes
valid users = your_user
read only = no

Save and exit the file.

4. Create a Samba User (For Private Share)

If you are setting up a private share, add the user to Samba and set a password.

sudo smbpasswd -a your_user
sudo smbpasswd -e your_user

Replace your_user with the desired username.

Info

You need to create a UNIX user named your_user before you create a samba user named your_user. To create a UNIX user, use the adduser command.

5. Restart Samba Services

Restart Samba to apply the changes.

sudo systemctl restart smbd
sudo systemctl restart nmbd

Enable Samba to start on boot:

sudo systemctl enable smbd
sudo systemctl enable nmbd

6. Allow Samba Through Firewall (Optional)

If you have a firewall enabled, allow Samba traffic:

sudo ufw allow samba

7. Access the Share

smbclient //server_ip_or_hostname/Public
\\server_ip_or_hostname\Public

Replace server_ip_or_hostname with the actual IP address or hostname of the server.

smb://server_ip_or_hostname/Public