MacOS SSH connect using key
For a detailed explanation of what's going on see SSH Agents. Halfway through the page you'll find SSH Agent on OS X & macOS.
See also Apple's Technical Note TN2449 - OpenSSH updates in macOS 10.12.2
You have to add some lines to your config file:
# enable integration between Keychain and SSH Agent
UseKeychain yes
AddKeysToAgent yes
Once you have done that, I think you will be asked for your password the first time you ssh into your server. After that it will use the keys you provided.
So your config file should look like this:
Host alias
HostName host
User user_name
IdentityFile ~/.ssh/id_rsa
# enable integration between Keychain and SSH Agent
UseKeychain yes
AddKeysToAgent yes
To connect using SSH keys you need to copy the key from your machine to the remote server using ssh-copy-id user@remote_ip_address
.
You will be asked to enter the password for the remote server and the key will be copied.
If you generated a key pair using a password then you will always have to enter that password when connecting. If not, you can simply connect using ssh user@remote_ip_address
and you will be connected to the remote machine.
Are the permissions of authorized_keys correct? Should be 400 owned by the user.
Check the logs of the remote server, usually helpful to debug auth issues on SSH.