<\/span><\/h2>\n\n\n\nFirst of all, we need to log in to our VPS through SSH:<\/p>\n\n\n\n
ssh master@IP_Address -p Port_number<\/pre>\n\n\n\nReplace “master” with a user that has sudo privileges or root if necessary. Additionally, replace \u201cIP_Address\u201d and \u201cPort_Number\u201d with your server\u2019s respective IP address and SSH port number.<\/p>\n\n\n\n
Next, we are going to update our server that will act as the NFS server. Let’s execute the command below to update it. Make sure you run the command that suits your operating system.<\/p>\n\n\n\n
Ubuntu\/Debian<\/strong><\/p>\n\n\n\n$ sudo apt update<\/pre>\n\n\n\nCentOS\/AlmaLinux\/RockyLinux<\/strong><\/p>\n\n\n\n$ sudo dnf update<\/pre>\n\n\n\nThat’s it, the package index on your Linux machine has been updated. We can proceed to the next step now.<\/p>\n\n\n\n
<\/span>Step 2. Install NFS Server<\/span><\/h2>\n\n\n\nThe NFS package is available on all of the most common Linux distributions. We just need to install it from the existing repository, simply run the command below.<\/p>\n\n\n\n
Ubuntu\/Debian<\/strong><\/p>\n\n\n\n$ sudo apt install nfs-kernel-server<\/pre>\n\n\n\nCentOS\/AlmaLinux\/RockyLinux<\/strong><\/p>\n\n\n\n$ sudo dnf install nfs-utils<\/pre>\n\n\n\nAt this point, the NFS server has been installed. On Ubuntu\/Debian, the service was already set to active, but that is not the case on CentOS\/AlmaLinux\/RockyLinux. So, if you are using CentOS\/AlmaLinux\/RockyLinux as your NFS server, we can run this command:<\/p>\n\n\n\n
$ sudo systemctl enable nfs-server<\/pre>\n\n\n\n<\/span>Step 3. Configure NFS Server<\/span><\/h2>\n\n\n\nIn this step, we are going to create a directory to share with other users in the same local network. Then, we need to edit the exports<\/code> file to be able to run the NFS server.<\/p>\n\n\n\nIn this case, we’re sharing the folder \/mnt\/shared<\/code> – you can change this to any folder you want.<\/p>\n\n\n\nUbuntu\/Debian<\/strong><\/p>\n\n\n\n$ sudo mkdir \/mnt\/shared\n$ sudo chown nobody:nogroup \/mnt\/shared\n$ sudo chmod 777 \/mnt\/shared<\/pre>\n\n\n\nCentOS\/AlmaLinux\/RockyLinux<\/strong><\/p>\n\n\n\n$ sudo mkdir \/mnt\/shared\n$ sudo chown nobody:nobody \/mnt\/shared\n$ sudo chmod 777 \/mnt\/shared<\/pre>\n\n\n\nAfter creating the directory to share and correcting its permissions, we can edit the \/etc\/exports<\/code> file.<\/p>\n\n\n\n$ sudo nano \/etc\/exports<\/pre>\n\n\n\nInsert this line into the file to share the folder \/mnt\/shared<\/code> to the network 192.168.53.0<\/code> with a subnet mask of \/24<\/code> or 255.255.255.0<\/code>:<\/p>\n\n\n\n\/mnt\/shared 192.168.53.0\/255.255.255.0(rw,sync,no_subtree_check)<\/pre>\n\n\n\nMake sure to replace 192.168.53.0\/255.255.255.0<\/code> with your subnet IP and subnet mask.<\/p>\n\n\n\nSave the file then exit from the editor. Please note that with the line above, you are allowing all computers on the same network to access \/mnt\/shared<\/code>. If you want to share the NFS server only with a single IP address, you can use this line instead and replace 192.168.53.111 with your NFS client’s IP address:<\/p>\n\n\n\n\/mnt\/shared 192.168.53.111(rw,sync,no_subtree_check)<\/pre>\n\n\n\nEvery time you make changes to \/etc\/exports<\/code> file, you need to run this command below to apply the changes:<\/p>\n\n\n\n$ sudo exportfs -a<\/pre>\n\n\n\nNow that we installed everything, we can connect to the NFS server.<\/p>\n\n\n\n