This always takes me a while to figure out when installing a new system so here is a foolproof guide to do this right once and for all. Kudos to all the people in this Manjaro thread. However, this should work on any system with KDE and systemd
.
Make sure to install required packages:
sudo pacman -Syu --needed kwallet5 ksshaskpass kwalletmanager kwallet-pam signon-kwallet-extension
Create a new shell script named ssh-askpass.sh
in /etc/profile.d/
:
#!/bin/sh
# in /etc/profile.d/ssh-askpass.sh
export SSH_ASKPASS=/usr/bin/ksshaskpass
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR"/ssh-agent.socket
It needs to be at this location, adding this to user directories in $HOME
did not seem to have the desired effect. But perhaps adding to $HOME/.profile
could solve this and root privelages might not be needed for this step.
Create an ssh-agent
systemd
service for your local user:
mkdir -p ~/.config/systemd/user
touch ~/.config/systemd/user/ssh-agent.service
Contents of ~/.config/systemd/user/ssh-agent.service
:
[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
Then we just need to enable the service and start the service:
systemctl --user daemon-reload
systemctl --user enable ssh-agent.service
systemctl --user start ssh-agent.service # just to check it is working
Create a desktop entry to automatically add your keys:
touch ~/.config/autostart/ssh-add.desktop
with contents:
[Desktop Entry]
Exec=ssh-add -q ~/.ssh/key1 ~/.ssh/key2 ~/.ssh/key3 < /dev/null
Name=ssh-add
Type=Application
Reboot and you should be prompted for your passwords at the next login:
sudo systemctl reboot
If there is no prompt after login, keys can also be stored in the wallet manually:
ssh-add -q /path/to/key < /dev/null