代码是:import paramikoprivate_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 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找了很多方法都不对,有人知道吗。。。 |