I often create new accounts or virtual machines, and then have to load my SSH public key/signature in to the authorized keys on that account. That process can be tedious, so I created this script that pushes my authorization on the remote machine. So, typically when you ssh to a remote machine you have to enter your password, etc. To automate jobs, though, you often don't want to do that, and key-based authentication allows you to authenticate without the password.
There are other ways to push keys around, but this makes it simple to fix things after the fact, or to initialize new accounts, etc.
I am looking for a review of any and all aspects, including the way that SSH is set up, and so on.
Here's an example transcript of what the script outputs:
panabox:~/bin> loadkey sol@solarium
Installing Key...
sol@solarium's password:
Checking Key ...
Great!
panabox:~/bin> loadkey sol@solarium
Already Works!
panabox:~/bin>
And here is the script:
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo "Must supply user@hostname: loadkey <user@hostname>"
exit 1
fi
host=$1
ssh -2 -o BatchMode=yes $host "echo hi" >& /dev/null && echo Already Works! && exit 0
echo Installing Key...
install="mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat - >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh -2 $host $install
echo Checking Key ...
ssh -2 -o BatchMode=yes $host "echo hi" >& /dev/null && echo Great! && exit 0
echo Failed to install key.
exit 2