#!/bin/sh # GrantAuthorizedKey.sh # Tue Jun 16 21:26:50 PDT 2009 # Chieh Cheng # http://www.CynosureX.com/ # GNU General Public License (GPL) Version 2, June 1991 scriptName=`basename "$0"` function outputError () { msg="$1" echo "Error: ${msg}" } function usage () { echo " Usage: ${scriptName} \"public key file\"" echo echo " On success, this script outputs the key name that can" echo " be used to revoke the public key (see" echo " RevokeAuthorizedKey.sh). On failure, this script outputs" echo " an error message that is prefixed with \"Error:\"." echo " Therefore, you can use the prefix to test for success or" echo " failure." } if [ $# -eq 1 ] then publicKeyFile="$1" keyDir="${HOME}/.ssh" keyFile="${keyDir}/authorized_keys" if [ -f "${publicKeyFile}" ] then if [ ! -d "${keyDir}" ] then mkdir "${keyDir}" fi publicKey=`cat "${publicKeyFile}" | head -1` keyName=`echo "${publicKey}" | Token.sh 3` if [ "${keyName}" = "" ] then outputError "Invalid public key!" else echo "${publicKey}" >> "${keyFile}" echo "${keyName}" fi else outputError "${publicKeyFile} not found!" fi else usage fi