SSH
info
More info about SSH can be found here.
Generating a new SSH key
-
Open Git Bash.
-
Paste the text below, substituting in your GitHub email address.
ssh-keygen -t ed25519 -C "your_email@example.com"
- 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]
- 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
- Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
> Agent pid 59566
- 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
- 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
-
Open Terminal.
-
Change the current working directory to your local project.
-
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)
- 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
- 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
-
Open Terminal.
-
Enter the following:
ssh -T it@github.com
> Hi username! You've successfully authenticated, but GitHub does not provide shell access.