Last active
August 29, 2015 14:01
-
-
Save jowr/845b43cd92659a537b94 to your computer and use it in GitHub Desktop.
enable passwordless login
This file contains hidden or 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/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