Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 8 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


    and ensure this is commented out:


    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 '14 at 8:14
I also have the same problem with Ubuntu 14.04 – torayeff Oct 17 '14 at 6:51
I have the same problem too! – Maximilian Mar 17 '15 at 16:13
How come at Step 9 you have chown root:root /var/www/site only to revert it back to sudo chown -R www-data:www-data /var/www/site at Step 10 is this deliberate? – JohnnyQ Jul 14 at 14:41

If you are getting connection refused error at end then make sure that "Subsystem sftp internal-sftp" is place after "UsePAM yes". If not then update and Restart ssh and it worked.

share|improve this answer

Your Answer


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.