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.
- On the mac, make sure the user allows “Remote Login”. You’ll find this in Settings->Sharing
- 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)
- Open a bash commandline on the PC (Git Bash will do the job)
- ssh-keygen –t rsa
- press Enter until the command exits (passwords etc all blank)
- You now have a public key for the PC
- ssh to the mac
- ssh [user]@[IP] (in my case, ssh jenkins@JENKINS_SLAVE)
- 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
- Open another bash commandline on the PC
- cd to the directory where the id_rsa.pub was created. In my case: –
- cd /c/Users/andygreen/.ssh
- Copy the .pub to the mac
- scp ./id_rsa.pub jenkins@JENKINS_SLAVE:/Users/Shared/Jenkins/.ssh
- 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
- cd .ssh
- 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
One thought on “Setup a mac to allow ssh login without a password (PC to Mac in this example)”