2

I am trying to setup sftp to upload/download files from a specific directory (var/www/mysite.com)

My issue is when I try to connect using Filezilla and I get an error stating

No supported authentication methods available (server sent: publickey)

So I think I missed a step when settup up and configuring sftp on my Ubuntu LAMP server. I should not I want to be able to sftp using a username and password and not a keyfile.

Here is what I did: Created user with password via SSH I then

sudo adduser <username> www-data

I then

sudo nano /etc/vsftpd.conf

and inside the file set chroot_local_user=YES and commented out chroot_list_enable=YES I then restarted sftp using:

sudo service vsftpd restart

I then configured the users directory sudo usermod -d /var/www/mydomain.com note I replaced with the username I created

I then

sudo nano /etc/ssh/sshd_config

and added the below to the bottom of the file

Subsystem  sftp  internal-sftp
Match user <username>
ChrootDirectory /var/www/mydomain.com
ForceCommand internal-sftp
AllowTcpForwarding no

and ensure that further up in the file that this is commented out (i.e before the one you just added)

#Subsystem sftp /usr/lib/openssh/sftp-server

I then restarted ssh using:

sudo service ssh restart

and changed permissions using:

chown root:root /var/www
chown root:root /var/www/mydomain.com
chmod 755 /var/www

Lastly I did:

sudo chown -R www-data:www-data /var/www/mydomain.com
chmod 755 /var/www/site

However I am not able to login to sftp via filezilla??

When I run the ssh command:

sftp -vvv user@servername

I get the below. I do not have a /secure in the var/log folder?

when I run the above commend I get this output

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
/etc/ssh/ssh_config: line 57: Bad configuration option: usepam
/etc/ssh/ssh_config: line 58: Bad configuration option: subsystem
debug2: checking match for 'user <username>' host *****.com originally *****.com
debug3: /etc/ssh/ssh_config line 59: not matched 'user "*****"'
debug2: match not found
/etc/ssh/ssh_config: line 60: Bad configuration option: chrootdirectory
/etc/ssh/ssh_config: line 61: Bad configuration option: forcecommand
/etc/ssh/ssh_config: line 62: Bad configuration option: allowtcpforwarding
/etc/ssh/ssh_config: terminating, 5 bad configuration options
Couldn't read packet: Connection reset by peer
  • Are login attempts being logged in /var/log/secure on the server? What happens if you run this on the command line? sftp -vvv user@servername – bootbeast Mar 29 '17 at 23:12
1
/etc/ssh/ssh_config: line 60: Bad configuration option: chrootdirectory
/etc/ssh/ssh_config: line 61: Bad configuration option: forcecommand
/etc/ssh/ssh_config: line 62: Bad configuration option: allowtcpforwarding
/etc/ssh/ssh_config: terminating, 5 bad configuration options

You put these configuration options in the ssh_config instead of sshd_config. They are not valid in the first one.

sudo chown -R www-data:www-data /var/www/mydomain.com

This is also wrong, because the chroot directory has to be root-owned and not writable by any other user as explained in many answers and in manual page for sshd_config.

  • Thanks so I put the info in sshd_config , restarted vsftpd and then did sudo chown -R root:root /var/www/mydomain.com and I still get the same error? – Jay Mar 30 '17 at 13:04
  • Also make up your mind if you wish to configure VSFTPD or OpenSSH. They are completely different services providing SFTP. – Jakuje Mar 30 '17 at 13:06
  • ahh ok thank you show I made sure I am using and editing the ssh conf files and after a restart its now working. thanks all – Jay Mar 30 '17 at 16:46

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.