Make sure there is at least one file in it (even just the README.md)
ssh-keygen -t rsa -C "[email protected]"
or even better:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
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.
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 contents of the to your SSH keys to your GitHub account settings (https://github.com/settings/keys).
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
If the repo is under an organization the command is slightly different:
git remote set-url origin [email protected]:organization/your-repo.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.
When troubleshooting a really unconventional setup of a local gitlab in our environment and with keys configured I found this command on StackOverflow helped me determine that a nonstandard private key/identity file (ie not named id_rsa, id_ecdsa, etc) in the .ssh folder caused the auth to gitlab to fail. The easy fix in my case was to copy the private key into an id_rsa file. Im sure there is an option to specify a specific identity file but I havent checked the manpages yet.
Anyway the verbosity alias for git I used is
git -c core.sshCommand="ssh -v" push -u origin master