Skip to content

Instantly share code, notes, and snippets.

@e13h
Created February 22, 2023 03:59
Show Gist options
  • Save e13h/b0b856a37fba553147c48bbe979a4be8 to your computer and use it in GitHub Desktop.
Save e13h/b0b856a37fba553147c48bbe979a4be8 to your computer and use it in GitHub Desktop.
SSH keys and SSH config

Configure SSH to remember your credentials

Further reading here.

Create an SSH key pair

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).

Store your connection settings

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment