Unable to Connect to Server Using Private Key
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.8k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the ssh.connect call from the issue with the supplied privateKey and passphrase, then inspect how authentication failures are reported before getFile runs. Verify whether the key format, passphrase, and server-side public-key setup are accepted; done means the connection authenticates and the requested file transfer succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100