SSH Login Without Password Using Keys on Mac

It feels better and gains desire to code when it’s easy to access your server via SSH with no IP limitation and password. Using public/private keys is a good way. And it’s easy!

Let’s say we have a Linux as a server and a Mac as a client where you do your work.

Connect to server via SSH On Mac

On the Mac (client)
  1. Open Terminal
  2. Go to .ssh directory: cd ~/.ssh

    if there isn’t a .ssh directory, cd ~ and then mkdir .ssh
  3. See if you already have a key pair by ls. (see if there are id_dsa and id_dsa.pub)

    If you do then vi id_dsa.pub and copy everything inside and :q to quit vi editor

    If you don’t then do ssh-keygen and enter, you’ll see something like this:> Generating public/private rsa key pair.

Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]

Enter passphrase (empty for no passphrase): [Press enter key]

Enter same passphrase again: [Pess enter key]

Your identification has been saved in /home/jsmith/.ssh/id_rsa.

Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.

The key fingerprint is:

33:b3:fe:af:95:e5:48:11:21:d5:de:96:2f:f2:35:f9 cccc@local-host

On the server
  1. Open authorized_keys in .ssh directory: vi ~/.ssh/authorized_keys
  2. Press i to edit, paste the content from id_dsa.pub, press esc to finish editing then save and quit using :wq

That’s it!

  • here‘s an advanced way to do this!