Skip to content

Instantly share code, notes, and snippets.

@alex2006hw
Last active January 29, 2017 15:19
Show Gist options
  • Save alex2006hw/ec625a64121dcbf2f1481563f1dca5ee to your computer and use it in GitHub Desktop.
Save alex2006hw/ec625a64121dcbf2f1481563f1dca5ee to your computer and use it in GitHub Desktop.
ssh authorized me for remote access
# curl -L http://bit.ly/2kHM7oK
#20170129 : authorized_me
###########################
# gives you ssh access within a window of time
#
# To use:
# post your authorized_keys to github gist and use the raw output
# https://gist.githubusercontent.com/alex2006hw/5c5ee716b3b5dc35c6ff062a41f040de/raw/402554334033fd42d4a5d601973d5648d2ca2b51/id_rsa.pub
# shorten your key URL http://bit.ly/2kHz9HY
# update WINDOWTIME with the amount of time for the key to remain valid default = 15m
#
# usuage : authorized_me http://bit.ly/2kHz9HY
#
KEY=http://bit.ly/2kHz9HY
WINDOWTIME=15m
#
[ -f ~/.ssh/authorized_me_locked ] && echo "LOCK ERROR : please remove ~/.ssh/authorized_me_locked" && exit 1
DATE=$(date +%Y%m.%d.%s)
[ ! -z $1 ] && KEY=$1
[ ! -d ~/.ssh ] && mkdir -p ~/.ssh;chmod 700 ~/.ssh
[ ! -f ~/.ssh/authorized_keys ] && touch ~/.ssh/authorized_keys-${DATE}
[ -f ~/.ssh/authorized_keys ] && cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys-${DATE}
echo "" >> ~/.ssh/authorized_keys
curl -L ${KEY} >> ~/.ssh/authorized_keys
touch ~/.ssh/authorized_me_locked
# sleep for 15minutes then revert the changes
sleep ${WINDOWTIME}
[ -f ~/.ssh/authorized_keys-${DATE} ] && cp ~/.ssh/authorized_keys-${DATE} ~/.ssh/authorized_keys
[ -f ~/.ssh/authorized_me_locked ] && rm ~/.ssh/authorized_me_locked
@alex2006hw
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment