Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 90082  / 3 Years ago, tue, june 8, 2021, 12:36:14

I've created a user and made his home directory /var/www/mysite/ftpdir



I've also added a Match user entry for this user in sshd_config with a ChrootDirectory that points to /var/www/mysite



I've restarted ssh to pick this up.



When I log in with sftp - the user still goes to the user's old directory ie /home/user



What am I missing?


More From » users

 Answers
1

This is the process:




  1. Add the user to the group: sudo usermod -aG www blub as in Whats the simplest way to edit and add files to "/var/www"?



    or just use sudo adduser <username> www-data


  2. Install vsftpd sudo apt-get install vsftpd

  3. Configure vsftpd for remote access: sudo nano /etc/vsftpd.conf and inside the file set



    chroot_local_user=YES


    and ensure this is commented out:



    #chroot_list_enable=YES


    as per documentation.


  4. Restart nsftp: sudo service vsftpd restart

  5. Configure the user's home directory to the web directory (not in /home):



    sudo usermod -d /var/www/mysite/ftpaccessdir <username>

  6. Configure ssh chroot



    sudo nano /etc/ssh/sshd_config


    add the following to the end:



    Subsystem  sftp  internal-sftp
    Match user <username>
    ChrootDirectory /var/www/site
    ForceCommand internal-sftp
    AllowTcpForwarding no


    and ensure that further up in the file that this is commented out (ie before the one you just added)



    #Subsystem sftp /usr/lib/openssh/sftp-server

  7. Restart ssh



    sudo service ssh restart

  8. Change the permissions for apache:



    chown root:root /var/www
    chown root:root /var/www/site
    chmod 755 /var/www


    As in the docs here.


  9. Ensure that your directory has www-data access



    sudo chown -R www-data:www-data /var/www/site
    chmod 755 /var/www/site


[#38031] Tuesday, June 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pipeag

Total Points: 489
Total Questions: 107
Total Answers: 115

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;