Skip to content

Instantly share code, notes, and snippets.

@massenz
Created August 16, 2013 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save massenz/6247539 to your computer and use it in GitHub Desktop.
Save massenz/6247539 to your computer and use it in GitHub Desktop.
Having to type a thousand times the password when SSH'ing into a server commonly used is a pain: the obvious solution is to use key-based auth - this is a handy script that takes out even the effort of having to remember (not to mention) type up every time the same set of commands. You will have to enter the password to the remote host twice, bu…
#!/bin/bash
#
# Copies the PUB key to a server via SCP then adds it to
# .ssh/authorized_keys.
#
# Must be invoked like this:
# scp-pub-remote.sh user@server
declare -r REMOTE=$1
if [ -z $REMOTE ]; then
echo "Must be invoked with username@server as the one and only argument"
exit 1
fi
scp $HOME/.ssh/id_rsa.pub $REMOTE:
if [ $? == 0 ]; then
ssh $REMOTE "if [ ! -e .ssh ];then mkdir .ssh;fi && cat id_rsa.pub >> .ssh/authorized_keys"
echo 'Public key copied to ' $REMOTE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment