Enabling Remote File Sharing with NFS and Samba

Tutu Godfrey Oritseshutieyimi
3 min readOct 30, 2020

File sharing allows users on different work stations to gain access to common resources such as files and other data stored in a common location in a remote server. Linux provides two technologies to enable remote file sharing which are NFS and Samba. NFS is a Unix to Unix file sharing solution, whereas Samba is a technology originally introduced by Microsoft and provides a way for enabling file sharing with Windows machine. In this post, I will demonstrate how to enable file sharing using both methods to allow access to directories. I will be using NFS to share the directory /developers amongst developers and Samba to share the directory /admin amongst administrative staff. Let get started.

To enable file sharing with NFS we need to have the required utilities enabled. Use. yum install nfs-utils to install the NFS the service utility. On an Ubuntu system that will be apt install nfs-server-utils Once installed check the status of the NFS service and enable it. systemctl status nfs to check if the service is running. Use systemctl enabling --now nfs to enable the service if not already enabled and systemctl start nfs to start the service if necessary. Now we need to create the directory we which to share mkdir /developers will get us there. To configure NFS sharing you need to open and edit the /etc/exports on the client machine. vim /etc/exports and the following lines /developers * (rw,no_root_squash) In this case, we are sharing with all hosts on the network. If you will rather share among specific hosts, the configuration will look sometime like /developers host1 host2 host2 (rw,no_root_squash) host1 for example is the IP address or hostname of the remote machine. Save the file and restart the NFS service once again. systemctl restart nfs and systemctl status nfs verify that the service is active. To confirm that the share directory is been share use the show mount command showmount -e localhost and confirm that the shared directory is listed. Once that is set, we can start configuring the host machines.

On the host machine verify the share is working by running the showmount command showmount -e client-hostname and confirm that the shared directory is listed. If so, we can mount the share persistently on the host using the /etc/fstab file. Open the file and edit as follow vim /etc/fstab add the following lines clienthostname:/developers /developers nfs _netdev 0 0 Here we are mapping on the client to /developers on the host machine using the nfs protocol. _netdev is a specifying dependency on the network. Create the local /developers directory and mount the share. mkdir /developers to create the directory and mount -a to mount. Confirm that the mount was successful by running the command mount | grep nfs and you should see the nfs mounted share listed. We are all set! Create a file in the /developers directory either from the client or from the host and confirm that it can be accessed from the machine where mounts have been enabled.

Let now configure the share for the /admin directory using Samba. To start we need to make sure Samba is installed. yum install samba should do that for us. Next, we need to configure the share. Open vim /etc/samba/smb.conf and add the following configuration. It is important to note that the user must exist as a user in your Linux system.

[admin]
comment = /admin
path = /admin
browseable = yes
writable = yes
valid users = @admin

Create the shared directory mkdir /admin and start the Samba service systemctl enable --now smb or systemctl restart smb if it was already running. Very the share is enabled by running the command smbclient -L host_ip If all is good we can move on to configuring the host.

On the host machine installed the required utilities yum install cifs-utils samba-client. Test the share by running samba-client -L clienthostname or ip Once we confirm that the share is visible on the host we can move on to mounting the directory. Let create the directory. mkdir /admin. Next, we mount the directory. Open vim /etc/fstab and add the line. //hostname/admin /admin cifs _netdev 0 0. Persist the mount mount -a. Now you can create files in the /admin directory from either the host or the client and expect to get it from the other end.

We have succeeded in enabling file sharing between our remote machines, which is the purpose of this article. I hope you have enjoyed reading the article and I hope that the content helps in your use case. If so, please like and share and expect more articles from this space, thanks.

--

--

Tutu Godfrey Oritseshutieyimi

I am a Fullstack Software engineer with commitment to delivering great products. Enthusiastic about DevOps and Linux system administration