blob: a0add9370814b5d9bef16a6da3d2df8618f5132d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/bin/sh
### Add RSA keys to the authorized_keys file of a given user
### Copyright (C) 2015 Rafael Laboissiere
###
### This program 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; either version 3 of the License, or (at your option) any later
### version.
###
### This program 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
### this program; if not, see <http://www.gnu.org/licenses/>.
### Get the program name
prog=${0##*/}
### Ensure that the correct number of arguments are given
if [ $# != 2 ] ; then
echo "Usage: $prog user file" 1>&2
exit 1
fi
### Get the input arguments and check their sanity
user=$1
rsaid=$2
ret=false
id -u $user >/dev/null 2>&1 && ret=true
if [ $ret = false ] ; then
echo "$prog:E: User $user does not exist. Add it first." 1>&2
exit 1
fi
type="OpenSSH RSA public key"
if [ "$(file --brief $rsaid)" != "$type" ] ; then
echo "$prog:E: File $rsaid is not of type '$type'." 1>&2
exit 1
fi
### Install the key(s)
home=$(getent passwd $user | cut -f6 -d:)
cat $rsaid >> $home/.ssh/authorized_keys
|