paramiko not properly forwarding agent

Viewed 116

I have tried this on both Python2 and Python3, with the same result.

My goal is to ssh into a machine, create a screen session, then ssh into that same machine from within there without being prompted for a password. I'm using localhost currently for testing. When I try this manually, it works as expected. I've tried to reproduce this in code:

ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
sshHostConfig = {
    "hostname": "localhost"
}

ssh.connect(**sshHostConfig)
s = ssh.get_transport().open_session()
paramiko.agent.AgentRequestHandler(s)
s.exec_command("screen -dmS test")

But when the code is done executing and I connect to the screen session, then try to ssh to localhost, it asks me for a password.

I can see that when I manually ssh, it's using the key from .ssh/authorized_keys. In the debug logging for paramiko, I see

DEBUG:paramiko.transport:Debug msg: b'.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding'

So I don't understand why I'm seeing a different result if I'm agent forwarding with both and they're both using the key from authorized_keys.

0 Answers
Related