You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: support certificate authentication. #551
In OpenSSH one can use a CA-signed key and certificate pair to sign-in to an SSH server with CA authentication turned on. The server sets a public certificate as the "trusted ca" and the client then uses a private key signed by that certificate to connect to the server.
The private key is just like an id_rsa file
You also need the signing public certificate file.
In OpenSSH this is passed using a convention:
Example: id_rsa <- the name of the signed private key. id_rsa-cert.pub <- the public certificate used to sign the private key.
you would then connect to your server with this command: ssh -i id_rsa username@server.com
I would like to see SSH2 support this authentication mechanism.
My suggestion for interface would be to add a "certKey" option to the connection options where we can include the certificate.
Reacted by Julien Nigri, Avin, Carl Hörberg, Sonny Bhatia, Anders Bälter, Oren Fromberg, Zaiter, Ev Haus, Jinawong, Paul Kretschel and 11 more
AFAIK it should already work as such private keys are designed to be supported. Does it not work when you just supply the privateKey (e.g. with the contents of id_rsa in your example) or use one via an ssh agent?
It does not work. In OpenSSH I have to have both the id_rsa and id_rsa-cert.pub files present.
When I try to only use the private key with SSH2 it returns an error at client-authentication with this error message: Error: All configured authentication methods failed.
Any update on this one? Instead of generating a new public key in client.js, I tried sending the 'id_rsa-cert.pub'. From what I could understand, this seems to be passing the authentication (onUSERAUTH_PK_OK is being called in the stack trace), but I am stuck with the below error:
InvalidAsn1Error: Expected 0x2: got 0x8a
at newInvalidAsn1Error (/Users/emavin/Desktop/ssh2-master/node_modules/asn1/lib/ber/errors.js:7:13)
at Reader.readString (/Users/emavin/Desktop/ssh2-master/node_modules/asn1/lib/ber/reader.js:168:11)
at ECDSASigASN1ToSSH (/Users/emavin/Desktop/ssh2-master/node_modules/ssh2-streams/lib/utils.js:135:21)
at /Users/emavin/Desktop/ssh2-master/node_modules/ssh2-streams/lib/ssh.js:1623:19
at /Users/emavin/Desktop/ssh2-master/lib/client.js:596:9
at SSH2Stream.authPK (/Users/emavin/Desktop/ssh2-master/node_modules/ssh2-streams/lib/ssh.js:1618:3)
at SSH2Stream.onUSERAUTH_PK_OK (/Users/emavin/Desktop/ssh2-master/lib/client.js:567:14)
at Object.onceWrapper (events.js:273:13)
at SSH2Stream.emit (events.js:182:13)
at parse_USERAUTH (/Users/emavin/Desktop/ssh2-master/node_modules/ssh2-streams/lib/ssh.js:4329:12)
I couldn't figure out how to make this work either... I tried passing in the private key as the privateKey, and the cert as the publicKey, which didn't work. My use case is connecting to an AWS Lightsail server from a Lambda function. Using the AWS Lightsail API, you're able to obtain a temporary SSH key, but it's a signed key (private key + cert key). If I save the private key data into a file mykey and the cert key data into mykey-cert.pub, I can run ssh -i mykey ec2-user@... and connect just fine. The verbose output from that command shows:
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: Will attempt key: mykey explicit
debug1: Will attempt key: mykey RSA-CERT SHA256:wFM/y6uB4+7G6NCO013BYd+WjqqXBYZz+R3CPm0QLKU explicit
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: mykey
debug1: Authentications that can continue: publickey
debug1: Offering public key: mykey RSA-CERT SHA256:wFM/y6uB4+7G6NCO013BYd+WjqqXBYZz+R3CPm0QLKU explicit
debug1: Server accepts key: mykey RSA-CERT SHA256:wFM/y6uB4+7G6NCO013BYd+WjqqXBYZz+R3CPm0QLKU explicit
debug1: Authentication succeeded (publickey).
As of Version 6.2.0, @baelter's statement rings true, and force-swapping the pubKeyFullType results in an InvalidAsn1Error Error. (it can throw with multiple different messages aside from Expected <ref>: got <ref>)
However, as of Version 8.2.0 (latest I checked), force-swapping "ssh-rsa-cert-v01@openssh.com" to "ssh-rsa" actually works perfectly fine.
Any news or at least implementation plans in this issue after a next year? :-)
It seems that this library in the only one in npm for SSH connections - all the rest are just wrappers (please drop a link here if I'm wrong).
I've just faced this issue and have to use ssh-agent-based authentication (will try it and I hope it works fine - I guess it would not be easy/trivial to implement Nodejs-based server solution for multi-users/accounts with agent-based authentication), but would be nice to have native certificate-based method here in this library...
Activity
mscdex commentedon Apr 30, 2017
AFAIK it should already work as such private keys are designed to be supported. Does it not work when you just supply the
privateKey(e.g. with the contents ofid_rsain your example) or use one via an ssh agent?donleyp commentedon Apr 30, 2017
It does not work. In OpenSSH I have to have both the
id_rsaandid_rsa-cert.pubfiles present.When I try to only use the private key with SSH2 it returns an error at client-authentication with this error message:
Error: All configured authentication methods failed.mscdex commentedon May 1, 2017
Ok and just to clarify what
ssh-keygenparameters are you using to generate these key/certificate pairs?jdiamond commentedon Nov 20, 2017
Was looking for this, too. Here's a pretty good description of what they are and the
ssh-keygencommands used to create them:https://blog.habets.se/2011/07/OpenSSH-certificates.html
Avinm commentedon Jun 20, 2018
Any update on this one? Instead of generating a new public key in client.js, I tried sending the 'id_rsa-cert.pub'. From what I could understand, this seems to be passing the authentication (
onUSERAUTH_PK_OKis being called in the stack trace), but I am stuck with the below error:Here is my modified version of client.js
rbayliss commentedon Dec 27, 2018
I couldn't figure out how to make this work either... I tried passing in the private key as the
privateKey, and the cert as thepublicKey, which didn't work. My use case is connecting to an AWS Lightsail server from a Lambda function. Using the AWS Lightsail API, you're able to obtain a temporary SSH key, but it's a signed key (private key + cert key). If I save the private key data into a filemykeyand the cert key data intomykey-cert.pub, I can runssh -i mykey ec2-user@...and connect just fine. The verbose output from that command shows:baelter commentedon May 16, 2019
The CA signed key type is not supported it looks like?
DEBUG: Agent: Skipping unsupported key type: ssh-rsa-cert-v01@openssh.comTried adding
pubKeyFullType = pubKeyFullType.replace(/-cert-.*@openssh.com$/, '')toonUSERAUTH_PK_OKbut it only got me a little further.aleksmsd commentedon Jul 28, 2019
As of Version 6.2.0, @baelter's statement rings true, and force-swapping the
pubKeyFullTyperesults in anInvalidAsn1ErrorError. (it can throw with multiple different messages aside fromExpected <ref>: got <ref>)However, as of Version 8.2.0 (latest I checked), force-swapping
"ssh-rsa-cert-v01@openssh.com"to"ssh-rsa"actually works perfectly fine.TimWolla commentedon Jul 29, 2019
see #808
azaiter commentedon Dec 19, 2019
Above PR doesn't really solve connecting to SSH2 hosts that can only authenticate through
ssh-rsa-cert-v01@openssh.comfor example.Example debug output when using above PR branch:
TimWolla commentedon Dec 19, 2019
My PR is for certificates for client authentication. It's not for server / machine authentication like your log appears to require.
paulkre commentedon Aug 15, 2020
Would love to use this feature too.
davidchappelle commentedon Jan 4, 2022
What needs to be done here to take this across the finish line? Seems it has been kicked down the road for 5-ish years.
bbthekings commentedon May 5, 2022
any proposals in this case? at least an implementation approach? thanks
lichwala commentedon Aug 4, 2023
Any news or at least implementation plans in this issue after a next year? :-)
It seems that this library in the only one in npm for SSH connections - all the rest are just wrappers (please drop a link here if I'm wrong).
I've just faced this issue and have to use ssh-agent-based authentication (will try it and I hope it works fine - I guess it would not be easy/trivial to implement Nodejs-based server solution for multi-users/accounts with agent-based authentication), but would be nice to have native certificate-based method here in this library...
realByg commentedon May 19, 2024
bruh this is a 7-year-old issue, any work around for it?
darkmirrors commentedon Apr 30, 2025
最后我是通过用
node-pty这个库来发起 SSH 证书校验请求的,还加了证书校验失败后用密码登录做兜底,希望对依然有这个问题的人有帮助。