[github] Push to GitHub without a password using ssh-key

I generated an SSH key pair without a password and added the public key to GitHub.

Connection with

user@dev:/var/www/project# ssh -T [email protected]
Hi User! You've successfully authenticated, but GitHub does not provide shell access.

was successful and when I rename the key, it fails.

But when I want to push my changes, it stills ask me for my username and password combination.

Is there a way to push without a password?

This question is related to github ssh-keys

The answer is


As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)

To check everything is correct, use ssh -T [email protected]

Next, don't forget to modify the remote point as follows:

git remote set-url origin [email protected]:username/your-repository.git

Using the command line:

Enter ls -al ~/.ssh to see if existing SSH keys are present.

In the terminal is shows: No directory exist

Then generate a new SSH key

Step 1.

ssh-keygen -t rsa -b 4096 -C "[email protected]"

step 2.

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>

step 3.

Enter passphrase (empty for no passphrase): [Type a password]

Enter same passphrase again: [Type password again]

You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)

Here is a link, which says why we need SSH and how to use it: step by step

Git Generate SSH Keys


In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:

git remote set-url origin [email protected]:<Username>/<Project>.git

You should try troubleshooting with:

ssh -vT [email protected]

Below is a piece of sample output:

...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.

According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.

cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa

Now when I run ssh -vT [email protected] again, I have:

...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...

And now I can push to GitHub without being asked for username and password :-)


Additionally for gists, it seems you must leave out the username

git remote set-url origin [email protected]:<Project code>