I've been using a ssh key for a while by opening it using gpg agent. I do remember the gpg agent password, but I don't remember the ssh key.
How could I recover the ssh key from the gpg agent?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
ssh-agent. Auth requests are sent to the agent, and agent returns the authentication. You can't retrieve any private key but only public keys from the agent. It is designed in this way on purpose for security.
The agent will never send a private key over its request channel. Instead, operations that require a private key will be performed by the agent, and the result will be returned to the requester. This way, private keys are not exposed to clients using the agent.
If you want to get back your public key, you can interact with the gpg agent with
ssh-add just as what you did with ssh agent.
# list public keys from the agent ssh-add -L
Update: detail about how key challenges work.
When you connect to a server with SSH, the server doesn't directly ask you for the private key and passphrase to do the authentication, because sending them over the net is insecure.
Instead, when the server wants to authenticate you're who you claim to be, it sends you a request calculated with your public key. To complete the auth, you have to calculate a response with the private key and the request, and send the response back to the requester.
The gpg agent is an agent for you to handle the response. It does store the private key and passphrase. But it's designed in a way such that you can't retrieve them out of the agent.