Skip to content

Instantly share code, notes, and snippets.

@polynomialspace
Last active September 23, 2019 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polynomialspace/d27afe8c7af45ef5414d9b9bfb4063cf to your computer and use it in GitHub Desktop.
Save polynomialspace/d27afe8c7af45ef5414d9b9bfb4063cf to your computer and use it in GitHub Desktop.
Quick script to scrape ssh pubkeys from a server via ssh-keyscan and sign them with an SSH CA
#!/bin/sh
umask 77
TMPDIR=$(mktemp -d)
HOST="${1}"
cd ${TMPDIR}
for TYPE in dsa ecdsa ed25519 rsa; do
# ssh-key{gen,scan} are very smart and their outputs are not directly compatible, very cool
ssh-keyscan -t ${TYPE} ${HOST} | cut -d' ' -f 2- > ssh_host_${TYPE}_key.pub
if [ ! -s ssh_host_${TYPE}_key.pub ]; then
rm ssh_host_${TYPE}_key.pub;
fi
done
sudo ssh-keygen -s /etc/ssh/ca -h -I "${HOST}" -n "${HOST}" ./*
echo "signed keys for host ${HOST} in ${TMPDIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment