首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Paramiko为SSH密钥身份验证提供了PasswordRequiredException错误

Paramiko为SSH密钥身份验证提供了PasswordRequiredException错误
EN

Stack Overflow用户
提问于 2022-08-28 11:02:14
回答 1查看 127关注 0票数 0

代码:

代码语言:javascript
运行
复制
pkey=paramiko.RSAKey.from_private_key_file(key_path)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('host, username='xxxxx',pkey=pkey)

我没有给私钥设置任何密码。所以,我没有提出任何论据。

错误:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/client.py", line 435, in connect
    self._auth(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/client.py", line 766, in _auth
    raise saved_exception
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/client.py", line 736, in _auth
    key = self._key_from_filepath(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/client.py", line 588, in _key_from_filepath
    key = klass.from_private_key_file(key_path, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/pkey.py", line 249, in from_private_key_file
    key = cls(filename=filename, password=password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/rsakey.py", line 64, in __init__
    self._from_private_key_file(filename, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/rsakey.py", line 194, in _from_private_key_file
    data = self._read_private_key_file("RSA", filename, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/pkey.py", line 322, in _read_private_key_file
    data = self._read_private_key(tag, f, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/pkey.py", line 351, in _read_private_key
    data = self._read_private_key_openssh(lines[start:end], password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/paramiko/pkey.py", line 452, in _read_private_key_openssh
    raise PasswordRequiredException(
paramiko.ssh_exception.PasswordRequiredException: private key file is encrypted

我能够成功地使用FileZilla和SSH连接。

SSH详细输出

代码语言:javascript
运行
复制
ssh -v -i /Users/aptuz/Downloads/integra_rsa user@host  
OpenSSH_8.6p1, LibreSSL 3.3.6  
debug1: Reading configuration data /Users/aptuz/.ssh/config  
debug1: /Users/aptuz/.ssh/config line 1: Applying options for *   
debug1: Reading configuration data /etc/ssh/ssh_config  
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files  
debug1: /etc/ssh/ssh_config line 54: Applying options for *  
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling  
debug1: Connecting to host port 22.  
debug1: Connection established.  
debug1: identity file /Users/aptuz/Downloads/integra_rsa type 0  
debug1: identity file /Users/aptuz/Downloads/integra_rsa-cert type -1  
debug1: Local version string SSH-2.0-OpenSSH_8.6  
debug1: Remote protocol version 2.0, remote software version GXSSSHD_Comments  
debug1: compat_banner: no match: GXSSSHD_Comments  
debug1: Authenticating to host:22 as 'user'  
debug1: load_hostkeys: fopen /Users/aptuz/.ssh/known_hosts2: No such file or directory  
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory  
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory  
debug1: SSH2_MSG_KEXINIT sent  
debug1: SSH2_MSG_KEXINIT received  
debug1: kex: algorithm: ecdh-sha2-nistp256  
debug1: kex: host key algorithm: ssh-rsa  
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none  
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256-etm@openssh.com compression: none  
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY  
debug1: SSH2_MSG_KEX_ECDH_REPLY received  
debug1: Server host key: ssh-rsa SHA256:9spuefLNoQEYjtHhNfF3Emwbnlqibxbam2QYf5VXEp4  
debug1: load_hostkeys: fopen /Users/aptuz/.ssh/known_hosts2: No such file or directory  
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory  
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory  
debug1: Host 'host' is known and matches the RSA host key.  
debug1: Found key in /Users/aptuz/.ssh/known_hosts:10  
debug1: rekey out after 4294967296 blocks  
debug1: SSH2_MSG_NEWKEYS sent  
debug1: expecting SSH2_MSG_NEWKEYS  
debug1: SSH2_MSG_NEWKEYS received  
debug1: rekey in after 4294967296 blocks  
debug1: Will attempt key: /Users/aptuz/Downloads/integra_rsa RSA     SHA256:A8qNBO5MTleOBw3oRxo09zj5iiLpG6Tl8u0iHnG+7W0 explicit  
debug1: SSH2_MSG_SERVICE_ACCEPT received  
Please login with user ID and password.debug1: Authentications that can continue:   password,publickey,keyboard-interactive  
debug1: Next authentication method: publickey  
debug1: Offering public key: /Users/aptuz/Downloads/integra_rsa RSA   SHA256:A8qNBO5MTleOBw3oRxo09zj5iiLpG6Tl8u0iHnG+7W0 explicit  
debug1: Server accepts key: /Users/aptuz/Downloads/integra_rsa RSA   SHA256:A8qNBO5MTleOBw3oRxo09zj5iiLpG6Tl8u0iHnG+7W0 explicit  
debug1: Authentication succeeded (publickey).  
Authenticated to host ([xxx.xxx.xxx.xxx]:22).  
debug1: channel 0: new [client-session]  
debug1: Entering interactive session.  
debug1: pledge: filesystem full  
debug1: Sending environment.  
debug1: channel 0: setting env LANG = "en_US.UTF-8"  
This server does not support an interactive session.  
Goodbye.  
debug1: channel 0: free: client-session, nchannels 1  
Connection to host closed.  
Transferred: sent 3688, received 2716 bytes, in 1.6 seconds  
Bytes per second: sent 2302.4, received 1695.6  
debug1: Exit status -1  
EN

回答 1

Stack Overflow用户

发布于 2022-08-29 06:30:38

从堆栈跟踪中,您可以看到错误不是来自您的RSAKey.from_private_key_file,而是来自于SSHClient.connect中的某个地方。

这可能意味着使用key_path的身份验证失败,Paramiko不得不尝试.ssh文件夹中的默认密钥(因为SSHClient.connect的默认look_for_keys=True参数)。你可能那里有一个加密的密钥。没有加载它,隐藏您假定的“身份验证失败”问题。

查看Paramiko日志文件以获得详细信息。你可能有这样的问题:

Paramiko authentication fails with "Agreed upon 'rsa-sha2-512' pubkey algorithm" (and "unsupported public key algorithm: rsa-sha2-512" in sshd log)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73518110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档