From 01cb2d675103283664e0a870818cfc413f546b37 Mon Sep 17 00:00:00 2001 From: Rafael Laboissiere Date: Sat, 9 May 2015 10:42:34 +0200 Subject: Initial commit --- add-authorized-keys | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 add-authorized-keys (limited to 'add-authorized-keys') diff --git a/add-authorized-keys b/add-authorized-keys new file mode 100755 index 0000000..a0add93 --- /dev/null +++ b/add-authorized-keys @@ -0,0 +1,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 . + +### 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 -- cgit v1.2.3