How to make Windows WSL remember our ssh passphrase permanently

It’s annoying when our Terminal keeps asking us for our SSH passphrase when pushing our Git commit to GitHub/etc.
Here is a workaround that we can do to fix this issue permanently.

Add this script to your .bashrc or .zshrc file.

# SSH Agent should be running, once
if ! ps -ef | grep "[s]sh-agent" &>/dev/null; then
    echo Starting SSH Agent
    eval $(ssh-agent -s)
fi

# Add the ssh-key if no keys are added yet
if ! ssh-add -l &>/dev/null; then
    echo Adding keys...
    ssh-add -t 1d
fi

reference: https://serverfault.com/questions/672346/straight-forward-way-to-run-ssh-agent-and-ssh-add-on-login-via-ssh

Leave a comment