To configure a user for uploading files via sftp on an NFS server, follow these steps:
- Set file permissions in the NFS directory
Set file permissions in the NFS directory by editing the /etc/exports file.
/data 192.168.1.0/24(rw,no_root_squash,sync,anonuid=1000,anongid=1000)
In the /etc/exports file, each line specifies the following information:
/datais the directory you want to make available via NFS192.168.1.0/24is the network that is allowed to access the NFS serverrw,no_root_squash,sync,anonuid=1000,anongid=1000are the NFS server configuration options
The NFS server configuration options are as follows:
rwallows read and write access to filesno_root_squashallows root users on client machines to access files on the NFS serversyncforces the NFS server to sync files with client machines immediatelyanonuid=1000assigns the UID of 1000 to anonymous users on client machinesanongid=1000assigns the GID of 1000 to anonymous users on client machines
- Create a user
Create a user by running the following command:
useradd -d /home/user -m user
In this command:
useraddis the command for creating a user-dis the option for specifying the user’s home directory-mis the option for creating the user’s home directory. If not specified, an empty directory will be created.
- Set a password for the user
Set a password for the user by running the following command:
passwd user
- Set file permissions
Set file permissions by editing the /etc/passwd file.
user:x:1000:1000:user:/home/user:/bin/bash
In the /etc/passwd file, each line specifies the following information:
useris the user namexis the password (if you want to hide the password, enter!instead)1000is the UID1000is the GIDuseris the home directory name/bin/bashis the default shell
After completing these steps, the user will be able to upload files via sftp to the NFS directory.
Example
Suppose you have a user named user and a directory named /data that you want the user user to be able to upload files to.
You can set file permissions as follows:
chown user:user /data
After that, the user user will be able to upload files to the directory /data.
If you want to set file permissions for specific files or subdirectories, use the chmod command instead of chown.
In addition, you can also set file permissions for specific users on client machines by editing the /etc/exports file as follows:
/data 192.168.1.0/24(rw,no_root_squash,sync,anonuid=1000,anongid=1000,user=user)
In each line of the /etc/exports file:
useris the name of the user who is allowed to access the files
If you want to set file permissions for multiple users, you can separate the user names with commas, as follows:
/data 192.168.1.0/24(rw,no_root_squash,sync,anonuid=1000,anongid=1000,user=user1,user2)