-
Notifications
You must be signed in to change notification settings - Fork 695
Description
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?