Last active
January 3, 2016 14:29
-
-
Save sstelfox/8476231 to your computer and use it in GitHub Desktop.
A means to test whether or not the user has an SSH key installed for a remote system
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 | |
| USER=$1 | |
| HOST=$2 | |
| function test_ssh_key_setup() { | |
| ssh -q -q -o "BatchMode=yes" -o "ConnectTimeout 5" ${USER}@${HOST} "echo 2>1" | |
| [ $? ] && return 0 || return 1 | |
| } | |
| if [ -z "${USER}" ]; then | |
| echo "You need to provide a username for the remote host" | |
| exit 1 | |
| fi | |
| if [ -z "${HOST}" ]; then | |
| echo "You need to provide a hostname or IP for the sensor to update" | |
| exit 2 | |
| fi | |
| if [ ! $(test_ssh_key_setup) ]; then | |
| echo "Your SSH key doesn't appear to be installed for ${USER} on ${HOST}." | |
| echo "Please install your SSH key and run this script again." | |
| exit 3 | |
| fi | |
| # Do stuff on remote system with SSH safely knowing you won't be prompted for a password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment