Installing ssh-copy-id on MAC and connect through SSH without password

Update September, 1st 2014

The newer versions of port does not include the ssh-copy-id package anymore, but you can still use it cloning this repo from Github: https://github.com/beautifulcode/ssh-copy-id-for-OSX

Hello everybody! I have some servers and always I have to login using SSH, but some passwords is very complex. So, you must copy your public key to the desired server and be happy.

Installing the command ssh-copy-id

I used to use mac ports to install packages on my Mac, so: sudo port install ssh-copy-id Now you have the command installed on /opt/local/bin/ssh-copy-id. Just create a symbolic link to that: sudo ln -s /opt/local/bin/ssh-copy-id /usr/bin/ssh-copy-id

Copying your public key to server

Now you only have to run the command and be happy! The server will ask for password, and this will be the last time you type the code!

ssh-copy-id -i ~/.ssh/id_rsa.pub username@example.com
This way you'll registering your public key for the "username" user at "example.com" server.

Alternative way

You can too copy your id_rsa.pub file content, login inside the server and append the file content to /home/username/.ssh/authorized_keys. The effect will be the same, but I think using ssh-copy-id is easier and quickly. Now when you try to login to server using ssh, like ssh username@example.com you’ll have direct access! Thank you!

Update Oct 9 2013

An easy way to do that, without install nothing:

Check if id_rsa.pub exists

ssh-copy-id -i ~/.ssh/id_rsa.pub username@example.com
This way you'll registering your public key for the "username" user at "example.com" server.

If you found id_rsa.pub go to the next topic. If not do the following to create one public key:

cd ~/.ssh 
ssh-keygen -t rsa -C "your_email@example.com"
  • Creates a new ssh key, using the provided email as a label
  • Generating public/private rsa key pair.
  • Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

After that:

ssh-add id_rsa

Copying your public key to remote server

cat ~/.ssh/id_rsa.pub | ssh user@example.org 'cat >> /home/user/.ssh/authorized_keys'

Done!

Published by

Junior Grossi

senior software engineer & stutterer conference speaker. happy husband & dad. maintains Corcel PHP, elePHPant.me and PHPMG. Engineering Manager @ Paddle

4 thoughts on “Installing ssh-copy-id on MAC and connect through SSH without password”

Leave a Reply

Your email address will not be published. Required fields are marked *