Skip to content

Instantly share code, notes, and snippets.

@xirixiz
Forked from developius/README.md
Last active April 25, 2024 20:53
Show Gist options
  • Save xirixiz/b6b0c6f4917ce17a90e00f9b60566278 to your computer and use it in GitHub Desktop.
Save xirixiz/b6b0c6f4917ce17a90e00f9b60566278 to your computer and use it in GitHub Desktop.
Set up GitHub push with SSH keys

SSH keypair setup for GitHub (or GitHub/GitLab/BitBucket, etc, etc)

Create a repo.

Make sure there is at least one file in it (even just the README.md)

Generate a SSH key pair (private/public):

ssh-keygen -t rsa -C "your_email@example.com"

or even better:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

It also possible to use ed25519. There are pros and cons, but personally I've had some issues and that is the reason I've chosen to stick to 4096 rsa for now.

Copy the contents of the public SSH key

macOS:

pbcopy < ~/.ssh/id_rsa.pub

GNU/Linux (requires the xclip package):

xclip -sel clip < ~/.ssh/id_rsa.pub

Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub | clip

Git Bash on Windows / Windows PowerShell:

cat ~/.ssh/id_rsa.pub | clip

or ofcourse copy it via your favorite editor, cat, or whatever suits your needs :)

Copy the public SSH key to GitHub

Copy the contents of the to your SSH keys to your GitHub account settings (https://github.com/settings/keys).

Test the SSH key:

ssh -T git@github.com

Change directory into the local clone of your repository (if you're not already there) and run:

git remote set-url origin git@github.com:username/your-repository.git

Now try editing a file (try the README) and then do:

git add -A
git commit -am "Update README.md"
git push

Add the key to the ssh-agent

ssh-add ~/.ssh/id_rsa

You should not be asked for a username or password. If it works, your SSH key is correctly configured.

@thomas15503
Copy link

thomas15503 commented Jan 17, 2024 via email

@phetdam
Copy link

phetdam commented Jan 27, 2024

Sorry for the late response--have been recovering from an illness for nearly 2 weeks.

The public SSH key should be easy to copy via your browser... so far it seems like that's the problem. Unless you have figured it out already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment