Created
July 26, 2012 02:13
-
-
Save deanproctor/3179854 to your computer and use it in GitHub Desktop.
manage ssh keys via ldap groups
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/bash | |
declare -A LDAP_USERS | |
# | |
# Setup authorized_keys for users in groups assigned to this server | |
# | |
for GID in "$@" | |
do | |
USERS=$(ldapsearch -LLL -x -H ldap://ldap1.bos1 -b dc=bos1 "gidNumber=${GID}" uid | grep "uid: " | cut -f2 -d' ') | |
for USER in $USERS | |
do | |
HOME_DIR="/home/$USER" | |
if [ ! -e "$HOME_DIR/.ssh/authorized_keys" ]; then | |
echo mkdir -p $HOME_DIR/.ssh | |
echo chown -R $USER:$GID $HOME_DIR | |
echo wget -o $HOME_DIR/.ssh/authorized_keys https://raw.github.com/basho/ssh_keys/master/$USER | |
echo chmod 600 $HOME_DIR/.ssh/authorized_keys | |
fi | |
LDAP_USERS[$USER]="1" | |
done | |
done | |
# | |
# Remove authorized keys files from users not assigned to this server | |
# | |
LOCAL_USERS=$(ls /home) | |
for USER in $LOCAL_USERS | |
do | |
if [[ ! ${LDAP_USERS[$USER]+_} ]]; then | |
echo rm -f /home/$USER/.ssh/authorized_keys | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./ldap_authorized_keys.sh 5000 5001