Further reading here.
If you need to create a new SSH key pair, use the ssh-keygen
command to create an Ed25519 key (more secure than RSA).
ssh-keygen -t ed25519
Follow the prompts, and give it a custom filename to not override existing key pairs if you have them.
On the local machine, transmit key to remote machine.
ssh-copy-id -i /Users/<username>/.ssh/<ssh_key_name (do not append .pub extension)>
Follow the prompt to enter password on remote machine (for hopefully the last time).
On the local machine, add a new entry to your SSH config to use the corresponding SSH key. Open your ssh config with your favorite text editor
vim ~/.ssh/config
Append the following template (replace everything in <brackets>
with your actual values).
Host <host-nickname>
HostName <hostname>
User <username>
IdentityFile ~/.ssh/<ssh_key_name (do not append .pub extension)>
From the local machine, try connecting to the remote.
ssh <host-nickname>