Skip to content

Unable to Connect to Server Using Private Key #1448

@Suryad250900

Description

@Suryad250900

Description

Currently, I am able to connect to the server using a password, but I am facing an issue when trying to connect using a private key.

Steps Taken

Connected to the server using PowerShell.

Generated an SSH key using ssh-keygen -m PEM.

Downloaded the id_rsa file.

Copied the file path and passed it to privateKey.

Encountered the following error:

"All configured authentication methods failed."

Code for Reference

const fs = require('fs');
const path = require('path');
const { NodeSSH } = require('node-ssh');

const ssh = new NodeSSH();

// Connecting to the server using private key
ssh.connect({
  host: '1.1.1.1',
  username: 'root',
  privateKey: fs.readFileSync(path.join(__dirname, './id_rsa')).toString(),
  passphrase: '*****' // If the key is passphrase-protected
})
.then(() => {
    ssh.getFile('/opt/nodejs/sample.txt', '/Users/Surya/Downloads/sample.txt')
        .then(() => {
            console.log("The file has been transferred.");
        })
        .catch(err => {
            console.error("File transfer error:", err);
        });
})
.catch(err => {
    console.error("SSH connection error:", err);
});

Expected Behavior

The SSH connection should be established using the private key without any authentication failure.

The file should be successfully transferred from the server to the local system.

Issue Faced

Error: "All configured authentication methods failed."

Possible Causes:
Incorrect private key format
Key permissions issue
Passphrase mismatch
Server not recognizing the public key

Request for Assistance
Is there anything wrong with how the private key is being used?
Are there additional steps required to configure the SSH key correctly on the server?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions