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
Related
I have set remote using git remote set-url but if it includes username, git works fine on terminal and doesn't work in Xcode. If url was set without username, it works only in Xcode, but doesn't work in terminal.
The error showing in the shell without username is ERROR: Repository not found.
The Xcode error with included username is The remote repository could not be accessed and username in dialog box is git without ability to change
I did not change ~/.ssh/config after OS update. user.name and user.email are set for --local only, no changes here as well.
$ git remote set-url origin git#github.com-UserName:repo/project-name.git
//Remote commands work only in Shell
$ git remote set-url origin git#github.com:repo/project-name.git
//Remote commands work only in Xcode
Where is the problem, how can I fix this issue and get it working in both Xcode and the shell?
PS: Yesterday I had only one of my repos working in both Xcode and shell when set url without username (other repos was working as described only either in terminal or xcode), but after minor Mac OS update (just 12.2->12.2.1) it works the described way also now like others. Have no idea what additionally was set but know it's possible to get working both Xcode and Terminal at least.
UPD: If I change Host from github.com-UserName to github.com I am losing ability to use both repos simultaneously in Terminal because only one repo for added ssh keys works.
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github-User-1
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github-User-2
//Terminal:
$ ssh-add --apple-use-keychain ~/.ssh/UserName-1
$ ssh-add --apple-use-keychain ~/.ssh/UserName-2 //Only repo with this one will work, another will show `ERROR: Repository not found` as both hosts are same.
UPD 2: Looks like Xcode is just ignoring ~/.ssh/config file and just using set remote url as is, not replacing Host name with the actual url.
The URL git#github.com-UserName can only work if you have a ~/.ssh/config file with a Host github.com-UserName entry in it, which reference the right private key to use (the same private key that XCode has in its settings)
Simply rename that Host entry to Host github.com, and the git#github.com:user1/project-name.git should work in command line (as well as with XCode)
If you have more than one repository for the same user, you don't need to add anything to your ~/.ssh/config file.
git#github.com:user1/project-name.git
git#github.com:user1/project2-name.git
git#github.com:user1/project3-name.git
...
If you have more than one user, make sure the Host entry is different than the first in ~/.ssh/config:
Host gh1
Hostname github.com
User git
IdentityFile ~/.ssh/gh1
Host gh2
Hostname github.com
User git
IdentityFile ~/.ssh/gh2
This supposes you have generated two SSH keys, one named gh1, with gh1.pub added to user1, and one named gh2, with gh2.pub added to user2.
ssh-keygen -f ~/.ssh/gh1 -t rsa -P ""
ssh-keygen -f ~/.ssh/gh2 -t rsa -P ""
Finally, use for the repo1 owned by user1
git clone gh1:user1/repo1
# or, for an existing repo1 clone
cd /path/to/local/repo1
git remote set-url origin gh1:user1/repo1
And for repo2, owned by user2
git clone gh2:user1/repo2
I'm trying certain git operations, such as pull, push etc but none works:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Things I have done:
Checked whether the remotes were ssh's: git remote -v
origin git#github.com:USERNAME/REPOSITORY.git (fetch)
origin git#github.com:USERNAME/REPOSITORY.git (push)
Checked if the ssh agent is running: eval "$(ssh-agent -s)"
Agent pid 123456
Added the private key to ssh agent: ssh-add "path_to_private_key_file"
Identity added: "path_to_private_key_file" (email#provider.com)
Added the public key to Github at "https://github.com/settings/ssh/new"
Checked whether ssh connection is working: ssh -T git#github.com
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
Assuming that:
you don't have an environment variable GIT_SSH
your %PATH% references C:\Program Files\Git\usr\bin\ssh.exe first
Make sure that:
your remote origin URL is git#github.com:me/myRepo
you have a %USERNAME%\.ssh\config file which set a the right private key file path, assuming it is not the default one (id_rsa).
That config file would be (again, only if the private key is nont the default one):
Host github.com
Hostname github.com
User git
IdentityFile C:\path\to\private\key\file
I have two different accounts where I have to upload changes to, the thing here is that the GitHub account and the Bitbucket account has different email addresses, so I'm trying to configure multiple ssh keys in order to keep committing, pushing and pulling changes from Github and Bitbucket respectively.
I've tried to generate two different ssh-keys by running:
ssh-keygen -t rsa -C "My.CorporateAddress#company.com"
Then, when asked to enter the file in which to save the key I add this:
Enter file in which to save the key (/Users/myUser/.ssh/id_rsa): /Users/myUser/.ssh/id_rsa_github
I do the same steps with the bitbucket one.
Then I generate a file named config and edit it by adding:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github
Host bitbucket
HostName corporate-address.com
User git
IdentityFile ~/.ssh/id_rsa_bitbucket
But when I run:
ssh -T git#bitbucket
Or:
ssh -T git#github
And try to make a pull request for any of those, I get the following error:
GITHUB 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.
---------------------------------------------------
---------------------------------------------------
BITBUCKET ERROR:
git#bitbucket.corporate.companyName.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
For security reasons, I omitted the company name.
What I'm trying to achieve is the possibility to work with both, my work Bitbucket account and my Personal Github account which are configured with a different email address.
What am I doing wrong? Your feedback will be truly appreciated it!
To test your different key, you should type:
ssh -Tv github
ssh -Tv bitbucket
No need to add the user.
Try again, with the old PEM format
ssh-keygen -t rsa -C "xxx#yyyy.com" -m PEM -P "" -f ~/.ssh/id_rsa_github
ssh-keygen -t rsa -C "another#yyyy.com" -m PEM -P "" -f ~/.ssh/id_rsa_bitbucket
But make sure to add your public keys to your accounts.
Example for GitHub: "Adding a new SSH key to your GitHub account".
I was finally able to configure my two git accounts, they're now up and running.
I followed this tutorial I found and it worked like charm!
Configuring Multiple SSH Keys on Mack
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
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")