Experiencing an issue when attempting to connect to a server using Paramiko and SSH agent Pageant. The error indicates that the script is failing during the connection attempt, specifically when Paramiko tries to interact with the SSH agent (Pageant) and processes the key data. The error message suggests that Paramiko is encountering non-UTF-8 byte sequences when it expects UTF-8 encoded data:
"utf-8' codec can't decode byte 0x82 in position 1: invalid start byte"
However, decoding does not fix the problem.
Traceback (most recent call last):
File: “c:../ssh_little.py”, line 11, in module,
client.connect(hostname=hostname, username=username)
File “c:/..../conda/Lib/site-package/paramiko/agent.py, line 415, in __init__ self.connect(conn)
File “c:/..../conda/Lib/site-package/paramiko/agent.py, line 89, in _connect AgentKey(
File “c:/..../conda/Lib/site-package/paramiko/agent.py, line 443, in __init__ self.name = msg.get_text()
File “c:/..../conda/Lib/site-package/paramiko/message.py, line 184, in get_text return u(self.get_string())
File “c:/..../conda/Lib/site-package/paramiko/util.py, line 333, in u return s.decode(encoding)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x82 in position1: invalid start byte
Here is the used code:
import paramiko
hostname = 'host.com'
username = 'user'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=hostname, username=username)
On the other hand, I can connect manually to that server using PuTTY and Pageant with the same key.
Any idea, please? Thanks!
On macOS I can reproduce the same exception (with
ssh-agentandssh-add) with a\x82char in the private key's comment:In the above
hexdumpoutput we can see there's a\x82betweenfooandbar.On Windows I have a PuTTY
.ppk(I assume your private key is generated by PuTTY since you are using Pageant) and the content is like:Here it has a
Comment:section. So check your private key file to see if there are non-UTF8 chars.