Skip to content

SSH keys in KDE Plasma

So, from what you might have read, I've been doing a little distro hopping and with that I've also moved from Gnome Shell(Gnome 3) to KDE Plasma as well. But one thing has always bugged me in recent years regarding Plasma and that is that when I try and use my private SSH keys I keep being asked for my passphrase for said keys. After having searched the net again and again, I decided I'd just throw what is needed, into a blog post here on the site so that if I ever need it again, I could just look at my own site =D

That and, of course, for others as well.

Startup and shutdown scripts

Create the file (and folders leading to it if needed):

$HOME/.config/plasma-workspace/env/ssh-agent-startup.sh

And add the following to it:

#!/bin/bash
export SSH_ASKPASS="/usr/bin/ksshaskpass"

if ! pgrep -u $USER ssh-agent > /dev/null; then
    ssh-agent > ~/.ssh-agent-info
fi
if [[ "$SSH_AGENT_PID" == "" ]]; then
    eval $(<~/.ssh-agent-info)
fi

Create the file (and folders leading to it if needed):

$HOME/.config/plasma-workspace/shutdown/ssh-agent-shutdown.sh

And add the following to it:

#!/bin/sh
[ -z "$SSH_AGENT_PID" ] || eval "$(ssh-agent -k)"

KDE should automatically load those scripts and execute them when you login and logout.

Login script

The last step is to unlock the wallet on login, so that you don't have to enter the passphrase for your SSH keys every time you login, just the first time if you tick the "Remember password until you logout" checkbox.

You can place this file where ever you want and name it what ever you want, in my instance I have it as:

~/bin/ssh-autostart-plasma.sh

Now, put the following in it:

#!/bin/bash

# Wait for kwallet
kwallet-query -l kdewallet > /dev/null

for KEY in $(ls $HOME/.ssh/id_rsa_* | grep -v \.pub); do
  ssh-add -q ${KEY} </dev/null
done

for KEY in $(ls $HOME/.ssh/id_ed25519_* | grep -v \.pub); do
  ssh-add -q ${KEY} </dev/null
done

Now all we have to do is add this script to our autostart scripts by going to:

System Settings -> Startup and Shutdown -> Autostart

Click on "+Add" and then "+Add Login Script", in the file browser that pops up, go and select the file you created last.

AutostartKDE Plasma Autostart

Conclusion

That's it! Now all you have to do is to logout and login again to get a prompt for each of your private keys where you enter the passphrase for each of them and tick the "Remember password until you logout" checkbox (if you want) and you're done!