Created
March 7, 2022 01:24
-
-
Save joaofds/a8c55373e05e78e8c1c8561e74ad46bc to your computer and use it in GitHub Desktop.
Set up GitHub push with SSH keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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 "[email protected]" | |
| ``` | |
| or even better: | |
| ``` | |
| ssh-keygen -t rsa -b 4096 -C "[email protected]" | |
| ``` | |
| ### 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 [email protected] | |
| ``` | |
| Change directory into the local clone of your repository (if you're not already there) and run: | |
| ``` | |
| git remote set-url origin [email protected]: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 | |
| ``` | |
| You should not be asked for a username or password. If it works, your SSH key is correctly configured. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment