Last Updated: November 06, 2018
·
1.163K
· infoslack

Manage public keys on the server with gist

The github offers a nice view to the public keys of the users, simple feature: https://github.com/infoslack.keys.

Thinking about it I created a simple script to collect a list of users starting a private gist and add their respective public keys to the authorized_keys:

#!/bin/sh

URL="RAW_URL_PRIVATE_GIST"
TMP="/tmp/authorized_keys_dl"
ERR="/dev/null 2>&1"

mkdir -pm 700 ~/.ssh > $ERR

for user in $(curl --silent $URL)
do
  curl -s "https://github.com/"$user".keys" -w "\n" >> $TMP
done

mv -f $TMP ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys > $ERR

The script can be added to cron and the gist would be a whitelist containing the list of users who will access the server:

user_1
user_2
user_3...

Happy Hacking ;)