I am thinking about this lately a lot, so I wanted to get someone else's opinion.

Let's say that I have an SSH key agent (e.g. Pageant or ssh-agent) running in background with loaded keys (keys were, of course, passphrase-protected). What stops a malware (running as a current user) from exploiting this, connecting to a SSH host and possibly running remote commands?

I hope that my understanding of this is flawed but, as long as agent is running in background, I can issue an ssh command and go right through the login.

Can you please help me confirm whether this is correct?

If this is in fact valid attack vector, what would be the best a way of protecting myself from it?


  • 1
    Take a look at the “Security issues” section of en.wikipedia.org/wiki/Ssh-agent
    – Steve
    Nov 28, 2018 at 15:51
  • Aha, thanks Steve! This clarifies everything! :) Can you please add it as answer so I could mark it as accepted? Nov 28, 2018 at 15:53

1 Answer 1


@Steve helped answering, but this question was still marked unanswered, so:

WikiPedia says:

ssh-agent creates a socket and then checks the connections from ssh. Everyone who is able to connect to this socket also has access to the ssh-agent. The permissions are set as in a usual Linux or Unix system. When the agent starts, it creates a new directory in /tmp with restrictive permissions. The socket is located in this directory.

There is a procedure that may prevent malware from using the ssh-agent socket. If the ssh-add -c option is set when the keys are imported into the ssh-agent, then the agent requests a confirmation from the user using the program specified by the SSH_ASKPASS environment variable, whenever ssh tries to connect.

Ssh-agents can be "forwarded" onto a server you connect to, making their keys available there as well, for other connections. On the local system, it is important that the root user is trustworthy, because the root user can, amongst other things, just read the key file directly. On the remote system, if the ssh-agent connection is forwarded, it is also important that the root user on the other end is trustworthy, because it can access the agent socket on the remote (though not the key, which stays local).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .