Skip to content

Instantly share code, notes, and snippets.

@petertoi
Last active August 29, 2015 14:14
Show Gist options
  • Save petertoi/24b598eb269fac767cc7 to your computer and use it in GitHub Desktop.
Save petertoi/24b598eb269fac767cc7 to your computer and use it in GitHub Desktop.
Upload local id_rsa.pub to remote .ssh/authorized_keys
#!/bin/sh
#
# Author: Peter Toi
# Source: https://gist.github.com/petertoi/24b598eb269fac767cc7
#
# Usage 1: $ sshkey2remote.sh # No argument will result in prompts
# Usage 2: $ sshkey2remote.sh user@host # Skip the prompts by including the argument
if [ "$#" -eq 1 ]
then
userhost=$1
else
echo "Remote User: "
read user
echo "Remote Host: "
read host
userhost=$user@$host
fi
([ -f ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa ) && (ssh $userhost "([ -d ~/.ssh ]||mkdir -m 700 ~/.ssh) && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment