Skip to content

Instantly share code, notes, and snippets.

@michaelstephens
Last active April 20, 2016 18:23
Show Gist options
  • Save michaelstephens/ebc5ba548c37841196edc2c787985d23 to your computer and use it in GitHub Desktop.
Save michaelstephens/ebc5ba548c37841196edc2c787985d23 to your computer and use it in GitHub Desktop.
#!/bin/bash
# This is a script that checks for encryption on your ssh key
# Its purpose is to verify the security of your keys
# It also will help you encrypt your current ssh key should you desire
while [[ ! -f $ssh_key ]]; do
echo -n "Enter the path to your private ssh key ($HOME/.ssh/id_rsa): "
read user_input
if [[ -n "$user_input" ]]; then
ssh_key=$user_input
else
ssh_key="$HOME/.ssh/id_rsa"
fi
if [[ ! -f $ssh_key ]]; then
echo "Could not locate file. Please user format: $HOME/location/to/your_ssh_key and verify the file exists."
fi
done
echo "Using $ssh_key"
if [[ $(grep ENCRYPTED $ssh_key) ]]; then
echo "Success! You have an encrpyted ssh key!"
else
echo "Uh oh. Looks like you don't have an encrypted ssh key."
echo -n "Would you like to fix that by adding a password? [Y/N]: "
read user_input
if [ $user_input == 'Y' ] || [ $user_input == 'y' ]; then
echo "Awesome! Please follow the commands:"
ssh-keygen -p -f $ssh_key
echo "ssh-agent makes it so your password is only required once."
ssh-agent
else
echo "Ok thank you for running the script. Quitting..."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment