Search code examples
sshkeyprivatetunneldbeaver

DBeaver ssh tunnel invalid private key


Just want to leave it here, so the link to the solution won't be lost.

I have a private 4096-byte RSA key (probably it was generated using this guide https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).

I've got an error while trying to establish a new connection through an ssh tunnel using DBeaver (6.1.2).


invalid privatekey: [B@540.....


Solution

  • This error is due to the format of the SSH private key. By default, ssh-keygen is creating a private key using the OpenSSH format—with this header:

    -----BEGIN OPENSSH PRIVATE KEY-----
    

    But DBeaver only accept keys using the older PEM format—with this header:

    -----BEGIN RSA PRIVATE KEY-----
    

    You can either generate a key directly with the correct header using:

    ssh-keygen -t rsa -b 2048 -m PEM
    

    Or you can convert an existing key (careful! this overwrite the existing key, you can just copy the private key and apply the command on the copy):

    ssh-keygen -p -m PEM -f id_rsa
    

    There is an open issue on DBeaver's GitHub.