Ruby Net/SSH 7.0.1 - Ubuntu 22 / OpenSSL 3 issue

2.2k views Asked by At

I'm using Ubuntu 22 and OpenSSL 3

Ruby's Net/SSH is not working any longer as soon as I'm trying to connect using private keys.

Net::SSH.start X.X.X.X, "root"
/.rvm/gems/ruby-3.1.2/gems/net-ssh-7.0.1/lib/net/ssh/authentication/key_manager.rb:168:in `rescue in sign': the given identity is known, but the private key could not be loaded: OpenSSL::PKey::PKeyError (rsa#set_key= is incompatible with OpenSSL 3.0) (Net::SSH::Authentication::KeyManagerError)                     
/.rvm/gems/ruby-3.1.2/gems/net-ssh-7.0.1/lib/net/ssh/buffer.rb:266:in `set_key': rsa#set_key= is incompatible with OpenSSL 3.0 (OpenSSL::PKey::PKeyError)

I haven't found anything useful to fix this. This seems to work as long as I'm connecting with a Password, but as soon as I'm using a PEM key this fails.

I'm using:

  • Ubuntu 22
  • Net-SSH 7.0.1
1

There are 1 answers

0
billybaroo On

Until this is fixed in the 'net-ssh' gem you can workaround it. For this solution you'll have to generate a new ssh key pair using the older PEM format.

Note: You may be able to just convert your newer format to the older PEM format using this https://unix.stackexchange.com/questions/638043/how-to-convert-rfc4716-private-keys-to-pem-private-keys article, but I didn't test it. I did test and am currently using the solution below.

Move your existing keys to a save directory

cd ~
mkdir old_keys
mv id_rsa* old_keys

Generate new keys using older PEM format.

ssh-keygen -m PEM

This worked for me on my Ubuntu 22.04 install running Ruby (3.0.2-7ubuntu2.1) and net-ssh (7.0.1) and openssl (3.0.2-0ubuntu1.6)