求教:python paramiko库:paramiko.ssh_exception.SSHException: not a valid RSA private key file

私钥是正确的;通过secureCrt可以正常访问堡垒机。
本地是mac,堡垒机那边是linux。
用python paramiko库加载私钥时会报错。。代码是:

import paramiko
private_key = paramiko.RSAKey.from_private_key_file('/Users/tian/.ssh/id_rsa')

异常是下面这个;Mac上之前是python3.6和现在是python3.7,都有这个异常。

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/tian/.ssh/id_rsa')
  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

我都尝试了很久了,但是没找到解决办法。。。。求大神帮忙。。。。。。

查看全部
carrieyummy
carrieyummy
2019/03/29 19:23
  • python
  • 点赞
  • 收藏
  • 回答
    私信

2个回复