Linux – Creating FTP user to access a specific directory with SFTP in Linux Ubuntu Server 14.04 LTS

ftplinuxsftpuser-management

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.

Best Answer

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/