Strovent SystemsSign in
Reference

SSH "agent refused operation": signing failed and could not add identity

The agent was reached but said no, and it never says why. Usual causes: a key added with -c and no askpass, an untouched FIDO key, a locked agent, or gpg-agent.

"agent refused operation" means ssh or ssh-add reached the agent, sent a request, and got back a plain failure reply. In the SSH agent protocol (RFC 9987) the generic failure reply is a single byte, SSH_AGENT_FAILURE, with no reason attached, so the client can only print this generic text. The real cause is known only to the agent.

If the agent cannot be reached at all, the message is different: see ssh-add "Could not open a connection to your authentication agent".

Where it appears

  • At login: sign_and_send_pubkey: signing failed for ED25519 "/home/user1/.ssh/id_ed25519" from agent: agent refused operation. Older clients print only sign_and_send_pubkey: signing failed: agent refused operation. The client then tries its next key or method, so the session often ends in "Permission denied (publickey)" or falls back to a password prompt.
  • Adding a key: Could not add identity "/home/user1/.ssh/id_ed25519": agent refused operation.
  • Adding a smart card or token library: Could not add card "/opt/vendor/lib/pkcs11.so": agent refused operation.
  • Signing a file with ssh-keygen -Y sign, which git also uses to sign commits with an SSH key: Couldn't sign message (signer): agent refused operation.

First, find out which agent answered

Run echo "$SSH_AUTH_SOCK". The OpenSSH ssh-agent uses a socket under ~/.ssh/agent/ (OpenSSH 10.1 and later) or a /tmp/ssh- directory (older versions). Any other path belongs to another program that speaks the same protocol, such as gpg-agent, a desktop keyring or a password manager. Those have their own rules for refusing; check that program's settings and log.

Causes in the OpenSSH agent

  • The key was added with confirmation (ssh-add -c). For every use, the agent runs ssh-askpass to ask you. If no askpass program is installed, the agent has no display to show it on, or you click no, it refuses. The display is the one in the agent's own environment when it started, not your current window's. Install an askpass program, or reload the key without -c: ssh-add -d ~/.ssh/id_ed25519, then ssh-add ~/.ssh/id_ed25519.
  • A FIDO security key (made with ssh-keygen -t ed25519-sk or ecdsa-sk) did not sign. The agent signs through the authenticator, so it refuses when the key is not plugged in or you do not touch it in time. A key created with verify-required also needs its PIN. The agent asks for it through askpass, and without askpass it cannot ask. How touch and PIN work is in Security keys (FIDO2) with SSH.
  • The agent is locked. After ssh-add -x, the agent lists no keys and refuses to add new ones. Unlock it with ssh-add -X.
  • The key has a destination constraint (ssh-add -h, OpenSSH 8.9 and later). The agent refuses to use it for a host, or a forwarded hop, that the constraint does not list. Run ssh-add -d on the key, then add it again with the missing -h entry. Examples are in SSH agent forwarding not working.
  • A PKCS#11 or FIDO library is not on the agent's allowed list. ssh-add -s and ssh-add -S load a shared library into the agent. The agent accepts only paths that match its -P list (/usr/lib*/*,/usr/local/lib*/* by default in portable OpenSSH). A forwarded agent refuses to load such libraries unless it was started with -O allow-remote-pkcs11.

See the reason

Start a separate agent in debug mode on its own socket. It stays in the foreground and logs each refusal:

ssh-agent -d -a /tmp/agent-debug.sock

In a second terminal, run export SSH_AUTH_SOCK=/tmp/agent-debug.sock, add the key the same way as before, and repeat the failing command. The first terminal shows lines such as process_sign_request2: user refused key (confirmation failed) or refusing use of destination-constrained key. Stop it with Ctrl+C.

gpg-agent as the SSH agent

gpg-agent can serve SSH when started with --enable-ssh-support. It keeps keys added with ssh-add encrypted, and asks for their passphrase through pinentry when you use them. The SSH agent protocol cannot tell it which terminal you are on, so it opens pinentry on the terminal or display where gpg-agent started. From another terminal or an SSH session, nothing appears and the request fails.

Tell it which terminal to use, then try again:

export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye

GnuPG's manual recommends setting GPG_TTY in ~/.bashrc for every shell. gpg-agent also offers only the keys listed in its sshcontrol file or marked with the Use-for-ssh attribute.

Similar messages with other causes

Sources

Spotted a mistake? Email [email protected].