I've setup a global git username and password while logged in as root on my Fedora server with the following commands:

git config --global user.email "[my email]"
git config --global user.name "[my username]"

I have also created and saved a public key to my ~/.ssh directory, and added this to the ssh agent with the following command:

ssh-add ~/.ssh/[filename]

After checking the ssh-agent was running using

eval "$(ssh-agent -s)"

I then added the key from ~/.ssh/[filename].pub to the SSH and GPG keys section on github.

I have checked in ~/.gitconfig and the username and email are clearly listed there.

However, whenever I try to do anything on github it's still prompting me for a username and a password every time. Can anyone tell me what I need to do to fix this issue?


You are most probably connecting to https URL of your GitHub repositories. Your url in the .git/config looks somehow like this:

url = https://github.com/User/repository.git

If you want to use ssh authentication, you need to use ssh protocol and therefore url like this:

url = git@github.com:User/repository.git
  • The weird thing is, it's still prompting me for username and password even when I'm just trying to clone another repo. Do I need to put my own username before the url of the repo I'm cloning...? – user179084 Aug 24 '16 at 10:04
  • How does the url you are using look like? – Jakuje Aug 24 '16 at 10:05
  • git clone http://github.com/robertdavidgraham/massscan – user179084 Aug 24 '16 at 10:05
  • That is https url. Clone with ssh as explained above: git clone git@github.com:robertdavidgraham/massscan and it should do the job for you. – Jakuje Aug 24 '16 at 10:06
  • root/.ssh/config: line 2: Bad configuration option: identifyfile /root/.ssh/config: terminating, 1 bad configuration options fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. – user179084 Aug 24 '16 at 10:08

You need to specify that it has to use the key for github.com

In your ~/.ssh/config, add

Host github.com
    IdentityFile ~/.ssh/<private key>
  • I tried this, but it doesn't work. Could this be anything to do with the fact I didn't have a ~/.ssh/config file untiI I created one to add the lines you suggested? – user179084 Aug 24 '16 at 10:01
  • No, when you create the file does not matter. It just has to exist once you try to establish an SSH connection (see also Jakuje's answer to check if you really connect via SSH). – Martin Nyolt Aug 24 '16 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy