Last active
December 16, 2015 07:39
-
-
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 [email protected] [email protected]
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/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