Skip to content

Instantly share code, notes, and snippets.

@rmueck
Created March 11, 2020 12:16
Show Gist options
  • Save rmueck/3528fefa80751e4679b7fa369e6558cb to your computer and use it in GitHub Desktop.
Save rmueck/3528fefa80751e4679b7fa369e6558cb to your computer and use it in GitHub Desktop.
ssh-copy-id script
#!/bin/bash
## VARIABLES
SSH_PUB_KEY=~/.ssh/id_rsa.pub
USER=$1
HOST=$2
# exit if no atributes were passed
if [ $# -eq 0 ]; then
echo ""
echo "Please, type ssh-copy-id USER HOST"
echo ""
exit 1
fi
# test if there is a SSH public key
if [ ! -f $SSH_PUB_KEY ]; then
echo 'No public SSH key found!'
exit 1
fi
cat $SSH_PUB_KEY | ssh $USER@$HOST "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
# exit if successfull
echo ""
echo "Key successfully copied to the server"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment