Skip to content

Instantly share code, notes, and snippets.

@lwille
Created June 25, 2010 11:43
Show Gist options
  • Save lwille/452750 to your computer and use it in GitHub Desktop.
Save lwille/452750 to your computer and use it in GitHub Desktop.
Establish a passwordless SSH connection between your Mac and your server
#!/bin/sh
host="yourhost.de"
port="3344"
user="root"
bold="\033[1;30m"
reset="\033[0m"
echo "Please follow the instructions:"
ssh-keygen -t dsa
key=~/.ssh/id_dsa.pub
echo "Enter path of generated file"
echo "(press enter for $bold$key$reset):\c"
read newkey
if [ -n "$newkey" ]; then
key="$newkey"
fi
echo "copying keys ..."
scp -P $port $key $user@$host:~/authorized.key
ssh $user@$host -p $port 'cat ~/authorized.key >> ~/.ssh/authorized_keys;rm ~/authorized.key'
echo "Establishing test connection (you should be asked for your "$bold"Passphrase"$reset" instead of the SSH password)"
ssh -p $port -l $user $host
@lwille
Copy link
Author

lwille commented Nov 29, 2010

This script will generate a new private key and save it in your user folder. It then copies the new key to your host via SCP and appends it to ~/.ssh/authorized_keys.

Beware: If you should choose not to enter a Passphrase for your key (if you do, you could save it to your Keyring to avoid getting prompted each time the key is accessed), anyone can access your machine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment