Export Your Public SSH Key

Adding a public SSH key to a Unix, Linux or other OpenSSH server is a bit of a tedious task; Copy the key, open a shell session, use your favorite text editor to paste the key in place. Unless you have a farm or a servers, it probably nothing more then a slight damper on your otherwise awesome day.

I wrote a simple script to make adding public RSA keys just a tad bit easier.


#!/bin/sh
# written by: Herman Griffin
# herman@hermangriffin.com

if [ ! $1 ];
then
echo "USAGE:"
echo " $0 USER@HOST";
echo " USER = SSH username";
echo " HOST = SSH server to export your public key to"
else
key_file=$(echo ~/.ssh/id_rsa.pub);
auth_file=".ssh/authorized_keys";
key=$(cat $key_file);

ssh $1 "touch $auth_file; chmod 644 $auth_file; echo $key >> $auth_file; tail -n1 $auth_file";
fi

Download it here.

Leave a Reply

Powered by WP Hashcash