Return to site

SSH Keys & Machine Auth

· Memory

I'm always forgetting how to setup SSH key auth on MacOS. Once I've noted it down here I doubt I'll forget it again. This is also of course a key component to K8S pipelines and general VM automations, you would think I would know it by now !

Generating a new SSH key

$ ssh-keygen -t rsa -b 4096 -C ""

This is create both the public and private key pair, using the email address as a label (its just a label doesn't have to be a valid email address). Provide a passphrase for access (no not - in which case secure your private key another way).

Adding SSH Key to ssh-agent - MacOS Specific

You need to create (it doesn't exist by detail) the ~/.ssh/config to load the created keys in and store both the keys and passphrase into MacOS key store.

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
<-- This is the public key of the pair

Add the SSH private key to the ssh-agent and keychain with ssh-add -K ~/.ssh/id_rsa

use ssh-copy-id to copy the public key to the desired host. This will add the key to the host machines '~/.ssh/authorizd_keys' file -- and as if by magic you no longer need to provide you password to connect from you trusted host machine.

All Posts

Almost done…

We just sent you an email. Please click the link in the email to confirm your subscription!