Created
December 5, 2014 18:03
-
-
Save sergioccrr/235d41786377c274c27e to your computer and use it in GitHub Desktop.
Script for create and append SSH key in a remote server
This file contains 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/sh | |
FKEY="$HOME/.ssh/id_rsa" | |
FPUB="$FKEY.pub" | |
if [ ! -f "$FPUB" ]; then | |
echo 'Type your email, followed by [ENTER]:' | |
read COMMENT | |
ssh-keygen -t rsa -N '' -C "$COMMENT" -f "$FKEY" | |
fi | |
TPARENT="/tmp/$(basename $0)-$$" | |
TDIR="$TPARENT/.ssh" | |
mkdir -p "$TDIR" | |
if [ $? -ne 0 ]; then | |
echo 'fatal'; | |
exit | |
fi | |
TFILE="$TDIR/authorized_keys" | |
echo 'Type user of server, followed by [ENTER]:' | |
read SUSER | |
echo 'Type host of server, followed by [ENTER]:' | |
read SHOST | |
scp "$SUSER@$SHOST:~/.ssh/authorized_keys" "$TFILE" | |
if [ $? -ne 0 ]; then | |
touch "$TFILE" | |
fi | |
cat "$FPUB" >> "$TFILE" | |
scp -r "$TPARENT/." "$SUSER@$SHOST:~/" | |
rm "$TFILE" | |
rmdir "$TDIR" | |
rmdir "$TPARENT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment