Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active January 19, 2023 20:25
Show Gist options
  • Save heywoodlh/b5c9b6f8da74f10a03d34aa0338aca97 to your computer and use it in GitHub Desktop.
Save heywoodlh/b5c9b6f8da74f10a03d34aa0338aca97 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
bw get password ssh/key_passphrase | head -1
#!/usr/bin/env bash
## Start new ssh-agent if ssh-agent is not running with PID
if ! ps aux | grep ${SSH_AGENT_PID} | grep -q ssh-agent
then
if ! ssh-add -l > /dev/null
then
rm -rf $(dirname ${SSH_AUTH_SOCK})
mkdir -p $(dirname ${SSH_AUTH_SOCK})
ssh-agent -a "${SSH_AUTH_SOCK}" > /dev/null
fi
fi
## Alpine Linux needs util-linux installed to work properly (along with pass and openssh)
ssh_identities=$(ssh-add -l)
if [[ ${ssh_identities} == 'The agent has no identities.' ]]
then
if [ -f /etc/debian_version ] || grep -q 'Alpine Linux' /etc/os-release #|| grep -q 'Arch Linux' /etc/os-release
then
bw get password ssh/key_passphrase | SSH_ASKPASS=/bin/cat setsid -w ssh-add -t 1h ~/.ssh/id_rsa &>/dev/null
else
bw get password ssh/key_passphrase > /dev/null \
&& export SSH_ASKPASS=$(which ssh-askpass) \
&& ssh-add -t 1h ~/.ssh/id_rsa < /dev/null
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment