Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
how about you symlink /home/user to the target? –  izx May 29 '12 at 14:39

1 Answer 1

up vote 7 down vote accepted

This is the process:

  1. Add the user: sudo adduser <username> www-data as per this answer

  2. Add the user to the group: sudo usermod -aG www blub

    or just use sudo adduser <username> www-data in 1

  3. Install vsftpd sudo apt-get install vsftpd

  4. Configure vsftpd for remote access:

    nano /etc/vsftpd.conf

    inside the file set

    chroot_local_user=YES

    and ensure this is commented out:

    #chroot_list_enable=YES

    as per doco.

  5. Restart nsftp: sudo /etc/init.d/vsftpd restart

  6. Configure the user's home directory:

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

    ie not in \home

  7. Configure ssh chroot

    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

  8. Restart ssh

    /etc/init.d/ssh restart

  9. 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.

  10. Ensure that your directory has www-data access

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

    chmod 755 /var/www/site

share|improve this answer
    
Please accept your own answer :) Thanks for the research. –  izx May 30 '12 at 22:55
    
I have followed these instruction, but I got connection refused at end when I add these lines Subsystem sftp internal-sftp Match user <username> ChrootDirectory /var/www/site ForceCommand internal-sftp AllowTcpForwarding no –  Ata Jun 12 at 8:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.