Last active
March 14, 2020 18:13
-
-
Save leoheck/a9436a1661089eeb8e4ead8fde025b45 to your computer and use it in GitHub Desktop.
Script to launch a remote browser to authenticate a host on PUCRS network
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 | |
# By Leandro Heck ([email protected]) | |
# Add this script in your .bashrc (or .zshrc) or source it like: | |
# $> source autenticate_pucrs.sh | |
# Usage examples: | |
# 1. Authenticate using same network user | |
# $> authenticate_host lheck gaphl12 | |
# 2. Autenticate using different users | |
# $> authenticate_host lheck:leo gaphl12 | |
# 3. Autenticate using different users and ip address | |
# $> authenticate_host lheck:leo 10.32.10.134 | |
authenticate_host() | |
{ | |
user=$1 | |
host=$2 | |
if ! which sshpass > /dev/null 2>&1; then | |
echo "\nMissing sshpass (install it)\n" | |
return 1 | |
fi | |
if [[ $# != 2 ]]; then | |
echo -e "\nUSAGE: authenticate_host <KRITI_USER>[:HOST_USER] <HOSTNAME|IP>\n" | |
return 1 | |
fi | |
user1=$(cut -d":" -f1 <<< $user) | |
user2=$(cut -d":" -f2 <<< $user) | |
echo -n "password for $user1@kriti: " | |
read -s pass1 | |
echo | |
if [[ $user1 != $user2 ]]; then | |
echo -n "password for $user2@$host: " | |
read -s pass2 | |
echo | |
else | |
pass2=$pass1 | |
fi | |
echo 'conneting kriti...'; \ | |
sshpass -p "$pass1" ssh -C [email protected] -p 8888 -Y " \ | |
echo \"conneting $host...\"; \ | |
sshpass -p \"$pass2\" ssh -C $user2@$host -Y ' \ | |
echo 'launching authentication page...'; \ | |
firefox -new-instance https://gwpolicy02.pucrs.br/ 2> /dev/null &'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment