1

I want to create users for sftp with limited access to specific folders

My folder structure looks like this:

/var/www/site1/files/

/var/www/site2/files/

/var/www/site3/files/

I want to create sftp user1 to access /var/www/site1/files/ only to upload website files using filezila and cannot view any other folders

and likewise for user2 with limited access to /var/www/site2/files/

and for user3 with limited access to /var/www/site3/files/

0

2 Answers 2

1

You have pretty much followed the thing.
The best way is to do this:

  1. Mount each of the 3 directories to /home directories by appending the following lines in /etc/fstab:

    /var/www/site1/files/ /home/site1/htdocs/ bind 0 0
    /var/www/site2/files/ /home/site2/htdocs/ bind 0 0
    /var/www/site3/files/ /home/site3/htdocs/ bind 0 0
    
  2. Use mount -a to instantly initiate the mounts.

  3. Make sure you have added the users site1, site2, site3 to same group (eg. sftpusers or sftponly). You can use these commands to add the users to groups:

    usermod -aG sftponly site1
    usermod -aG sftponly site2
    usermod -aG sftponly site3
    
  4. Make the /home/{site1,site2,site3} home directories for corresponding users using:

    usermod -d /home/site1 site1
    usermod -d /home/site2 site2
    usermod -d /home/site3 site3
    
  5. Append the following in your /etc/ssh/sshd_config:

    Match group sftponly
          ChrootDirectory %h
          X11Forwarding no
          AllowTcpForwarding no
    
  6. Finally restart the ssh service using:

    service ssh restart
    

See this post on Digital Ocean for details.

5
  • many thanks for your response i make this steps but it not work with me could you explain the steps with commands
    – Ahmed
    Mar 26, 2018 at 10:45
  • i got this error in filezilla Error: Server unexpectedly closed network connection Error: Could not connect to server
    – Ahmed
    Mar 26, 2018 at 20:33
  • are you sure you added the ssh-public key in /home/site1/.ssh/authorized_keys Mar 27, 2018 at 3:20
  • could you explain the steps from a to z how to create a sftp user can upload and to the www folder using filezilla
    – Ahmed
    Mar 27, 2018 at 22:21
  • i can't solve this issue
    – Ahmed
    Mar 29, 2018 at 7:35
0

After following krishna chalise's answer you may need to adjust ownership and permissions.

For example, for user site1:

chown root:root /home/site1
chmod 755 /home/site1
cd /home/site1
chown site1:sftponly

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .