Skip to content

Instantly share code, notes, and snippets.

@icook
Last active December 16, 2015 07:39
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 icook/5400173 to your computer and use it in GitHub Desktop.
Save icook/5400173 to your computer and use it in GitHub Desktop.
Simple script to easily add ssh local key to authorized_keys. Execute as mkautosh me@host1.com me@host2.com
#!/bin/bash
if [ -e ~/.ssh/id_rsa.pub ];
then
echo "SSH Key already exists on local machine"
else
echo "Generating SSH key on local machine"
ssh-keygen -t rsa
chmod -R 700 ~/.ssh
ssh-add
fi
echo "Loading client public key into memory"
value=$(<~/.ssh/id_rsa.pub)
for server
do
echo "Adding client public key to $server remote server authorized keys"
ssh $server "mkdir -p ~/.ssh; echo \"$value\" >> ~/.ssh/authorized_keys;
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"
done
echo "SSH keys schronized successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment