Skip to content

Instantly share code, notes, and snippets.

@chaseroden
Created September 3, 2014 13:27
Show Gist options
  • Save chaseroden/a108fa58324cf4349cf5 to your computer and use it in GitHub Desktop.
Save chaseroden/a108fa58324cf4349cf5 to your computer and use it in GitHub Desktop.
Adds ssh key to remote server
#!/bin/sh
# ./add-key.sh <keyfile> <remote server>
# First argument is the key file
# Second argument is the server name or IP
# To do: check remote server to see if the key's already there first
scp $1 $2:.ssh/new_key
ssh $2 /bin/bash << EOF
cd .ssh
cp authorized_keys authorized_keys.bak
cat new_key >> authorized_keys
cat authorized_keys
rm new_key
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment