Last active
September 23, 2019 20:18
-
-
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
This file contains hidden or 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 | |
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