Samba

What is Samba

What is Samba

Samba is standard Window interoperability (Able to exchange and communication information) with Unix-like system.

Samba provides file services through

  1. CIFS (Common Internet File System): This is obsolete dialect of the SMB protocol
  2. SMB (Server Message Block): More recent and up to date

Both are Window's file sharing protocol for storage system like network-attached system. This basically means that you can run a NAS on Unix like system and by using Samba, Window OS can also access the NAS through Samba.

Samba File Server

You can configure a Samba File Server to enable file sharing across different operating system over network, hence network attached storage. To set up a Samba File Server on Ubuntu follow the guide below:

1. Install Samba

sudo apt update
sudo apt install samba

2. Create a sample directory to share

This directory can be a storage that's mounted through different drive that have Raid set up, it doesn't matter, ultimately at the end of the day, you will just be sharing a directory to those that want to access the files.

mkdir /data

Let's say we want to share the /data file that we have just created, after getting Samba file server installed and ensuring that it is up and running through sudo systemctl status smbd we will need to configure the samba file server to serve this particular directory.

3. Editing samba config file to share the directory

This can be done by editing /etc/samba/smb.conf file and appending at the end of the file

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

Finally, after you make the change you will need to restart the samba file server through

sudo service smbd restart

4. Adding user to access the file

Because Samba doesn't use the system account password (whatever username and password that you have set up for Ubuntu), you will need to setup a separate password for the user account which the other host that want to access the file need to use in order to access the files.

Even though it doesn't use the system account, the account that you will be creating with samba will need to exist, otherwise it will not save

sudo smbpasswd -a <username>

Running the command above will prompt you entering a password for the username that you have provided

You can also find the list of users that you have created by running

sudo pdbedit -L -v

5. Connecting to share

Now in order to see the file directory that is shared through Samba, on Ubuntu you can open up a default file manager and click Connect to Server then enter in:

smb://ip-address/sambashare

This is the same for macOS

On Windows you will have to open up file manager and edit the file path to simply

\\ip-address\sambashare

 

You will be prompted to enter in the username and the password that you have created.

Restricting file access

To restrict a file access in Samba to only a set of users that you have specified that you configure you smb.conf as such:

[special]
    path = /home/special
    read only = no
    writeable = yes
    browseable = yes
    valid users = user1, user2, user3

Disable These Files Might be Harmful for your Computer Warning

Windows

On windows if you connect to the network drive, and tries to right click files, you might get these nasty warnings every single time you right click the file.

image.png

To solve this issue you would need to trust the IP address of the network drive on your computer.

  1. Open up control panel 
  2. Click on Network and Internet
  3. Click on Internet Options and click on Security tab
  4. Then click on Local intranet and click on Sites
  5. Click on Advanced and finally enter in the IP address of the network drive

Wa-la you should no longer seeing these errors after right clicking the files.