Finely Cultured Eric Danielson's Personal Blog

2Nov/090

Quick script: Easy passwordless SSH setup

This is a quick one - I work almost entirely on remote servers via SSH & SFTP at this point, so passwordless SSH is a huge timesaver. The setup is easy, but it's a few steps and I always forget how to do it. I threw together this bash script to make it easier - to use it, run:

./passless.sh (username) (server)

The Code:

#! /usr/bin/env bash
MINPARAMS=2
if [ $# -lt "$MINPARAMS" ]
then
  echo
  echo "This script needs at least $MINPARAMS command-line arguments!"
  exit 2
fi
USER=$1
SERVER=$2
echo "---"
echo "Step 1: Generating RSA Key - Accept the default location & don't enter a password."
echo "---"
if [ -f ~/.ssh/id_rsa ]
then
echo "RSA Key already exists."
else
ssh-keygen -t rsa
fi
echo "---"
echo "Step 2: Creating the .ssh directory on the remote server."
echo "---"
ssh ${USER}@${SERVER} mkdir -p .ssh
echo "---"
echo "Step 3: Copying the ssh key to the remote server."
echo "---"
cat .ssh/id_rsa.pub | ssh ${USER}@${SERVER} 'cat >> .ssh/authorized_keys'
echo "---"
echo "Done! You should be able to log in now."
echo "---"

About Eric Danielson

No description. Please complete your profile.
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Pages

Categories

Blogroll

Archive

Meta