I want to save an SSH key passphrase in gnome-keyring and then use it automatically when I need it.
How to do this?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIf 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".
seahorse-ssh-askpass
just prints the password I enter to stdout!!!
Mar 20, 2017 at 11:52
ssh-add
, however: SSH_ASKPASS=/usr/lib/seahorse/seahorse-ssh-askpass ssh-add /path/to/private/key </dev/null
. Redirecting standard input is required to force the use of SSH_ASKPASS
(graphical prompt).
/usr/libexec/seahorse/ssh-askpass
, but… yes, it adds the key to the agent and uses graphical prompt but this doesn't solve the problem. Next time I have to add the key again and enter the passphrase again…
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 (username@example.com)