How to stop SSH from asking for passphrase every time?

Howdy!

This is how I usually do it (for ed25519 and GitHub):

ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519 -C "name/desc <user@email.tld>
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
git config --global core.sshCommand "ssh -i ~/.ssh/id_ed25519 -F /dev/null"

Then add this to ~/.bash_profile (you will be prompted to enter the passphrase everytime you login to your system though):

if [ -z "$SSH_AUTH_SOCK" ] ; then
  eval `ssh-agent -s`
  ssh-add
fi

An alternative option is to use Keychain as manager for the ssh-agent and add this to your ~/.bash_profile. This allows for shells to share a single ssh-agent process.

eval $(keychain --eval --agents ssh --quick --quiet)

By default, the ssh-agent started by keychain is long-running and will continue to run, even after you have logged out from the system.
Quoted source ref: https://linux.die.net/man/1/keychain

Furthermore, in your ~/.ssh/config

Host github
    Hostname ssh.github.com
    Port 443
    User git
    PubKeyAuthentication yes
    IdentityFile ~/.ssh/id_ed25519
    ForwardX11 no
    IdentitiesOnly yes
1 Like