This guide goes through setting up SSH keys on macOS Mojave 10.14 back to Mac OSX 10.11 and also a secure password-less SSH connection between a local macOS workstation and a remote server also running a Linux variant operating system.The process requires generating a public and private key on the local computer and then adding the public key to the remote servers authorised list. What is great about this is that it allows a password prompt free session, handy for a lot of uses.First thing that you need to do on your macOS machine is to create a directory that will store your SSH keys. Then you will generate a public and private key for your account, launch the Terminal and punch in some commands: Create a.ssh DirectoryChange to the home directory cd /Create a SSH directory name.ssh and move into it mkdir.ssh; cd.sshMake sure that the file permissions are set to read/write/execute only for the user chmod go-rwx.sshCreate your private and public key, the blank quotes at the end of the command gives the private key no password, so allowing for passwordless logins! Ssh-keygen -b 1024 -t rsa -f idrsa -P '. Keygen-generate-ssh-keysChange into the.ssh directory and list the contents of that.ssh directory cd.ssh; ls -la -rw- 1 username staff 887B Jun 1 11:35 idrsa-rw-r-r- 1 username staff 239B Jun 1 11:35 idrsa.pubThats your SSH keys created, the private key is the idrsa and the public one is the idrsa.pub, don’t give out the private one always keep that one only on your local machine.
![](/uploads/1/2/6/5/126541477/534168988.jpg)
Sharing the Public KeyCreate an authorizedkeys in the.ssh directory of the remote computer that you want to connect to.
![Startup Startup](/uploads/1/2/6/5/126541477/173296321.png)
Saving SSH keys in macOS Sierra keychain Source links.ProblemAs described in detail on, macOS/OS X till Yosemite used to remember SSH keys added by command ssh-add -K.Unfortunately this way no longer works. Keys added to the keychain via ssh-add -K are not automatically re-added to the ssh-agent after a reboot. As Apple Developer stated:'That’s expected.
Making Pageant automatically load keys on startup So I have a few private keys I generated for Public-Key SSH authentication. In Windows I manage SSH keys with Pageant - an SSH authentication agent for PuTTY.
We re-aligned our behavior with the mainstream OpenSSH in this area.' Solutions Solution 1 (recommended)Apple updated its to indicate that since 10.12.2, macOS includes version 7.3p1 of OpenSSH and its new behaviors.In /.ssh create config file with the following content: Host. (asterisk for all hosts or add specific host)AddKeysToAgent yesUseKeychain yesIdentityFile (e.g. /.ssh/userKey)Solution 2After usage of ssh-add -K (it's recommended to use absolute path of keys) call the command ssh-add -A on every startup of macOS.To automate this, add a.plist with the following content to the path /Library/LaunchAgents/.
DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' '@@@@LingonWhatStart:ssh-add -A@@@@LingonWhatEnd - Alternatives.Create this file with.Use curl to download the.plist file to the stated path.
![](/uploads/1/2/6/5/126541477/534168988.jpg)