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 22.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_userName]
path = /home/userName/
comment = Personal Files
writeable = yes
create mask = 0777
directory mask = 0777
browseable = yes
public = yes
valid users = userName

Customize this command to meet your network:

[Home_userName] The name of the share will be ‘Home_userName
path = /home/userName/ 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 = userName Allows user ‘userName‘ 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.

adduser -s /usr/sbin/nologin userName
sudo smbpasswd -a userName
sudo smbpasswd -e userName

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

Test connectivity and authentication:

smbclient -U userName -L \\\\192.168.2.40
smbclient -U userName \\\\192.168.2.103\\Home_userName

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

sudo mount -t cifs -o username=userName //192.168.2.40/Home_userName /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=userName Specifies what user you want to login as ‘userName‘.
//192.168.2.40/ The address of the server.
Home_userName 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_userName /tmp/HU cifs username=userName,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_userName Share name.
/tmp/HU Local mounting point.
cifs Informs to the command mount the type ‘cifs‘, the protocol used by Samba.
username=userName Defines each user you want to login ‘userName‘.
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, 20.04, 22.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