Skip to content

Instantly share code, notes, and snippets.

@wpalmer
Created January 27, 2011 00:09
Show Gist options
  • Save wpalmer/797803 to your computer and use it in GitHub Desktop.
Save wpalmer/797803 to your computer and use it in GitHub Desktop.
set gitolite keys based on existing users
#!/bin/bash
dir="$(mktemp -t -d "vcs-keys.XXXXXXXXXX")"
function _cleanup(){
rm -rf "$dir"
}
trap _cleanup EXIT
while read passwd; do
user="$(printf "%s" "$passwd"|cut -d: -f1)"
home="$(printf "%s" "$passwd"|cut -d: -f6)"
shell="$(printf "%s" "$passwd"|cut -d: -f7)"
[ "${home#/home/}" = "$home" ] && continue
[ "$shell" = "/bin/bash" -o "$shell" = "/bin/sh" ] || continue
for keys in "$home/.ssh/authorized_keys" "$home/.ssh/authorized_keys2"; do
[ -e "$keys" ] && break
done
[ -e "$keys" ] || continue
n=0
while read -r key; do
n=$(( $n + 1 ))
printf "%s\n" "$key" > "${dir}/${user}@authorized_keys-${n}.pub"
done < <(grep '^ssh-' "$keys")
done < /etc/passwd
chown -R vcs "$dir" &&
cd /home/vcs &&
su -l -c '/home/vcs/bin/gl-setup-authkeys -batch '"$dir" vcs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment