1

I'm creating an FTP user on Linux Ubuntu Server 14.04 LTS, but when I try to log in via FileZilla with SFTP I get the following error:

Received unexpected end-of-file from SFTP server

If I try to connect with my root user everything's fine, so I must have missed something in the new user creation. Here's what i did:

First of all I created a fake shell in /etc/shells naming it /bin/false I create a group named ftpgroup

sudo groupadd ftpgroup

Then I created the ftp user within it

sudo useradd --home /var/www/html/mydir --group ftpgroup --shell /bin/false myftpuser

I gave a password to the user

sudo passwd myftpuser

And made it the owner of the home directory i gave him

sudo chown -R myftpuser /var/www/html/mydir

finally I set up privileges for the folder

sudo chmod 755 /var/www/html/mydir

I'm aware that changing the /bin/false shell to /bin/bash would make it work, but that would give my user the ability to access shell commands, which I would avoid if possible, I just want him to access files in his own directory and nothing more.

1

Change the owner of your /var/www/html/mydir with below command

sudo chown -R root:ftpgroup /var/www/html/mydir

check this one for reference http://devtidbits.com/2011/06/29/implement-a-sftp-service-for-ubuntudebian-with-a-chrooted-isolated-file-directory/

| improve this answer | |
0

You could modify /etc/ssh/sshd_config a bit and use

Match User myftpuser
   ChrootDirectory %h
   ForceCommand internal-sftp
   AllowTcpForwarding no
   PermitTunnel no
   X11Forwarding no

Of course, replace username with the username you'd like to restrict. It's also possible to match against user group with Match Group parameter.

Anyway, after that modification and reloading your ssh server config it should work.

| improve this answer | |
  • I tried your solution, but if I leave ChrootDirectory %h I can't access, I get a "Network error: Software caused connection abort". Without that line it works, but I'm able to access parent directory, which is not the desired behaviour. – Dakkar Mar 12 '15 at 11:59
  • Since you have only one user to match against, try ChrootDirectory /home/myftpuser or so. Also check out the directory permissions. – Janne Pikkarainen Mar 12 '15 at 12:14
  • Same behaviour. The user owns the directory, and permission are 777. – Dakkar Mar 12 '15 at 12:29

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.