The decision of using NFS or Samba only depends on who you are sharing with. Linux can communicate with NFS and SAMBA, but Windows can communicate only with SAMBA.

To learn about NFS file-sharing read the following post: NFS Server and Client on Ubuntu 20.04 [Link].


SERVER – SAMBA CONFIG

sudo apt update
sudo apt install samba -y
sudo ufw allow samba
sudo nano /etc/samba/smb.conf

The configuration file of Samba is like a manual, self-explanatory. There are parameters set and others are commented (with the symbol ‘;‘ in the beginning), which means it is not being used.

The Samba configuration is done in blocks. Add this block at the end of the file:

[Home_Ubuntu]
path = /home/ubuntu/
comment = Personal Files
writeable = yes
create mask = 0777
directory mask = 0777
browseable = yes
public = yes
valid users = ubuntu

Customize this command to meet your network:

[Home_Ubuntu] The name of the share will be ‘Home_Ubuntu’
path = /home/ubuntu/ The directory being shared.
comment = Personal Files ‘Personal Files’ is just a description.
writeable = yes Allow the client to write.
create mask = 0777 Will apply this mask when one file is created.
directory mask = 0777 Will apply this mask when one directory is created.
browseable = yes Make it visible while browsing.
public = no Denny any guest user.
valid users = ubuntu Allows user ‘ubuntu‘ to access the share.

The syntax of the parameters may differ depending on the version of the Samba Server. Always follow the instructions and examples in it or check the manual:

man smb.conf

At this point is necessary to set a password to the user and enable it, even if the user already has one password in the local system. Samba manages passwords separately.

sudo smbpasswd -a ubuntu
sudo smbpasswd -e ubuntu

After editing the configuration file, restart the service and check if it is running:

sudo systemctl restart smbd
sudo systemctl status smbd

OR

sudo service smbd restart
sudo service smbd status


CLIENT – SAMBA MOUNT

sudo apt update
sudo apt install cifs-utils -y

To eventually mount one remote share in the local file system issue:

sudo mount -t cifs -o username=ubuntu //192.168.2.40/Home_Ubuntu /tmp/hu

Customize this command to meet your network:

-t cifs Informs to the command mount the type ‘cifs’, the protocol used by Samba.
-o username=ubuntu Specifies what user you want to login as ‘ubuntu‘.
//192.168.2.40/ The address of the server.
Home_Ubuntu Share name.
/tmp/HU Local mounting point.

The directory ‘/tmp/HU‘ has to exist in the local file system. If it does not exist issue:

sudo mkdir /tmp/HU
sudo chmos 755 /tmp/HU

To make it automatically mount on the boot:

sudo nano /etc/fstab

Add this line at the end of the file:

//192.168.2.40/Home_Ubuntu /tmp/HU cifs username=ubuntu,password=pass,iocharset=utf8,file_mode=0777,dir_mode=0777

Customize this command to meet your network:

//192.168.2.40/ IP address of the server.
Home_Ubuntu Share name.
/tmp/HU Local mounting point.
cifs Informs to the command mount the type ‘cifs‘, the protocol used by Samba.
username=ubuntu Defines each user you want to login ‘ubuntu‘.
password=pass Informs the password ‘pass
iocharset=utf8,
sec=ntlm 0 0
Keep these arguments as they are.

This exercise was created and tested on Ubuntu 18.04 and Raspbian Buster 10, except for the firewall command that does not work on Raspbian everything else is the same, and everything works anyway.

To “refresh” and apply the new lines you added to the fstab:

sudo mount -a

One Reply to “SAMBA Server and Client on Ubuntu 20.04”

Comments are closed.