Difficulty: ★★☆☆☆
INTRODUCTION
Every time you need to authenticate an SSH session on KDE you’ll be prompted for your SSH key passphrase. Below are the steps that to remove this “feature”:
- Set
kwallet
as a passphrase store for SSH keys. - Start the SSH agent upon login as a
systemd
service. - Add all private keys present in
~/.ssh/
to the SSH agent.
INSTRUCTIONS
1. Install any required packages
Update your system and install the required packages as follows:
sudo pacman -Syu --needed kwallet ksshaskpass kwalletmanager
The modules required to unlock kwallet
at login are located in the kwallet-pam
and/or signon-kwallet-extension
packages. Reinstalling these ensures you have everything. kwalletmanager
isn’t necessary, but provides a convenient GUI to view the contents of kwallet
.
2. Set the SSH_ASKPASS environmental variable
Use nano
to create a new shell script named ssh-askpass.sh
in /etc/profile.d/
:
sudo nano /etc/profile.d/ssh-askpass.sh
Then add the following text:
#!/bin/sh
export SSH_ASKPASS=/usr/bin/ksshaskpass
NB: Alternatively, if you do not wish make SSH_ASKPASS
a system-wide environmental variable you can set it in ~/.zshenv
, ~/.bashrc
, or equivalent.
3. Set the SSH_AUTH_SOCK
environmental variable
Use nano
to edit your login shell, e.g. ~/.zshenv
, ~/.bashrc
, etc:
nano ~/.zshenv
Then add the following text:
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR"/ssh-agent.socket
4. Create the ssh-agent
systemd
service
Create the user-level systemd
directory if it does not already exist:
mkdir -p ~/.config/systemd/user
Use nano
to create the following ssh-agent
systemd
service:
nano ~/.config/systemd/user/ssh-agent.service
Then add the following text:
[Unit]
Description=SSH agent (ssh-agent)
[Service]
Type=simple
Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket
Environment=DISPLAY=:0
ExecStart=ssh-agent -D -a $SSH_AUTH_SOCK
ExecStop=kill -15 $MAINPID
[Install]
WantedBy=default.target
5. Reload the user-level system daemon
Run the following code to reload the user-level system daemon:
systemctl --user daemon-reload
6. Enable the new user-level systemd
service
Enable the new user-level systemd
service:
systemctl --user enable ssh-agent.service
7. Create startup script to add SSH keys to the agent
Use nano
to create the following ssh-add.desktop
startup script:
nano ~/.config/autostart/ssh-add.desktop
Then add the following text:
[Desktop Entry]
Exec=ssh-add -q ~/.ssh/key1 ~/.ssh/key2 ~/.ssh/key3 < /dev/null
Name=ssh-add
Type=Application
Note that your keys need to be listed in the Exec
line.
8. Reboot
Reboot for the changes to take effect.
sudo systemctl reboot
9. Add your SSH key passphrases to kwallet
You may be prompted by a series of dialogue boxes asking for each of your SSH key passphrases. If not, run the following code for each of your SSH private keys to store their passphrases in kwallet
:
ssh-add -q /path/to/key < /dev/null
AUTHOR’S NOTES:
- All input welcome. This is the first version I was able to get working after switching it to use
systemd
. - Source used: SSH keys - ArchWiki
- Source used: KDE Wallet - ArchWiki