Data Codes through Eyeglasses

To configure a user for uploading files via sftp on an NFS server, follow these steps:

  1. 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:

  • /data is the directory you want to make available via NFS
  • 192.168.1.0/24 is the network that is allowed to access the NFS server
  • rw,no_root_squash,sync,anonuid=1000,anongid=1000 are the NFS server configuration options

The NFS server configuration options are as follows:

  • rw allows read and write access to files
  • no_root_squash allows root users on client machines to access files on the NFS server
  • sync forces the NFS server to sync files with client machines immediately
  • anonuid=1000 assigns the UID of 1000 to anonymous users on client machines
  • anongid=1000 assigns the GID of 1000 to anonymous users on client machines
  1. Create a user

Create a user by running the following command:

useradd -d /home/user -m user

In this command:

  • useradd is the command for creating a user
  • -d is the option for specifying the user’s home directory
  • -m is the option for creating the user’s home directory. If not specified, an empty directory will be created.
  1. Set a password for the user

Set a password for the user by running the following command:

passwd user
  1. 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:

  • user is the user name
  • x is the password (if you want to hide the password, enter ! instead)
  • 1000 is the UID
  • 1000 is the GID
  • user is the home directory name
  • /bin/bash is 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:

  • user is 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)