SFTP is a common way to upload and download files from your web server. However, sometimes you may encounter an error when trying to connect to your server via SFTP, such as:

FATAL ERROR: No supported authentication methods available (server sent: publickey)
Error: Could not connect to server

This error means that the SFTP client and the server could not agree on a common authentication method. The server only accepts public key authentication, but the client either doesn’t have a valid SSH key pair, or doesn’t provide it correctly.

Don’t worry, we can quickly resolve this problem by working through the following steps.

Check Your SFTP Client Settings

Log in to your server via SSH, and make sure you have necessary superuser permissions. Edit the SSH configuration using a text editor – you can use the following command to use nano:

sudo nano /etc/ssh/sshd_config

The above command will open a text editor. Use the arrow keys on your keyboard to navigate.

Look for the line that says PasswordAuthentication and ensure that it is set to ‘yes‘ – this line enables you to log in with a password.

Also, verify that the line ChallengeResponseAuthentication or KbdInteractiveAuthentication has a value of ‘yes‘.

After editing the file, press Ctrl + o to save the changes, and then press “Enter” to confirm it. Finally, press Ctrl + x to close the text editor.

Restart Your SSH Service

The final step is to restart your SSH service on your server. To do this, you can use the following command on your server:

sudo service ssh restart

This will restart the SSH service and reload the configuration files. You may need to enter your password for the sudo command.