Skip to content

Instantly share code, notes, and snippets.

@WalterInSH
Created July 11, 2016 04:37
Show Gist options
  • Save WalterInSH/b17917ab5e44448eb356ce24fc734311 to your computer and use it in GitHub Desktop.
Save WalterInSH/b17917ab5e44448eb356ce24fc734311 to your computer and use it in GitHub Desktop.
add a ssh key on servers
#!/bin/sh
SSH_KEY="key"
if [ -f ~/.ssh/authorized_keys ] && [ $(grep -c "$SSH_KEY" ~/.ssh/authorized_keys) -gt 0 ]; then
echo "ssh key exists"
else
if [ -f ~/.ssh/authorized_keys ]; then
cp ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak
fi
printf "\n$SSH_KEY" >> ~/.ssh/authorized_keys
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment