Pushing a branch to a remote server fails - macos

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")

Related

How to clone more than one private repository on CPanel

I am having some issues cloning a private repo into my CPanel server, because of a previously cloned private GitHub repository. I have cloned it before using ssh access and everything went right. However, I need to clone another repo that is also private and using ssh access, as well.
I followed all the procedures to copy the private repo into CPanel as the previous one. However, I'm having issues with access rights, getting the same message as following:
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Is there a way to clone two private repositories with different ssh keys? how to clone those repositories without getting the same message above?
Thanks in advance.
------------------------------------------------- EDIT-----------------------------------------------------
My config file in the .ssh folder is the following
Host region_admin
HostName <git#github.com:SthefanyRangel/regionadmin.git>
User regioye5#cs2006.webhostbox.net:2083
IdentityFile ~/.ssh/id_rsa
Host renovafacil
HostName <git#github.com>
User regioye5#cs2006.webhostbox.net:2083
IdentityFile ~/.ssh/id_rsa.rf
Host regionadmin-ra2
HostName <git#github.com>
User git
IdentityFile ~/.ssh/region_admin
Where my attempts to connect to the second account are the last record.
After reading the documentation "CPanel / How to Copy an Account with SSH Keys", you might need a second key if the GitLab repository uses the same account than the first one.
If not, try:
git -c core.sshCommand='ssh -Tv' clone git#github:...
That will give you an idea of which keys are considered. If your second key is not with a default name, it would need a ~/.ssh/config in order to specify it.
You can test a config entry with:
ssh -T region_admin
Note: Hostname is always just the hostname, not <git#github.com:SthefanyRangel/regionadmin.git>
Your first ~/.ssh/config entry should therefore be (for the actual GitHub username, for which the public SSH key has been registered):
Host region_admin
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Then:
cd /path/to/regionadmin
git remote set-url origin region_admin:SthefanyRangel/regionadmin.git

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.

Multiple git account doesn't work with Xcode

Due to my customer's privacy requirement, I've got create multiple account to access different git. With some helps, I've created the file config and multiple ssh keys in dir ~/.ssh. Using terminal, I've been able to perform all kind of action to the git. However, if I use XCode to perform those action, it stated that failed to authenticate.
This is the content of ~/.ssh/config:
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa
Host bitbucket-myAccount2
HostName bitbucket.org
User git
IdentityFile ~/.ssh/acc2ssh
Inside ~/.ssh/, I've already had id_rsa, id_rsa.pub, acc2ssh, acc2ssh.pub. id_rsa is my usual git account, and acc2ssh is the other private account.
If I use terminal, it's alright, but it ask for passphrase everytime.
$ git remote -v
origin git#bitbucket-myAccount2:privateTeam/project.git (fetch)
origin git#bitbucket-myAccount2:privateTeam/project.git (push)
$ git pull
Enter passphrase for key '/Users/$myUser/.ssh/acc2ssh':
Already up-to-date.
How do I config this to work in both xcode and terminal?
Additional question: How do I make the terminal to remember my passphrase?
UPDATE
Due to the confusion, I'll add more details about the git remote:
I'm checkout out the git via:
$ git clone git#bitbucket-myAccount2:privateTeam/project.git
Because if I use the ssh provided from bitbucket, it won't work (access denied):
$ git clone git#bitbucket.org:privateTeam/project.git
repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
But Xcode seems to doesn't recognize the host bitbucket-myAccount2 as #Jakuje pointed out. Maybe I'm missing something here?
XCode (most probably) does not read your ~/.ssh/config because it is not based on OpenSSH. You should use just the hostname as it is and provide the correct private key.
If the other one (in default location) is still picked up, move it away/rename from default location (~/.ssh/id_rsa) and update the ~/.ssh/config to reflect this change. For example:
Host bitbucket.org
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa2

Xcode - Authentication failed error when adding repository with SSH auth

I am trying to add repository via Xcode > Settings > Accounts and I am stuck on the proper address. Address of our repo is quite simple: my.domain.com:port/project-name. Authentication via SSH Keys. Could someone help me to understand what's going on here? See screenshot below.
By the way running git clone git+ssh://git#my.domain.com:port/project-name works fine.
EDIT
Running git clone without git+ssh//
git clone git#my.domain.cz:2222/project-name
or
git clone git#my.domain.cz:22/project-name
is giving me same error:
ssh: connect to host my.domain.cz port 22: Connection refused
fatal: Could not read from remote repository
Please make sure you have the correct access rights and the repository exists.
Xcode accepts just ssh://git#my.domain.cz:2222/project-name.
The git protocol is somehow redundant in this case. Raw git tools don't have a problem with it, but Xcode does not like it for some reason.
It always fails for me when I use existing ssh keys.
I created a new ssh key pair through Xcode and uploaded the public key to the git server (in my case, Phabricator), and it works.

"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