Toss this little shell script in your bin dir and you can quickly create and setup ssh keys between your client and server. I called it sshkeys.sh but you can name it what you want.

#!/bin/bash

KEY_PRIVATE="$HOME/.ssh/id_dsa"
KEY_PUBLIC="${KEY_PRIVATE}.pub"

if [ "$1" == "" ] ; then
   echo "Usage: $0 <[user@]server>"
   exit
fi

if [ ! -f "${KEY_PRIVATE}" ] ; then
   echo Creating the private and public keys.
   ssh-keygen -t dsa -f "${KEY_PRIVATE}" -N ''
fi

if [ -f "${KEY_PUBLIC}" ] ; then
   cat "${KEY_PUBLIC}" |
   ssh "${1}" "mkdir -p ~/.ssh ; cat >> .ssh/authorized_keys2 ; chmod -R go-rwx ~/.ssh"
else
   echo Unable to find "${KEY_PUBLIC}"
fi

Run this, enter your pass once, and then you’re free to ssh without entering a password.

Watch for line wraps in your browser, especially the ssh line.

Related posts:

  1. parsing some xml
  2. BASH: Split a string without ‘cut’ or ‘awk’
  3. read a file with bash
  4. Stompbox: HowTo Switch to Sprint Merlin S620 Linux
  5. functions and error handling