Using KWallet to add SSH keys upon launch of the terminal

I already have SSH password set into KWallet and that works to auto add SSH keys to ssh-agent when I open VSCode (once upon login to system).

However if I open Konsole (the terminal) then the ssh key is not auto added, that is, the wallet isn’t used and instead I’m asked in the terminal to input password.

Reason the terminal asks me for the passoword is because I’ve added the following code into my .bashrc file:

# SSH Agent should be running, once
RunCount=$(ps -ef | grep "ssh-agent" | grep -v "grep" | wc -l)
if [ $RunCount -eq 0 ]; then
    echo Starting SSH Agent
    eval $(ssh-agent -s)
fi

# Add SSH keys to SSH agent
ssh-add -l &>/dev/null
if ! [ "$?" == 0 ]; then
     echo Adding SSH key...
     ssh-add ~/.ssh/GitHub-SSH
fi

Problem with this setup is that I first need to open VSCode to for the SSH keys to be added, and only then the terminal won’t ask me for the password.
So it appears KWallet is used only for GUI programs.

The question is, how do I tell the terminal to use KWallet when opened?
I suppose there are some command line options for KWallet that are suitable for .bashrc?

Using Debian 12 bookworm

1 Like

OK, I figured out myself with the help of README.md on this link

Basically crease a login script as follows:

#!/bin/bash
SSH_ASKPASS=/usr/bin/ksshaskpass
ssh-add ~/.ssh/your_key

Replace /usr/bin/ksshaskpass with the output of which ksshaskpass and if there is no output install ksshaskpass and try again.

Replace your_key with your SSH key which is to be added.

chmod your script with chmod u+x to make it executable.

In system settings head to Startup and Shutdown -> Autostart and add this script there.

Log out and log in again, open up your terminal and type ssh-add -l to verify it works.

This assumes you already have SSH password stored in KWallet