Skip to content

Instantly share code, notes, and snippets.

@jowr
Last active August 29, 2015 14:01
Show Gist options
  • Save jowr/845b43cd92659a537b94 to your computer and use it in GitHub Desktop.
Save jowr/845b43cd92659a537b94 to your computer and use it in GitHub Desktop.
enable passwordless login
#!/bin/bash
# TODO: Check if public keys exist
#
echo "You are about to enable a passwordless login."
echo "Please provide the following information: (hit enter)"
read -p "Target hostname: " HOST
read -p "Target username: " USER
echo -n "Checking for public keys..."
#
FOUND=""
if [ -f $HOME/.ssh/id_rsa.pub ]; then
echo " ...found in $HOME/.ssh/id_rsa.pub"
FOUND="$HOME/.ssh/id_rsa.pub"
else
if [ -f $HOME/.ssh/id_dsa.pub ]; then
echo " ...found in $HOME/.ssh/id_dsa.pub"
FOUND="$HOME/.ssh/id_dsa.pub"
else
echo " ...could not find either $HOME/.ssh/id_dsa.pub or $HOME/.ssh/id_rsa.pub"
echo "Please run: \"ssh-keygen -t rsa\" and try again"
exit 1
fi
fi
#
echo "Connecting to host $HOST: "
cat $FOUND | ssh $USER@$HOST "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
echo "Thank you, you should be able to login now by typing:"
echo "ssh $USER@$HOST"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment