This page provides instructions on how to setup public key authentication (PKA) or public key infrastructure (PKI) to allow SSH to a remote host using authentication using a private/public key pair. These instructions have been tested in the following scenarios:
- macOS (host) to RHEL (remote)
- RHEL (host) to RHEL (remote)
Generate a Public/Private Key Pair:
Open a Terminal window on your host machine and type the following:
This will generate the public/private rsa key pair. You will be prompted on where to save the key; the default location (/Users/<username>/.ssh/id_rsa) is fine, so you can just hit " Enter ".
You will be prompted "Enter passphrase (empty for no passphrase)." If your goal is to SSH into machines without having to type in your password, leave this field blank and hit " Enter ".
You will be prompted to enter the same passphrase again. Hit " Enter ".
You will receive the following confirmation:
Your identification has been saved in /Users/(username)/.ssh/id_rsa.
Your public key has been saved in /Users/(username)/.ssh/id_rsa.pub.
Transfer the Public Key to Remote Machines
You now need to copy your public key to the machines that you want to SSH to. You must copy the public key to each remote machine.
SSH to the remote machine:
Then confirm the remote machine has a ".ssh" folder in your account's home directory:
If it does not, create the .ssh folder:
Make sure that directory is accessible only to your account:
Now copy your public key to the remote machine, from the machine you created the keys on:
where <hostmachinename> will help identify the source of the public key.
Now SSH into the remote machine you have copied the file to, and cd to the .ssh directory in your home directory:
You'll see the <hostmachinename>.pub file you just copied over. Add its contents to a file named "authorized_keys":
Back on the host machine, test SSH:
which should result in a login without a password.
- Repeat for every remote machine.