paramiko加载私钥文件报错

代码是:
import paramiko
private_key = paramiko.RSAKey.from_private_key_file('/Users/username/.ssh/id_rsa')

私钥文件是openssh的:

$ cat id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEA(略)

使用私钥+secureCrt可以正常登录;

但是python里这一行就会报错,提示rsa文件错误。

Traceback (most recent call last):
  File "/Users/tianyawei/PycharmProjects/protocolTest/CUAdapterV1/AdapterMachine/MyMachine.py", line 11, in <module>
    private_key = paramiko.RSAKey.from_private_key_file('/Users/tianyawei/.ssh/id_rsa', 'tianyawei@sunseaaiot.com')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/pkey.py", line 206, in from_private_key_file
    key = cls(filename=filename, password=password)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/rsakey.py", line 55, in __init__
    self._from_private_key_file(filename, password)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/rsakey.py", line 175, in _from_private_key_file
    data = self._read_private_key_file("RSA", filename, password)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/pkey.py", line 279, in _read_private_key_file
    data = self._read_private_key(tag, f, password)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/pkey.py", line 289, in _read_private_key
    raise SSHException("not a valid " + tag + " private key file")
paramiko.ssh_exception.SSHException: not a valid RSA private key file

找了很多方法都不对,有人知道吗。。。

慕姐3215275
浏览 2820回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP