I want to save an SSH key passphrase in gnome-keyring and then use it automatically when I need it.
How to do this?
I want to save an SSH key passphrase in gnome-keyring and then use it automatically when I need it.
How to do this?
If gnome-keyring-daemon is already running, you can use ssh-add to add your key to the service:
ssh-add /path/to/private/key
For example:
ssh-add ~/.ssh/id_rsa
To save the passphrase, use seahorse-ssh-askpass from package seahorse:
cd $HOME/.ssh
/usr/lib/seahorse/seahorse-ssh-askpass my_key
Make sure that the public key is the filename of the private key plus .pub, in the example my_key.pub
To automatically use the key afterwards, see "Gnome Keyring dialog and SSH" and at first use, check "Automatically unlock this key whenever I'm logged in".
If you are using gnome-keyring-daemon but a ssh-agent that is not managed by the keyring, you can still manually store the passphrase in the keyring and use secret-tool (via apt install libsecret-tools) and an expect script (via apt install expect) when adding the key to your agent:
# Save passphrase to keyring via same format used by seahorse-ssh-askpass
# only required if entry does not already exist in the keyring
secret-tool store --label="Unlock password for: id_ed25519" unique "ssh-store:/home/$USER/.ssh/id_ed25519"
# Load key into ssh agent
FILE="/home/$USER/.ssh/id_ed25519"
PASS=$(secret-tool lookup unique ssh-store:$FILE)
/usr/bin/expect <(echo "
spawn ssh-add $FILE
expect \"Enter passphrase for $FILE\"
send -- \"$PASS\n\"
expect eof")
# Results should look like:
Enter passphrase for /home/username/.ssh/id_ed25519:
Identity added: /home/username/.ssh/id_ed25519 ([email protected])
Make sure your private (e.g. mykey) and public (e.g. mykey.pub) key are stored in the ~/.ssh directory. Then it will be loaded automatically.
From Gnome Keyring docs (Automatically loading SSH Keys):
The SSH agent automatically loads files in ~/.ssh which have corresponding *.pub paired files. Additional SSH keys can be manually loaded and managed via the ssh-add command.