Skip to main content

SSH

info

More info about SSH can be found here.

GitHub SSH.

Generating a new SSH key

  1. Open Git Bash.

  2. Paste the text below, substituting in your GitHub email address.

ssh-keygen -t ed25519 -C "your_email@example.com"
  1. When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/Users/YOU/.ssh/id_ALGORITHM): [Press enter]
  1. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

Adding your SSH key to the ssh-agent

  1. Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
> Agent pid 59566
  1. If you're using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config file to automatically load keys into the ssh-agent and store passphrases in your keychain.
  • First, check to see if your ~/.ssh/config file exists in the default location.
open ~/.ssh/config
> The file /Users/YOU/.ssh/config does not exist.
  • If the file doesn't exist, create the file.
touch ~/.ssh/config
  • Open your ~/.ssh/config file, then modify it to contain the following lines.

Open:

nano ~/.ssh/config

Modify:

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
  1. Add your SSH private key to the ssh-agent and store your passphrase in the keychain.
ssh-add -K ~/.ssh/id_ed25519

Switching remote URLs from HTTPS to SSH

  1. Open Terminal.

  2. Change the current working directory to your local project.

  3. List your existing remotes in order to get the name of the remote you want to change.

git remote -v
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
  1. Change your remote's URL from HTTPS to SSH with the git remote set-url command.

git remote set-url origin git@github.com:OWNER/REPOSITORY.git

  1. Verify that the remote URL has changed.
git remote -v
# Verify new remote URL
> origin git@github.com:OWNER/REPOSITORY.git (fetch)
> origin git@github.com:OWNER/REPOSITORY.git (push)

Testing your SSH connection

  1. Open Terminal.

  2. Enter the following:

ssh -T it@github.com
> Hi username! You've successfully authenticated, but GitHub does not provide shell access.