Skip to content

Instantly share code, notes, and snippets.

@fjallstrom
Last active April 27, 2016 15:50
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 fjallstrom/006de119849ccf778e9ca8ed889d9911 to your computer and use it in GitHub Desktop.
Save fjallstrom/006de119849ccf778e9ca8ed889d9911 to your computer and use it in GitHub Desktop.
<?php
# import github keys
$ch = curl_init('https://api.github.com/orgs/EarthPeople/members');
curl_setopt($ch, CURLOPT_USERPWD, "XXX:XXX");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT,'EpBot');
$users = @json_decode(curl_exec($ch));
curl_close($ch);
echo "found ".count($users)." users in organisation\n";
if($users){
foreach($users as $user => $params){
echo "user: ".$params->login."\n";
$keys[] = file_get_contents('https://github.com/'.$params->login.'.keys');
}
}
echo "found ".count($keys)." keys\n";
if(count($users) === count($keys)){
file_put_contents('/root/.ssh/authorized_keys', implode($keys, "\n"));
echo "imported to keys to ~/.ssh/authorized_keys\n";
}else{
echo "error, could not fetch keys for all users\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment