简体   繁体   中英

Getting "not a valid RSA private key file" when loading key to Python Paramiko from Key Vault

I am trying to connect to a SFTP that use username, passphrase, SSH key (no password needed) in notebook in Synapse. SSH key is kept as a secret in Key Vault.

Host = "sftp.xxxxx.no"
Username = "xxxxx"
Passphrase = "xxxxx"
port = 22

from notebookutils import mssparkutils
SSHkey = mssparkutils.credentials.getSecret('keyvault','SSHkey') #so far has no problem

keydata = b"""AAAAxxx==""" #this is a public key I got through running ssh-keyscan in terminal
key = paramiko.RSAKey(data=decodebytes(keydata))

import io
privkey = io.StringIO(SSHkey)
ki = paramiko.RSAKey.from_private_key(privkey)

cnopts = pysftp.CnOpts()
cnopts.hostkeys.add('sftp.xxxxx.no', 'ssh-rsa', key)

client = pysftp.Connection(host = Host, username = Username, private_key = SSHkey, private_key_pass = Passphrase, cnopts=cnopts)
output = client.listdir()

My SSHkey starts with "ssh-rsa AAAA... " and ends with "RF rsa-key-20221126" .

The error msg is:

not a valid RSA private key file

Anyone can show me the light of the tunnel?

You have public key stored in your key vault. Not a private key.

You cannot authenticate using public key. You have to store the private key to the vault.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM