File storage sharing in the Linux world refers to the ability to share files and directories between multiple Linux systems or between Linux and other operating systems. It enables users to access and collaborate on files across a network, making it easier to share data and resources. Here are some key aspects
of file storage sharing in the Linux world:
- Network File Systems (NFS): NFS is a widely used file system protocol in Linux. It allows a system to export or share directories over a network, making them accessible to other systems as if they were local. NFS uses the client-server model, where an NFS server exports directories and clients mount them to access the shared files.
- Samba (SMB/CIFS): Samba is an open-source software suite that implements the SMB/CIFS protocol, which is used for file and printer sharing between Linux and Windows systems. Samba enables Linux systems to act as SMB/CIFS servers, allowing Windows clients to access shared directories and printers.
- File Transfer Protocols: Various file transfer protocols are used for sharing files in the Linux world. Some common protocols include FTP (File Transfer Protocol), FTPS (FTP over SSL/TLS), SFTP (SSH File Transfer Protocol), and SCP (Secure Copy). These protocols enable secure and efficient file transfers between systems.
- Web-based Sharing: Linux provides options for web-based file sharing using technologies like WebDAV (Web Distributed Authoring and Versioning). WebDAV extends the HTTP protocol, allowing users to remotely access, manage, and collaborate on files hosted on web servers.
- Peer-to-Peer (P2P) Sharing: P2P file sharing involves the direct sharing of files between individual systems without the need for a central server. Linux systems can utilize various P2P file-sharing applications, such as BitTorrent clients, to share files directly with other peers.
- Access Control and Security: File sharing in the Linux world includes features for access control and security. Permissions and ownership settings can be applied to shared files and directories to regulate who can read, write, or execute them. Additionally, encryption and authentication mechanisms can be implemented to ensure secure file transfers and protect sensitive data.
An NFS
(Network File System) server is a component in a networked environment that provides file-sharing services using the NFS protocol. It allows clients to access and mount remote directories as if they were local directories on their own systems. The NFS server hosts the shared directories and makes them available to authorized clients over the network.
Features & Benefits of NFS Server
- Security and Access Control: NFS offers security features for access control and data protection.Distributed File System: NFS enables the creation of a distributed file system, allowing files and directories to be shared across multiple systems on a network.
- Transparent Access: NFS provides transparent access to shared files and directories. Clients can mount remote NFS shares as if they were local directories, allowing users to interact with shared files seamlessly.
- Cross-Platform Compatibility: NFS is designed to work across different operating systems and platforms.
- Efficient Network File Access: NFS is optimized for efficient file access over a network. It employs caching mechanisms to reduce network overhead, minimizing the need for repeated file transfers and improving overall performance
- Security and Access Control: NFS offers security features for access control and data protection.
- File Locking: NFS supports file-locking mechanisms to ensure data consistency and prevent conflicts when multiple clients access the same file
- Integration with Existing Infrastructure: NFS seamlessly integrates with existing network infrastructure and services. It can utilize features like user authentication systems (e.g., LDAP or Kerberos) and work in conjunction with other network protocols and services.
- Ease of Administration: NFS servers are relatively easy to administer and configure. The server configuration file (
/etc/exports
) allows administrators to specify shared directories and access control settings. - Compatibility with Third-Party Tools: NFS is compatible with a wide range of third-party tools and utilities. Backup solutions, monitoring systems, and other file management tools can be used with NFS shares, allowing for integration into existing workflows and infrastructure.
How can I set up NFS file sharing on Debian 12? If you want to set up an NFS server on Debian 12, our guide today will walk you through the procedure step by step. We will look at how to install and configure NFS server on Debian 12, as well as how to configure NFS client to access the shared directory on the NFS server. We’ll start with an NFS server.
1. Prepare the system
Ensure that the system is up to date before beginning any installation.
sudo apt update
sudo apt upgrade -y
2. Install nfs-server packages
Run the below command to install nfs-server packages:
$ sudo apt install nfs-kernel-server rpcbind
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
keyutils libevent-core-2.1-7 libnfsidmap1 nfs-common python3-yaml
Suggested packages:
open-iscsi watchdog
The following NEW packages will be installed:
keyutils libevent-core-2.1-7 libnfsidmap1 nfs-common
nfs-kernel-server python3-yaml rpcbind
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 819 kB of archives.
After this operation, 3,187 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
3. Create a directory to share with clients
The directory that will be shared with and accessed by the client machines will be created in this phase.
sudo mkdir -p /mnt/nfs_share
We need to remove all permission constraints from the shared folder in order to allow client workstations to freely access it.
sudo chown -R nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
4. Configure the shared directory
Use your best editor to make changes to the configuration file /etc/exports
to set up the shared directory for nfs.
sudo vim /etc/exports
The shared directory, client network, and client permissions are all listed in this file. After you’ve opened the file, enter the following information:
/mnt/nfs_share 192.168.1.0/24(rw,sync,no_subtree_check)
192.168.1.0/24 means access is limited to systems in the network. For access from all networks you can use *
You must be aware of the following options to choose from:
- rw – enabling the disk or directory for both NFS server and client read and write access
- sync – only respond to queries after the modifications are saved to a reliable location. By default, this choice is active.
- no_subtree_check – disables subtree checking, which has few security repercussions but can occasionally increase dependability.
If you want to provide access to certain single servers, specify their IP addresses separately in the /etc/exports file:
/mnt/nfs_share client_ip_1(rw,sync,no_subtree_check)
/mnt/nfs_share client_ip_2(rw,sync,no_subtree_check)
Restart and enable nfs-server.
sudo systemctl restart nfs-server
sudo systemctl is-enabled nfs-server
Verify the status of nsf server.
$ systemctl status nfs-server
root@debian:~# systemctl status nfs-server
● nfs-server.service - NFS server and services
Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; preset: enabled)
Active: active (exited) since Sun 2025-01-19 01:47:07 EAT; 11s ago
Process: 4096 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Process: 4097 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
Main PID: 4097 (code=exited, status=0/SUCCESS)
CPU: 7ms
Jan 19 01:47:07 debian systemd[1]: Starting nfs-server.service - NFS server and services...
Jan 19 01:47:07 debian systemd[1]: Finished nfs-server.service - NFS server and services.
5. Export the shared directory
Once the client computers have been allowed access, export the NFS share directory and restart the NFS kernel server for the modifications to take effect.
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
6. Securing NFS Server with UFW Firewall
Installing the ufw
firewall and limiting access to the NFS server to particular hosts and networks only are what you will be doing at this point.
$ sudo apt install ufw
The following additional packages will be installed:
iptables libip6tc2
Suggested packages:
firewalld rsyslog
The following NEW packages will be installed:
iptables libip6tc2 ufw
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 548 kB of archives.
After this operation, 3,411 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Add SSH service to the ufw firewall rules.
ufw allow ssh
You must permit access through the firewall for the client to access the NFS share; otherwise, mounting the shared directory will not be feasible.
sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw enable
Verify its status.
$ ufw status
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
2049 ALLOW 192.168.1.0/24
22/tcp (v6) ALLOW Anywhere (v6)
7. Install NFS client on Client Machines
Using the apt command below, you will install the ‘nfs-common
‘ package and configure clients to access the shared directory and partition on the NFS server.
sudo apt update
sudo apt install nfs-common
If you got any prompt press yes and proceed. We’ll make a directory in which we’ll mount the NFS share from the NFS server.
sudo mkdir -p /mnt/nfs_clientshare
Let us proceed to mount the NFS share on the newly established directory.
sudo mount <nfs-server-ip>:/mnt/nfs_share /mnt/nfs_clientshare
To see if the NFS share is working on the client, we’ll write to the server’s shared directory and see if we can access the same files from the client. Create the following text files on the NFS server:
cd /mnt/nfs_share
touch file1
Check whether the files exist on the nfs client.
$ ls -l /mnt/nfs_clientshare
total 0
-rw-r--r-- 1 root root 0 Jan 18 22:59 file1.txt
$ cat /mnt/nfs_clientshare/file1.txt
Hello there!! This is an NFS share, if you can read this file, the NFS server has been installed successfully!!
8. Mount NFS on boot
We will discover how to set up the /etc/fstab
configuration to mount the NFS directory or partition upon system boot or startup. Open /etc/fstab add the below lines and input your own IP addresses for the details, shared directory, and path mount directory.
$ sudo vim /etc/fstab
192.168.1.180:/mnt/nfs_share /mnt/nfs_clientshare nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
Check if the /etc/fstab is successful by executing the commands below. Ensure that you don’t have any errors.
sudo umount -R /mnt/nfs_clientshare
To mount every file system on the ‘/etc/fstab’ configuration file, run the command below.
sudo mount -a
The next command should be run to display all mounted file systems.
$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 593M 1.2M 592M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 19G 6.6G 12G 38% /
tmpfs tmpfs 2.9G 0 2.9G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/vda2 ext4 2.0G 95M 1.7G 6% /boot
tmpfs tmpfs 593M 16K 593M 1% /run/user/0
192.168.1.180:/mnt/nfs_share nfs4 39G 5.4G 31G 15% /mnt/nfs_clientshare
Verdict
Bingo! You have successfully installed and set up an NFS server and client on Debian 12 (Bookworm). I hope you found the guide’s content helpful.
More guides to check: