3

I have my keys in ~/.ssh/ and on other computers I can push and pull from the repo in question.
Why on one computer do I always need to enter my github username/password but not on others?

What could I change to avoid this and use my ssh keys instead ?

3 Answers3

3

The easiest way is to create a ~/.netrc file with the following contents:

machine github.com
login YOUR_GITHUB_USERNAME
password YOUR_GITHUB_PASSWORD

(as shown here: https://gist.github.com/ahoward/2885020)

You can even close up the permissions on this file so that no one can read your password by typing:

chmod 600 ~/.netrc
2

This can be changed by changing the authentication protocol method from https to ssh

One option would be to rename or delete the existing repo and then 'reclone' with the different method. So after mving or rm -ring the current repo, the clone command will be something like

git clone git@github.com:user_name/repo_name.git

You can see the difference in the two approaches with the git config -l command:

For https:

...
remote.origin.url=https://github.com/user_name/repo_name.git
...

For ssh

...
remote.origin.url=git@github.com:user_name/repo_name.git
branch.master.rebase=true  # This was also created in the ssh method

...

You can see the difference in the .git/config file for each repo:

Note the change in 'url' below. Plus addition of rebase = true in ssh

http

[core]
  repositoryformatversion = 0 
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = https://github.com/user_name/repo_name.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master

ssh

[core]
  repositoryformatversion = 0 
  filemode = true
  bare = false
  logallrefupdates = true
[remote "origin"]
  url = git@github.com:user_name/repo_name.git
  fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
  remote = origin
  merge = refs/heads/master
  rebase = true

So if you want to just change the authentication method without 'recloning' the entire repo you can just edit the projects .git/config and change

  url = git@github.user_name/repo_name.git

to

  url = https://github.com/user_name/repo_name.git

plus add

rebase = true

at the bottom, in the "[branch "master"]" section

0

You did not specify if you are sure that you are already using ssh in the connection with github. It is highly possible that on your other machines, the github credentials are stored somewhere in a cache without you knowing (it was my case when I switched from a macos/unix to a linux system)

Set a remote using ssh type. You can check url type by using

git remote -v

You can change the url of the remote repository such that ssh will be used instead of https.

Instead of the html url https://github.com/username/repo_name

use the .git type url git@github.com:username/repo_name.git

Do the change using

git remote set-url <your_branch_name> <url>
Alex M.M.
  • 101
  • 2
  • This question already has an accepted answer and your answer don't bring anything new to the topic – mrc02_kr Nov 13 '19 at 09:56
  • There is a sub-question that hasn't been answered yet and I did ofer an explanation on why this can happen. Thanks for remark – Alex M.M. Nov 13 '19 at 10:19