This article is about fixing All configured authentication methods failed when both privateKey and password in VSCode sftp
  • 08-Feb-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing All configured authentication methods failed when both privateKey and password in VSCode sftp

All configured authentication methods failed when both privateKey and password in VSCode sftp

Lightrun Team
Lightrun Team
08-Feb-2023

Explanation of the problem

Problem Description: The configuration of AuthenticationMethods as publickey and password in the /etc/ssh/sshd_config file is causing “All configured authentication methods failed” error while using the SFTP extension in Visual Studio Code (VSCode). The password has been confirmed to be correct, and the ssh connection works fine without the authentication methods setting. Terminal SFTP works fine, but the issue occurs only with VSCode SFTP.

To Reproduce:

  1. Configure AuthenticationMethods as publickey,password in /etc/ssh/sshd_config
  2. Run the command service ssh restart
  3. Configure sftp.json as follows:
{
    "protocol": "sftp",
    "host": "server.example.com",
    "port": 22,
    "username": "****",
    "remotePath": "remotePath",
    "privateKeyPath": "/home/~~~/key.pem",
    "uploadOnSave": true,
    "password": "******"
}

Expected Behavior: The SFTP extension in VSCode should use both key and password authentication methods.

System Information:

  • Operating System: Linux Ubuntu 16.04
  • VSCode Version: 1.28.2
  • SFTP Extension Version: 1.7.4
  • Extension Logs:
[info] config at /home/user/example {"remotePath":"/home/project/test/example","uploadOnSave":true,"downloadOnOpen":false,"ignore":[],"concurrency":4,"protocol":"sftp","connectTimeout":10000,"interactiveAuth":false,"secure":false,"passive":false,"remoteTimeOffsetInHours":0,"port":22,"host":"server.example.com","username":"******","privateKeyPath":"/home/user/Documents/key.pem","password":"******"}
[error] Error: [server.example.com]: All configured authentication methods failed
   at Client.client.on.on.err (/home/user/.vscode/extensions/liximomo.sftp-1.7.4/out/src/core/remote-client/sshClient.js:229:28)
   at emitOne (events.js:121:20)
   at Client.emit (events.js:211:7)
   at tryNextAuth (/home/user/.vscode/extensions/liximomo.sftp-1.7.4/node_modules/ssh2/lib/client.js:394:12)
   at SSH2Stream.onUSERAUTH_FAILURE (/home/user/.vscode/extensions/liximomo.sftp-1.7.4/node_modules/ssh2/lib/client.js:599:5)
   at emitTwo (events.js:126:13)
   at SSH2Stream.emit (events.js:214:7)
   at parsePacket (/home/user/.vscode/extensions/liximomo.sftp-1.7.4/node_modules/ssh2-streams/lib/ssh.js:3930:10)
   at SSH2Stream._transform (/home/user/.vscode/extensions/liximomo.sftp-1.7.4/node_modules/ssh2

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for All configured authentication methods failed when both privateKey and password in VSCode sftp

The issue at hand is that the SFTP plugin is failing to connect to a remote host using password authentication when both authentication methods (password and private key) are setup on the destination host. The plugin outputs the error: [error] Error: [192.168.1.37]: All configured authentication methods failed.

To resolve this issue, it is recommended to use private key authentication instead of password authentication. This is because private key authentication allows for direct access without the need to enter a password, making it a more secure method of authentication. To use private key authentication, the privateKeyPath parameter should be added to the SFTP plugin configuration, as shown in the following code block:

{
    "name": "central-unit",
    "protocol": "sftp",
    "host": "192.168.1.37",
    "port": 22,
    "username": "pi",
    "remotePath": "sources/domo",
    "privateKeyPath": "/Users/jmcc/.ssh/id_rsa_code",
    "uploadOnSave": true
}

When using the private key authentication method, the SFTP plugin works perfectly and the following output is produced:

[info] [file-save] /Users/jmcc/sources/domo/src/storage.cpp
[info] local -> remote /Users/jmcc/sources/domo/src/storage.cpp

In conclusion, it is best to use private key authentication over password authentication when using the SFTP plugin to connect to a remote host, especially when both authentication methods are setup on the destination host.

Other popular problems with VSCode sftp

Problem: Incorrect Remote Path Configuration

Another common issue with using the VSCode sftp extension is specifying an incorrect remote path in the configuration. This can result in the plugin failing to upload files or upload them to the wrong location on the remote server.

Solution:

The remote path should be specified as an absolute path on the remote server, starting from the root directory. For example:

{
    "name": "central-unit",
    "protocol": "sftp",
    "host": "192.168.1.37",
    "port": 22,
    "username": "pi",
    "password": "*******",
    "remotePath": "/var/www/html/sources/domo",
    "uploadOnSave": true
}

It is important to check the specified remote path and make sure it is correct before using the plugin. If the remote path is incorrect, the plugin will not work as expected and may result in upload failures or incorrect file uploads.

Problem: Permission Denied Error

Another issue that may occur when using the VSCode sftp extension is encountering a “Permission Denied” error when attempting to upload files. This is typically caused by insufficient permissions on the remote server for the user specified in the configuration.

For example, if the user does not have write permissions in the specified remote path, the following error may occur:

[error] Error: [192.168.1.37]: Permission denied

Solution:

To resolve this issue, the user’s permissions on the remote server should be reviewed and adjusted as necessary to ensure they have sufficient permissions to write to the specified remote path. This may involve contacting the server administrator or using a different user account with sufficient permissions.

Problem: Connection Timeout Error

One of the common issues faced when using SFTP with Visual Studio Code is a connection timeout error. This can occur if the SFTP connection takes too long to establish or if the server takes too long to respond to a request. In such a scenario, the error message “Error: Timeout while trying to connect to the SFTP server” will be displayed.

Solution:

To resolve this issue, you can try increasing the timeout value in the SFTP configuration. This can be done by adding the “timeout” property to the SFTP configuration in the settings.json file. The default timeout value is set to 30 seconds, but it can be increased as per the requirement.

{
    "name": "central-unit",
    "protocol": "sftp",
    "host": "192.168.1.37",
    "port": 22,
    "username": "pi",
    "remotePath": "sources/domo",
    "privateKeyPath": "/Users/jmcc/.ssh/id_rsa_code",
    "timeout": 60,
    "uploadOnSave": true
}

In the above code snippet, the timeout value has been increased to 60 seconds. This should resolve the connection timeout error and allow the SFTP connection to be established successfully.

A brief introduction to VSCode sftp

VSCode SFTP is a plugin for Visual Studio Code that enables secure file transfer between a local system and a remote server. The plugin utilizes the SFTP (Secure File Transfer Protocol) protocol, which provides a secure and encrypted communication channel for transferring files. It allows developers to remotely access their files, edit them, and save changes directly to the server without having to manually download and upload files.

VSCode SFTP also provides a number of advanced features to streamline the workflow for developers, such as automatic upload on save, custom mappings for remote folders, and support for multiple SFTP connections. This plugin integrates seamlessly with Visual Studio Code and provides a simple and intuitive interface for managing file transfers. It also supports password and private key authentication, allowing developers to use the authentication method that best fits their needs. The plugin is highly customizable and can be configured to fit the specific needs of a project or organization, making it a valuable tool for any development team.

Most popular use cases for VSCode sftp

  1. File Transfer: Visual Studio Code SFTP (Secure File Transfer Protocol) is a plugin that allows for secure file transfers between a local development machine and a remote server. This makes it possible to upload and download files with ease and security, making it a useful tool for web developers, designers and other professionals who need to move files between local and remote environments.
  2. Remote Development: With the help of VSCode SFTP, developers can work on remote servers as if they were working on their local machine. This makes it possible to use Visual Studio Code’s powerful code editing and debugging tools on code running on remote servers, saving time and increasing productivity.
  3. Automated File Sync: VSCode SFTP can be configured to automatically upload files to a remote server every time they are saved, making it easier to maintain an up-to-date copy of a project on a remote server. This can be done using the following configuration:
{
    "name": "central-unit",
    "protocol": "sftp",
    "host": "192.168.1.37",
    "port": 22,
    "username": "pi",
    "remotePath": "sources/domo",
    "privateKeyPath": "/Users/jmcc/.ssh/id_rsa_code",
    "uploadOnSave": true
}

This configuration will ensure that every time a file is saved in Visual Studio Code, it will be automatically uploaded to the remote server at 192.168.1.37, in the directory sources/domo, using the private key stored at /Users/jmcc/.ssh/id_rsa_code.

Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.