Installing Samba on Ubuntu 21.04

To install Samba, we run:

sudo apt update
sudo apt install samba

We can check if the installation was successful by running:

whereis samba

The following should be its output:

samba: /usr/sbin/samba /usr/lib/x86_64-linux-gnu/samba /etc/samba /usr/share/samba /usr/share/man/man8/samba.8.gz /usr/share/man/man7/samba.7.gz

Setting up Samba

Now that Samba is installed, we need to create a use and directory for it to share:
Add a user

# adduser roger
Adding user `roger' ...
Adding new group `roger' (1000) ...
Adding new user `roger' (1000) with group `roger' ...
Creating home directory `/home/roger' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for roger
Enter the new value, or press ENTER for the default
        Full Name []: Roger
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

Add a directory to share (replace your username here).

mkdir /home/roger/sambashare/

The command above creates a new folder sambashare in our home directory which we will share later.

The configuration file for Samba is located at /etc/samba/smb.conf. To add the new directory as a share, we edit the file. Lets backup first.

cp /etc/samba/smb.conf /etc/samba/smb.conf-bk
sudo nano /etc/samba/smb.conf

Workgroup- make sure Workgroup is the same for your Windows box.

workgroup = WORKGROUP

At the bottom of the file, add the following lines:

[sambashare]
    comment = Samba on Ubuntu
    path = /home/username/sambashare
    read only = no
    browsable = yes

Then press Ctrl-O to save and Ctrl-X to exit from the nano text editor.
What we’ve just added

comment: A brief description of the share.

path: The directory of our share.

read only: Permission to modify the contents of the share folder is only granted when the value of this directive is no.

browsable: When set to yes, file managers such as Ubuntu’s default file manager will list this share under “Network” (it could also appear as browseable).

Now that we have our new share configured, save it and restart Samba for it to take effect:

sudo service smbd restart

Update the firewall rules to allow Samba traffic:

sudo ufw allow samba

Setting up User Accounts and Connecting to Share

Since Samba doesn’t use the system account password, we need to set up a Samba password for our user account:

sudo smbpasswd -a username

Note
Username used must belong to a system account, else it won’t save.
Connecting to Share

On Ubuntu: Open up the default file manager and click Connect to Server then enter:

smb://ip-address/sambashare

On Windows, open up File Manager and edit the file path to:

\\ip-address\sambashare

Note: ip-address is the Samba server IP address and sambashare is the name of the share.

You’ll be prompted for your credentials. Enter them to connect!

Excellent Article here: https://tecadmin.net/mounting-samba-share-on-ubuntu/

Leave a Comment