ssh-copy-id missing in OS X

Not sure if anyone else has noticed, but OS X is missing ssh-copy-id. This utility is included with the ssh client in most major linux distros. As it turns out, it is just a shell script.


# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.


if [ "-i" = "$1" ]; then
  # check if we have 2 parameters left, if so the first is the new ID file
  if [ -n "$2" ]; then
    if expr "$1" : ".*\.pub" > /dev/null ; then
    shift         # and this should leave $1 as the target name
  if [ x$SSH_AUTH_SOCK != x ] && ssh-add -L >/dev/null 2>&1; then
    GET_ID="$GET_ID ssh-add -L"

if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
  GET_ID="cat ${ID_FILE}"

if [ -z "`eval $GET_ID`" ]; then
  echo "$0: ERROR: No identities found" >&2
  exit 1

if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
  exit 1

{ eval "$GET_ID" ; } | ssh ${1%:} "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1

cat <<EOF
Now try logging into the machine, with "ssh '${1%:}'", and check in:


to make sure we haven't added extra keys that you weren't expecting.


Go forth, copy, paste, chmod and happily deploy your ssh keys with ease.

P.S. For those who don’t know what I mean by chmod, see the following.

chmod +x ./ssh-copy-id

2 thoughts on “ssh-copy-id missing in OS X

  1. What is wrong with scp .ssh/authorized_keys host:~./ssh/ ? I mean even on Linux this is how I have always done it. Oh well many ways to the same outcome. I guess we can all be happy 🙂

    • There is nothing particularly wrong with it, I just prefer how ssh-copy-id behaves by default when the .ssh directory doesn’t exist or when there may be other keys in the authorized_keys file already.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s