Yubikey + SSH Keys + xubuntu

From OISecWiki
Revision as of 10:46, 30 March 2025 by Cliff (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

So I have a yubikey with my SSH private key on them with a PIN.

When trying to SSH to a host on xubuntu with my Yubikey in it's USB port, ssh won't use the key. It does find the key, but it exits everytime with the error "sign_and_send_pubkey: signing failed for ECDSA-SK "" from agent: agent refused operation".

A post[1] on superuser.com has a potential fix. The problem is that the ssh-agent doesn't know how to ask you for your PIN.

Fixing this is making sure ssh-agent knows how to execute 'ssh-askpass' (you might need to apt-get install it first), so it can ask the PIN. When running the following, everything start to work:

eval "$(ssh-agent -s; SSH_ASKPASS=/usr/bin/ssh-askpass)"

However if you want this to permanent, you would try to stick it in your .bashrc or .profile.

To prevent multiple ssh-agents running when opening multiple terminals (.bashrc gets ran every time you open a terminal), I decided to put it in .profile. And here is where it goes wrong.

Apparantly gnome-keyring-daemon runs after executing .profile to fork it's ssh-agent. This will overwrite SSH_AUTH_SOCK environment, and we're stuck again with the gnome-keyring-daemon ssh-agent, which does not know how to execute ssh-askpass. Apparently when running normal ubuntu with full gnome this isn't a problem, because it will generate the ssh-askpass popup and ask for the PIN.

On xubuntu you need to do the following:

  1. Open xfce4-session-settings
  2. Go to the tab 'advanced'
  3. Disable 'Launch GNOME services on startup'
  4. Restart your system (a logout will still keep systemd running all backend services)

After the restart and login everything works. You might still see gnome-keyring-daemon running, but it will no longer interfer with your .profile started ssh-agent.