What if you have two Linux computers at your house. What if you need to transfer files back and forth between those two computers frequently.
Well, you have some options. You could use scp or sftp. But typing in passwords and paths every time you want to copy a file in a little bit of a hassle. What do we do? What if I could see the drive on computer1 on computer2 just like it was a mounted file system. Wouldn't that be handy?
For the sake of this tutorial, I will call the computer doing the sharing the NFS server, and the remote computer the NFS client.
You could actually make both of them servers, and both of them clients, but I rarely find the need to do that. The gotcha here is that
both computers have to be on the same local network. (There are ways around this with VPNs but that's another subject).
First, we need to install some packages. (if they aren't already installed). Both computers do not have to be the same distro.
You can mount Debian shares on Fedora, and you can mount Rocky shares on Ubuntu.
Deb/Apt based systems.
Server:
Client:
Rpm/Dnf based systems.
Server:
Client:
Pacman based systems.
Server:
Client:
Now we need to create a directory to export. This could really be almost any directory, but I do not recommend sharing your home
directory. I know people who do... but... anyway. It's best if "nobody" owns the shared filesystem.
Server:
We also need to create an exports file. The file may already be there, but you need to edit it if it is.
For the shared directory above it would look like this. Change the IP address to the address of the client you to share to.
Server:
Once that is done, we need to initialize the service.
Server:
Now on the client, we need to create a mount point to mount the shared drive to. This is really just a directory.
It could be anywhere, but the Linux convention is to put mounted drives under "/mnt".
Client:
Now we simply mount the shared drive. Change the IP address to the IP address of your NFS server.
Client:
Assuming all of that works, we can make this permanent by adding the share to our fstab. That way it gets automatically mounted
if I reboot the computer. Add this line to your /etc/fstab file.
Client:
There you go. Let me know if there any questions.
Well, you have some options. You could use scp or sftp. But typing in passwords and paths every time you want to copy a file in a little bit of a hassle. What do we do? What if I could see the drive on computer1 on computer2 just like it was a mounted file system. Wouldn't that be handy?
For the sake of this tutorial, I will call the computer doing the sharing the NFS server, and the remote computer the NFS client.
You could actually make both of them servers, and both of them clients, but I rarely find the need to do that. The gotcha here is that
both computers have to be on the same local network. (There are ways around this with VPNs but that's another subject).
First, we need to install some packages. (if they aren't already installed). Both computers do not have to be the same distro.
You can mount Debian shares on Fedora, and you can mount Rocky shares on Ubuntu.
Deb/Apt based systems.
Server:
Code:
sudo apt update
sudo apt install nfs-kernel-server
Client:
Code:
sudo apt update
sudo apt install nfs-common
Rpm/Dnf based systems.
Server:
Code:
sudo dnf install nfs-utils
Client:
Code:
sudo dnf install nfs-utils
Pacman based systems.
Server:
Code:
sudo pacman -S nfs-utils
Client:
Code:
sudo pacman -S nfs-utils
Now we need to create a directory to export. This could really be almost any directory, but I do not recommend sharing your home
directory. I know people who do... but... anyway. It's best if "nobody" owns the shared filesystem.
Server:
Code:
sudo mkdir -p /srv/nfs/share
sudo chown nobody:nogroup /srv/nfs/share
We also need to create an exports file. The file may already be there, but you need to edit it if it is.
For the shared directory above it would look like this. Change the IP address to the address of the client you to share to.
Server:
Code:
/srv/nfs/share 192.168.3.14(rw,sync,no_subtree_check)
Once that is done, we need to initialize the service.
Server:
Code:
sudo exportfs -a
sudo systemctl restart nfs-server
Now on the client, we need to create a mount point to mount the shared drive to. This is really just a directory.
It could be anywhere, but the Linux convention is to put mounted drives under "/mnt".
Client:
Code:
sudo mkdir -p /mnt/nfs/share
Now we simply mount the shared drive. Change the IP address to the IP address of your NFS server.
Client:
Code:
sudo mount 192.168.3.44:/srv/nfs/share /mnt/nfs/share
Assuming all of that works, we can make this permanent by adding the share to our fstab. That way it gets automatically mounted
if I reboot the computer. Add this line to your /etc/fstab file.
Client:
Code:
192.168.3.44:/srv/nfs/share /mnt/nfs/share nfs defaults 0 0
There you go. Let me know if there any questions.
Last edited: