About Me

- A little contribution to the linux newbies.

Tuesday, June 15, 2010

Script to upload ssh key to skip password authentication



#!/bin/bash

## Script to auto upload ssh keys on the LINUX HOST

NO_ARGS=0
E_OPTERROR=65

if [ $# -eq "$NO_ARGS" ] # should check for no arguments
then
echo "Usage: `basename $0` -i "
exit $E_OPTERROR
fi

while getopts ":ih" Option

do
case $Option in

i)
remote_host_ipaddress="$2"
;;

h)
echo "Usage: `basename $0` -i "
exit $E_OPTERROR
;;
esac
done

shift $(($OPTIND - 1))

## This will generate ssh key on the remote host
echo "Generation ssh-keygen on remote linux host"
echo $remote_host_ipaddress

ssh root@$remote_host_ipaddress /usr/bin/ssh-keygen -t dsa

echo "uploading your ssh keys on remote linux host"
scp ~/.ssh/id_dsa.pub root@$remote_host_ipaddress:/root/.ssh/authorized_keys


No comments:

Post a Comment