MacOS – Passwordless SSH between MacOS and MacOS not working

authenticationmacosssh

I know there are many tutorials, including instructions on this forum but I find that SSH still asks me for a password.

Here is what I tried on the local machine:

ssh-keygen -t rsa                   #   Generate Key Pair, accepting all defaults
ssh-copy-id me@192.168.1.235        #   Copy to remote
ssh me@192.168.1.235                #   Still asks for password

I have also tried with a custom key:

ssh-keygen -t rsa -f ~/.ssh/test.rsa
ssh-copy-id -i ~/.ssh/test.rsa.pub me@192.168.1.235
ssh-add ~/.ssh/test.rsa
ssh -i ~/.ssh/test.rsa me@192.168.1.235

In the remote host, I have changed the privileges to authorized_keys:

chmod 600 authorized_keys

I have tried all the variations to copy the key to the remote server, but they all give me the same results, and the authorized_keys file has the same new key.

Many of the tutorials are several years old, and some are for linux, so I don’t know whether things should be different.

Is there an extra step I need to take to use SSH without a password?

I am on MacOS Catalina.

Update

I have turned on verbosity, and I get something like this:

debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/me/.ssh/test.rsa RSA SHA256:…etc…
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/mark/.ssh/test.rsa RSA SHA256:…etc… explicit
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive

Best Answer

If you tell your config file about the setup it will work.

Open ~/.ssh/config

Add this:

Host whateverYouWannaCallIt
  Hostname      192.168.1.235
  User          me
  IdentityFile  ~/.ssh/id_rsa

Then you can do this:

ssh whateverYouWannaCallIt

I recommend when creating the ssh key, to not use a generic one and give it a name for the machine, so one key per computer. You don't want to use the same key for more than one machine... but that's what will happen if you keep using id_rsa.

So as step one, do something more like this:

ssh-keygen -t rsa -b 3072 -f ~/.ssh/theServersName.rsa
...
ssh-copy-id -i ~/.ssh/theServersName.rsa.pub me@192.168.1.235

Then point IdentityFile to the right place:

Host theServersName
  Hostname      192.168.1.235
  User          me
  IdentityFile  ~/.ssh/theServersName.rsa