Skip to content

Instantly share code, notes, and snippets.

@kemelzaidan
Created September 17, 2014 22:04
Show Gist options
  • Save kemelzaidan/8559812b58461348be64 to your computer and use it in GitHub Desktop.
Save kemelzaidan/8559812b58461348be64 to your computer and use it in GitHub Desktop.
This is a simple bash script to reproduce ssh-copy-id behavior on the Mac OS, since this shit OS doesn't have it natively.
#!/bin/bash
# This is a simple shell script to reproduce ssh-copy-id behavior
# on the MAC, since that shit OS does not have it natively.
#
# This script is under GPL version 3
# Author: Kemel Zaidan
# email: kemelzaidan AT gmail DOT com
# website: kemelzaidan.com.br
#
## 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