cub1cle.com

David Dean, dave.dean@gmail.com, 25 June 2006

HOWTO: Get SSH-AGENT loading in KDE on FreeBSD

Why?

ssh-agent stores your keys and your passphrase, so once you've run ssh-add for a specific key, you dont need to enter your passphrase again. It's a life-saver if you have more than a few machines.

I used to run some extra code in /usr/local/bin/startkde, but that kept getting obliterated when I'd update KDE. So I decided to fix it once and for all.

Howto:

Do this:

touch ~/.kde/Autostart/start_ssh-agent.sh
chmod 700 ~/.kde/Autostart/start_ssh-agent.sh

Then put the following code in there:

#!/bin/csh
eval `/usr/bin/ssh-agent`
dcop klauncher klauncher setLaunchEnv SSH_AGENT_PID "$SSH_AGENT_PID"
dcop klauncher klauncher setLaunchEnv SSH_AUTH_SOCK "$SSH_AUTH_SOCK"

Then restart your KDE session, and you can run ssh-add to add keys to the agent, like so:

ssh-add keyfile.ppk

ssh-add should then ask for your passphrase, and when you next ssh using that key, ssh-agent will fill it in for you - saving your valuable seconds. ;-)

What's going on here?

KDE auto-runs the files in ~/.kde/Autostart/ on loading your session. So we put the start_ssh-agent.sh in there so it will run.

start_ssh-agent.sh just loads a shell, then starts ssh-agent, and crucially, tells KDE to load those environment variables (SSH_AGENT_PID and SSH_AUTH_SOCK) each time another app is launched. This is so ssh-add can later find the ssh-agent process it needs.