We want to be able to login to a mac using ssh but don’t want to type a password every time. This is done by allowing Remote Login for a given user on the Mac and adding a public key to the Mac for the PC you’re logging in from.

  1. On the mac, make sure the user allows “Remote Login”. You’ll find this in Settings->Sharing
    1. Tick “Remote Login” and make sure the user you’re logging in as is included in the list on the right (click the ‘+’ if not)
  2. Open a bash commandline on the PC (Git Bash will do the job)
    1. ssh-keygen –t rsa
    2. press Enter until the command exits (passwords etc all blank)
  3. You now have a public key for the PC
  4. ssh to the mac
    1. ssh [user]@[IP] (in my case, ssh jenkins@JENKINS_SLAVE)
    2. Make sure you have a .ssh directory in the home directory (the one that you’re in straight after logging in). If not, mkdir .ssh
  5. Open another bash commandline on the PC
    1. cd to the directory where the id_rsa.pub was created. In my case: –
    2. cd /c/Users/andygreen/.ssh
    3. Copy the .pub to the mac
      1. scp ./id_rsa.pub jenkins@JENKINS_SLAVE:/Users/Shared/Jenkins/.ssh
    4. Go back to the bash session that’s logged into the Mac and copy the public key to an “authorized_keys” file so it’ll be checked when logging in
      1. cd .ssh
      2. cat id_rsa.pub >> authorized_keys

That should do it. The next ssh jenkins@JENKINS_SLAVE will login without asking for a password

Also, worth noting that Sierra or above will need to be a 2048 bit rsa or they won’t work. See here for more info