I have a Ubuntu 14.04 server installed with open ssh. I'd like to configure sftp for customers to be able to download files only. In other words, I put files in a directory that they are jailed to. I need to make sure they can only access the directory with their file(s) and nothing else.

Originally I was going to use vsftpd, but someone told me that sftp is the better option. If there's some documentation on what I need that would be great.

I need help with the following:

  1. How to configure sftp
  2. How to set up user accounts and use them for sftp
  3. How to set accounts to jail

Settings for /etc/ssh/sshd_config

Subsystem sftp internal-sftp -f AUTH -l VERBOSE
UsePAM yes
Match group sftp
  ChrootDirectory %h
  ForceCommand internal-sftp
  AllowTcpForwarding no

create group sftp:

groupadd sftp

Create directory

sudo mkdir /ftpusers
sudo mkdir /ftpusers/HomeFolder

Create user directly with new sftp group attached:

sudo useradd -d /ftpusers/HomeFolder -m UserName -g sftp -s /bin/false
sudo passwd UserName

set permissions for use with ssh for sftp:

chown root:root /ftpusers/HomeFolder
chmod 755 /ftpusers/HomeFolder

restart service:

service ssh restart

Note, the home folder for the new sftp user has to be given root owner.

  • Thanks for the reply!! Not sure why, but when I try to create a user directly to the group. I'm getting the following error... useradd: cannot create directory /ftpusers/HomeFolder – scottsmail Mar 20 '15 at 13:51
  • Run first sudo mkdir /ftpusers, then sudo mkdir /ftpusers/HomeFolder – 2707974 Mar 20 '15 at 13:55
  • Thank you. Ok, next problem... When I try to set permissions for use with ssh for sftp with chown root:root HomeFolder I get chown: cannot access ‘HomeFolder’: No such file or directory – scottsmail Mar 20 '15 at 14:17
  • chown root:root /ftpusers/HomeFolder and chmod 755 /ftpusers/HomeFolder – 2707974 Mar 20 '15 at 14:35
  • UsePAM yes ruins everything for me and causes "connection refused". Not sure why, but commenting that line out makes everything work perfectly. – pzkpfw Mar 22 '16 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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