Skip to content

Instantly share code, notes, and snippets.

@JasonSFuller
Created November 18, 2024 14:35
Show Gist options
  • Save JasonSFuller/9ebef25a3fb5d8bc877b02544ad81dfa to your computer and use it in GitHub Desktop.
Save JasonSFuller/9ebef25a3fb5d8bc877b02544ad81dfa to your computer and use it in GitHub Desktop.
keys.sh
#!/bin/bash
URL='https://github.com/jasonsfuller.keys'
if [[ -f ~/.ssh/authorized_keys ]]; then
cp -a ~/.ssh/authorized_keys{,.$(date +%Y%m%d%H%M%S)}
fi
function cleanup { rm -f "$tmp"; }
trap cleanup INT TERM QUIT EXIT
tmp=$(mktemp)
if ! curl -sfL "$URL" -o "$tmp"; then
echo "ERROR: failed to download keys from Github"
exit 1
fi
install -m 0755 -d ~/.ssh
install -m 0644 "$tmp" ~/.ssh/authorized_keys
if builtin command -v restorecon &>/dev/null; then
restorecon -R ~/.ssh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment