One of the things to check when you get a No existing session error in Paramiko’s SSH key authentication is whether the SSH key file is in an old format or not.

While writing a Python script, I encountered the following error in the process of connecting to a remote server.

  File "**********/paramiko/transport.py", line 1624, in auth_publickey
    raise SSHException("No existing session")
paramiko.ssh_exception.SSHException: No existing session

I thought it might be a server issue since it only happened on a specific server, so I did a web search, but didn’t find any specific cases.

The error message in auth_publickey caught my eye, so I recreated the key in ed25519 format and added it to the server, and that solved the problem!
FYI: The SSH key file generation was based on “Generating a new SSH key and adding it to the ssh-agent” on GitHub.

The server where the problem occurred is one that I’ve been using for a long time, and the format of the SSH key file is old, and I think the format was dropped in the Paramiko update.