Created
June 25, 2010 11:43
-
-
Save lwille/452750 to your computer and use it in GitHub Desktop.
Establish a passwordless SSH connection between your Mac and your server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!