% ./bin/hgapp-keys -h
Usage: hgapp-keys [options]
Options:
-h, --help show this help message and exit
-u USER, --user=USER user id
-n NAME, --name=NAME name associate to ssh key
-k KEY, --key=KEY path to an ssh pub key to add at NAME for USER
-d, --delete delete key NAME for USER
-l, --list list ssh keys
-r, --regen regen authorized_keys file
If you want to add a ~user/.ssh/authorised_keys file:
$ sudo su -
# HOME=/home/hgapp /home/hgapp/bin/hgapp-key -u user -k ~user/.ssh/authorised_keys
This will add all keys found in the authorised_keys file.
SSH key stuff
>>> HGAPP_AUTHORIZED_KEYS = '/tmp/hgapp_keys'
>>> os.environ['HGAPP_AUTHORIZED_KEYS'] = HGAPP_AUTHORIZED_KEYS
Create user dir:
>>> user_dir('gawel')
'/tmp/hgapp_keys/gawel'
>>> isdir(join(HGAPP_AUTHORIZED_KEYS, 'gawel'))
True
>>> users()
['gawel']
Add a key to the user:
>>> keys = add_key('gawel', 'test_key', StringIO('ssh-dss %s= gael@hostname' % ('AAA'*255,)))
>>> isfile(join(HGAPP_AUTHORIZED_KEYS, 'gawel', 'test_key.pub'))
True
>>> print open(keys[0]).read() #doctest: +ELLIPSIS
ssh-dss AAA...A=
Get user keys:
>>> user_keys('gawel') #doctest: +ELLIPSIS
{'test_key': 'ssh-dss AAAAAAAAAAAAA...AAAAAAAA='}
Add another key:
>>> keys = add_key('gawel', None, StringIO('ssh-dss %s= gael@hostname2' % ('AAA'*255,)))
Gen key file:
>>> filename = join(HGAPP_AUTHORIZED_KEYS, 'authorized_keys')
>>> authorized_keys(filename)
>>> print open(filename).read() #doctest: +ELLIPSIS
command="/...bin/hgapp-ssh -u gawel",no-port-forwarding,no-agent-forwarding,no-X11-forwarding ssh-dss AAAA...AAAAAA= gael@hostname2
command="/...bin/hgapp-ssh -u gawel",no-port-forwarding,no-agent-forwarding,no-X11-forwarding ssh-dss AAAA...AAAAAA= test_key
<BLANKLINE>
Del a key:
>>> del_key('gawel', 'test_key')
>>> isfile(join(HGAPP_AUTHORIZED_KEYS, 'gawel', 'test_key.pub'))
False
Del a user:
>>> del_user('gawel')
>>> isdir(join(HGAPP_AUTHORIZED_KEYS, 'gawel'))
False
>>> shutil.rmtree(HGAPP_AUTHORIZED_KEYS)