Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set up GitHub push with SSH keys

Create a repo. Make sure there is at least one file in it (even just the README) Generate ssh key:

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

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings. Test SSH key:

ssh -T git@github.com
clone the repo:
git clone git://github.com/username/your-repository

Now cd to your git clone folder and do:

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 "my update msg"
git push
@OtiZ2

This comment has been minimized.

Copy link

OtiZ2 commented Sep 27, 2017

Clone can by direct via ssh
git clone git@github.com:username/your-repository.git

@ragerdl

This comment has been minimized.

Copy link

ragerdl commented Oct 19, 2017

Given the recent factorability of rsa-2048, it's probably wise to change the first step to include -b 4096 as a flag,

@AndrewPlewe

This comment has been minimized.

Copy link

AndrewPlewe commented Jan 24, 2018

You can test your RSA keys here: https://keychest.net/roca -- I just generated a 2048 bit key using ssh-keygen and it's not vulnerable.

@AndrewPlewe

This comment has been minimized.

Copy link

AndrewPlewe commented Jan 24, 2018

...Also, from here: https://crocs.fi.muni.cz/public/papers/rsa_ccs17

"Q: Is the RSA algorithm insecure in general after the disclosure of this vulnerability?
A: No. If the RSA primes are generated as a truly random numbers, our method cannot be applied. For example, keys generated by the OpenSSL library are NOT affected."

@MartinX3

This comment has been minimized.

Copy link

MartinX3 commented Feb 16, 2018

Thank you for this gist!

It is recommend to use the 4096 bit keys.
You don't know, if there will be bugs found, which will weak your key.
You don't know, if there will be a breakthrough in computer performance.

But later, you should switch to elliptic curve keys.
They are smaller, but stronger compared to RSA.

@jbarros35

This comment has been minimized.

Copy link

jbarros35 commented Jan 13, 2019

fatal: No such remote 'origin'

@saikumar22k

This comment has been minimized.

Copy link

saikumar22k commented Mar 6, 2019

Can I push my changes using shh, if I clone my project using http. Please help

@HassanElanabi

This comment has been minimized.

Copy link

HassanElanabi commented Mar 24, 2019

Can I push my changes using shh, if I clone my project using http. Please help

yes, you can.
in this answer, I'll assume that you have already taken the steps above, and set up your ssh keys with github.
First check if there is a remote in your repository and its name using:
git remote
if there is one, let's assume it's origin
Check the url of that remote, with:
git remote get-url origin
if it was an http address , then change it to an ssh url using the following cmd:
git remote set-url origin git@github.com:username/repository-name

@lukependleton

This comment has been minimized.

Copy link

lukependleton commented Mar 24, 2019

@HassanElanabi Thank you so much! This has been causing me problems for a long time!

One other thing is that if
git remote get-url origin
doesn't work, you can use
git remote show origin
to see the current url. At least that's how I had to do it. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.