NFS (Network File System) is a protocol that allows you to share files and directories between multiple computers over a network. By default, NFS only allows the root user to have read and write access to shared files and directories. However, there may be cases where you want to give access to other users without granting them root privileges. In this article, we will guide you through the process of giving read and write access to other users on NFS without root privileges.
Step 1: Setting up NFS Server
Before we can grant access to other users, we need to set up the NFS server. Here are the steps to follow:
- Install the necessary packages:
sudo apt-get install nfs-kernel-server - Create a directory to be shared:
sudo mkdir /shared_directory - Edit the exports file:
sudo nano /etc/exports - Add the following line to the exports file:
/shared_directory *(rw,sync,no_root_squash,no_subtree_check) - Save and exit the file
- Restart the NFS server:
sudo systemctl restart nfs-kernel-server
Step 2: Granting Access to Other Users
Now that the NFS server is set up, we can proceed to grant access to other users without root privileges. Follow these steps:
- Create a user on the NFS server:
sudo adduser username - Assign a password to the user:
sudo passwd username - Edit the exports file:
sudo nano /etc/exports - Add the following line to the exports file, replacing "username" with the actual username:
/shared_directory *(rw,sync,no_subtree_check,all_squash,anonuid=1000,anongid=1000) - Save and exit the file
- Restart the NFS server:
sudo systemctl restart nfs-kernel-server
Now, the user "username" will have read and write access to the shared directory without requiring root privileges.
Step 3: Mounting the NFS Share on Client
To access the shared directory on a client machine, you need to mount the NFS share. Follow these steps:
- Install the necessary packages:
sudo apt-get install nfs-common - Create a directory to mount the share:
sudo mkdir /mnt/shared_directory - Mount the NFS share:
sudo mount nfs_server_ip:/shared_directory /mnt/shared_directory
Replace "nfs_server_ip" with the IP address of the NFS server. Now, you can access the shared directory on the client machine at /mnt/shared_directory.
Conclusion
In this article, we have learned how to give read and write access to other users on NFS without root privileges. By following the steps outlined, you can easily set up the NFS server, grant access to other users, and mount the NFS share on client machines. This allows for seamless file sharing and collaboration across multiple computers on a network.
References
| Source | Link |
|---|---|
| NFS - ArchWiki | https://wiki.archlinux.org/title/NFS |
| How to Set Up an NFS Mount on Ubuntu 20.04 | https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-ubuntu-20-04 |