Are you using a passphrase protected key for your ssh logins, but it asks for the passphrase all the time?

Here’s a way to enter it once, and just work.

Install apps

SSH Client

You should already have the ssh client apps installed. They come by default in most distros.

sudo apt-get install openssh-client
sudo dnf install ssh-client

GUI SSH Askpass

You will need to install the ssh-askpass-fullscreen or ssh-askpass-gnome package. You need only one. I prefer the full screen one, so I’ll go with the first for the following.

sudo apt-get install ssh-askpass-fullscreen
sudo dnf install ssh-askpass-fullscreen
sudo pacman -Sy ssh-askpass-fullscreen

SSH Wrapper Script

By default, SSH will ask you for your passphrase without adding it to ssh-agent.

So we’ll add a wrapper script to check for and open your SSH key.

Create a new file as /usr/local/bin/ssh and enter the following into it:

#!/bin/bash

# Set this to your SSH key location
sshkey=~/.ssh/id_rsa

ssh-add -T $sshkey 2>/dev/null
if [ $? -ne 0 ] ; then
        ssh-add -q $sshkey
fi

/usr/bin/ssh $@

Once saved, make it executable.

chmod +x /usr/local/bin/ssh

Enable it

SSH Agent

Make sure your ssh-agent is running.

pgrep ssh-agent

If it’s not, this will usually take care of it:

eval `ssh-agent -s`

Prompt for PassPhrase using GUI

SSH needs to know to use ssh-askpass-fullscreen instead of the console prompt. Add this to your .bashrc or .bash_profile files.

# prefer X passphrase prompter
export SSH_ASKPASS_REQUIRE=prefer

Conclusion

Simple as pie. And lasts longer.