Cloning repositories from github fails - windows

I am unable to clone any repositories from github. I always get this error message
fatal: Could not read from remote repository. Please make sure you have the
correct access rights and the repository exists
I have taken care of the following :
Set my path variable to ;C:\Program Files (x86)\Git\cmd; and C:\Program Files (x86)\Git\bin;
I have generated the public key and linked id_rsa.pub with git
I have seen all the related links and am unable to resolve this issue.

If you have issue with the ssh key, you can at least use as a workaround https url:
git clone https://github.com/username/reponame
Regarding ssh, make sure that:
environment variable HOME is defines, and that your private/public ssh keys are in:
%HOME%\.ssh\id_rsa
%HOME%\.ssh\id_rsa.pub
your public ssh key is added to your GitHub account.

Related

github ssh key names

I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).
I had previously been using password-based authentication, which is repetitive to keep typing in my passwords. I followed the steps (using windows) to set up SSH keys in github. I gave my key a specific name, anticipating that I will need more than one SSH key at some point. It doesn't make sense to always have id_rsa for github! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key. But running a git clone gave me this error:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I then had the idea to try it with the default name (id_rsa), rather than my custom name, and of course it works. So my question is how do I avoid this? I don't want the default name to be reserved for github.
You can set up an ssh configuration file to tell the ssh command to use that specific key when connecting to github.
Create the file .ssh/config with the content:
Host github.com
IdentityFile ~/.ssh/github_rsa_key
Assuming that you've named your private key ~/.ssh/github_rsa_key.
Now try connecting to github:
$ ssh git#github.com
You should see:
Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.

Git configuration on windows for ssh access to Github

I have a Github account with multiple projects.
I have cloned these projects to my windows 10 computer using ssh key.
some time later, it appear my ssh keys were compromise so i delete my ssh on Github and locally, then regenerate new ones :
4096 bits
rsa2
saved the pub as ~/.ssh/git_id_rsa.pub
add the pub key to my Github ssh keys
saved the priv as ~/.ssh/git/git_id_rsa.ppk
converted to Openssh format as ~/.ssh/git_id_rsa
the fact is I want different ssh keys for my different web tools (one for GitHub, one for DigitalOcean, one for OVH cloud, etc...) and I want to specify witch key to use when connecting to each host. thats why I change the default name for the ssh generated with PuttyGen (and converted with the same).
I don't have passphrase on the git_id_rsa.ppk (nor git_id_rsa) keys, as it seems that GitHub dont like them (saw long time ago).
I've configure my (projecytdir)/.git/config like bellow :
[remote "origin"]
url = git#github.com:hdGuild/JenkinsServerOnDO.git
fetch = +refs/heads/*:refs/remotes/origin/*
identityfile= ~/.ssh/git_id_rsa
But when I try a Git Pull, I've got the following error :
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Following the following answers I've created the ~/.ssh/config file with the following (using OpenSSH key for GitHub), and it works :
Host github.com
IdentityFile ~/.ssh/git_id_rsa
The fact is that if I need the ~/.ssh/config file, why would I need to configure my local git with (projecytdir)/.git/config as I describe it above ?
I would like to configure my local git to use the right ssh key for Github, without having to explain it in my ~/.ssh/config file.
I'm sure it is (again) a configuration problem and I miss something somewhere, but I can't find where.
Please help :)
thank-you
Okay,
As previously, I answer my own question :D
After some more research, I found this post that explain how to specify in Git local config file, the ssh key to use for git sh connection.
The command is simply, in the above explained case, the following while in project directory :
git config core.sshCommand "ssh -i ~/.ssh/git_id_rsa -F /dev/null"
This way, the git_id-rsa will be used by git for ssh connections on this particular project (as it is a local configuration).
Thank-you for reading.

Pushing a branch to a remote server fails

I have a project which uses Git on a remote server. I installed SourceTree for Mac to manage it. I also have a .ssh folder with the private in the root directory where I keep all my projects and the public key is in the server.
I was able to clone the project successfully and even commit+push it back with no problem. Then I ceated a branch in my local repo, added a new file and tried commit+push it. It was committed but the pushing failed with the following error message.
Pushing to git#gitserver:gitbtest
ssh: Could not resolve hostname gitserver: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I'm not sure why this is happening. Is there a way to set SSH keys in SourceTree for Mac? I can't seem to find any option to do so.
Any help to resolve this would be great.
Thank you!
An url like git#gitserver:gitbtest can only work if one have an ssh config file in order to resolve the name gitserver:
$HOME/.ssh/config
Host gitserver
Hostname xxx.xxx.xxx.xxx # IP or full name for gitserver
User git
IdentityFile ~/.ssh/id_rsa
Actually, with such a file, you don't even have to specify the user:
git remote set-url origin gitserver:gitbtest
(You can see an example of that ~/.ssh/config file used in "git public key for more repositories")

Configure Jenkins to use GIT On Windows, Got stderr: Permission denied (publickey)

My Git version is 1.8.0, for this version, the Git installation path in Jenkins is C:\Git\cmd\git.exe (in older versions, it is C:\Git\cmd\git.cmd). This solves the problem that I had: error deleting workspace. In Jenkins, Git repository URL uses the ssh protocol: git#github.com:xxxxx/xxx.git, for me, this URL works. If your key can't be found, this URL will return an error, you need to define %HOME%, then your key should be in %HOME%.ssh. then I started to build. When I built it, I got:
stdout: Cloning into 'C:\Jenkins\workspace\Lily'...
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897)
at hudson.plugins.git.GitAPI.access$000(GitAPI.java:42)
I don't understand why Jenkins can find my key for the repository URL, but can't find my key when it clones the repository.
Any help will be greatly appreciated.
My company has a proxy server, for me, to use SSH protocol is very difficult, it may have a way to solve the combination of a proxy server and ssh-to-github, but I gave up. In stead, I used https protocol. In order not to prompt credentials for Jenkins, I used github credential cache to solve this. Check here for credential cache: http://www.kernel.org/pub/software/scm/git/docs/git-credential-cache.html. Now my Jenkins/Git build works in Windows.

"no address associated with name" error when cloning github.com's repo under Windows using ssh

Searching google for +github +ssh "no address associated with name" gives the following SO questions as the 4 top results:
github no address associated with name
Github push origin master not working
Syncing with github
GITHUB setup - no address associated with name
None of them gives answer to my problem, though.
c:\Program Files (x86)\Git\bin>git --version
git version 1.7.7.1.msysgit.0
c:\Program Files (x86)\Git\bin>ssh git#github.com
Enter passphrase for key '/c/Users/Piotr/.ssh/id_rsa':
Hi piotr-dobrogost! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
c:\Program Files (x86)\Git\bin>git clone ssh://git#github.com:piotr-dobrogost/requests.git
Cloning into requests...
ssh: github.com:piotr-dobrogost: no address associated with name
fatal: The remote end hung up unexpectedly
I guess the problem is caused by git passing github.com:piotr-dobrogost as the hostname to ssh instead just github.com only. Why does git do this and what's the solution?
You answered it yourself - the problem is that you're passing github.com:piotr-dobrogost as the hostname, which is, in fact, not a valid hostname. git will understand either proper URLs to a repository, or a repository path in SCP format (see man 1 scp.) For a proper URL, try:
git clone ssh://git#github.com/piotr-dobrogost/requests.git
Which is equivalent to the following in SCP path format:
git clone git#github.com:piotr-dobrogost/requests.git
I had this same problem, and it's turn out it was DNS problem.
The DNS settings were wrong and the machines simply could not reach the remote git repository.
I am running a private git server with an address assigned by DHCP; this address seems to remain static. From time to time, authenticating with the remote host gives the "no address associated with this name" error.
However, I edit the known_hosts file for my client (which for me resides at C:\Users\MyUserName\.ssh\known_hosts) and delete the line that refers to the private git server:
gitserver.local,10.0.0.10 ssh-rsa AAAABCAAAA....
I then connect again to the git server and issue a pull request. This time, git asks whether to cache the SSH key and the pull concludes successfully, without the "no address associated with name" error.
So, I suspect that something about the RSA key, or how that key relates to DNS, is getting screwed up. If nothing else gives joy, try manually deleting and automatically reinstalling the RSA key on the client. This should not actually work, but it seems to work in my case. I have no clear idea why this should be so.

Resources