Last active
September 13, 2021 04:07
-
-
Save euske/7a6724afef8d92b67eab96ce95f3d998 to your computer and use it in GitHub Desktop.
sshon: add a specified ssh key only when necessary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SSH_HOME=$HOME/.ssh | |
SSH_LOG=${SSH_AGENT_LOG:-$SSH_HOME/ssh-agent.log} | |
SSH_KEY=${1:-$SSH_HOME/id_ed25519} | |
KEY_DURATION=1d | |
IFS=$'\n' | |
sig=$(ssh-keygen -l -f "$SSH_KEY") | |
for i in $(ssh-add -l); do | |
if [ "$i" = "$sig" ]; then | |
echo "$sig" | |
exit | |
fi | |
done | |
ssh-add -t "$KEY_DURATION" "$SSH_KEY" && | |
echo "$(date) added: $SSH_KEY" >>$SSH_LOG; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment