Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / bin / | server ip : 172.67.156.115 your ip : 172.70.80.62 H O M E |
Filename | /usr/bin/ssh-import-id-gh |
Size | 2.07 kb |
Permission | rwxr-xr-x |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 27-Feb-2014 23:42 |
Last accessed | 05-Jul-2025 15:55 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
#! /usr/bin/python
#
# ssh-import-id - Authorize SSH public keys from trusted online identities.
#
# Copyright (c) 2013 Casey Marshall <[email protected]>
# Copyright (c) 2013 Dustin Kirkland <[email protected]>
#
# ssh-import-id is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# ssh-import-id is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ssh-import-id. If not, see <http://www.gnu.org/licenses/>.
import os
import json
import subprocess
import sys
try:
import requests
# Only versions >= 1.1.0 support SSL certificate verification
if requests.__version__ >= '1.1.0':
REQUESTS = True
else:
REQUESTS = False
except:
REQUESTS = False
try:
from urllib import quote_plus
except (ImportError,):
from urllib.parse import quote_plus
if __name__ == '__main__':
if not sys.argv[:1]:
sys.stderr.write("Usage: %s <github-id>\n" % (sys.argv[0]))
os._exit(1)
for ghid in sys.argv[1:]:
try:
url = "https://api.github.com/users/%s/keys" % (quote_plus(ghid))
if REQUESTS:
text = requests.get(url, verify=True).text
else:
# Fall back to using good 'ole ubiquitous wget
p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
sys.stderr.write(stderr.decode('utf-8'))
if p.returncode == 0:
text = stdout.decode('utf-8')
else:
raise Exception("Could not fetch URL [%s]" % url)
data = json.loads(text)
for keyobj in data:
sys.stdout.write("%s %s@github/%s\n" % (keyobj['key'], ghid, keyobj['id']))
sys.stdout.flush()
except (Exception,):
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s\n" % (str(e)))
os._exit(1)
sys.stdout.write("\n")
os._exit(0)
#
# ssh-import-id - Authorize SSH public keys from trusted online identities.
#
# Copyright (c) 2013 Casey Marshall <[email protected]>
# Copyright (c) 2013 Dustin Kirkland <[email protected]>
#
# ssh-import-id is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# ssh-import-id is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ssh-import-id. If not, see <http://www.gnu.org/licenses/>.
import os
import json
import subprocess
import sys
try:
import requests
# Only versions >= 1.1.0 support SSL certificate verification
if requests.__version__ >= '1.1.0':
REQUESTS = True
else:
REQUESTS = False
except:
REQUESTS = False
try:
from urllib import quote_plus
except (ImportError,):
from urllib.parse import quote_plus
if __name__ == '__main__':
if not sys.argv[:1]:
sys.stderr.write("Usage: %s <github-id>\n" % (sys.argv[0]))
os._exit(1)
for ghid in sys.argv[1:]:
try:
url = "https://api.github.com/users/%s/keys" % (quote_plus(ghid))
if REQUESTS:
text = requests.get(url, verify=True).text
else:
# Fall back to using good 'ole ubiquitous wget
p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
sys.stderr.write(stderr.decode('utf-8'))
if p.returncode == 0:
text = stdout.decode('utf-8')
else:
raise Exception("Could not fetch URL [%s]" % url)
data = json.loads(text)
for keyobj in data:
sys.stdout.write("%s %s@github/%s\n" % (keyobj['key'], ghid, keyobj['id']))
sys.stdout.flush()
except (Exception,):
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s\n" % (str(e)))
os._exit(1)
sys.stdout.write("\n")
os._exit(0)