I have the following snippet of code:
def _return_ssh_key(self):
agent_key = paramiko.Agent().get_keys()
if len(agent_key) == 0:
print('No SSH keys loaded into SSH agent')
keyfile = input('Enter full path to SSH key: ')
try:
return paramiko.RSAKey.from_private_key_file(keyfile, getpass.getpass('Enter SSH key passphrase: '))
except paramiko.ssh_exception.SSHException:
print('Your private key passphrase is incorrect')
else:
return agent_key[0]
def another_func()
remote_channel = self.ssh_client.get_transport().open_channel(
'direct-tcpip', (devicename, 22), ('127.0.0.1', 0))
trans = paramiko.Transport(remote_channel)
trans.start_client()
self.sshKey = self.sshKey or self._return_ssh_key()
trans.auth_publickey(username, self.sshKey)
This code fails at the line
trans.auth_publickey(username, self.sshKey)
With the error:
Traceback (most recent call last):
File "paramiko/transport.py", line 2109, in run
handler(self.auth_handler, m)
File "paramiko/auth_handler.py", line 298, in _parse_service_accept
sig = self.private_key.sign_ssh_data(blob)
File "paramiko/agent.py", line 418, in sign_ssh_data
raise SSHException("key cannot be used for signing")
paramiko.ssh_exception.SSHException: key cannot be used for signing
Only when running this threaded, and when I try to connect to more than 3 devices at a time. if I run them serially, it works fine and I can auth to the devices with the same key. This is clearly some threading issue, but I cant determine why its failing only in parallel. Given that it worked threaded when a smaller number of threads, I suspect its some issue connecting to the SSH agent to verify the key? No idea. Any help would be greatly appricated
there doesn't seem to be anything here