Permission denied (publickey) error when trying to clone from GitHub - windows

I want to clone a repository and I ran into permission issues,
I tried to set up my username and email but keep getting errors
I used
git config --global user.name "yusuf-uthman"
git config --global user.email "yusufuthman57#gmail.com"
but didnt get any notification wether its accepted or not.
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git config --global user.name "Uthman Yusuf"
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git config --global user.email "yusufuthman57#gmail.com"
Uthman#DESKTOP-30QGK3L MINGW64 ~/Desktop/Scripts/hng_internship5.0
$ git clone git#github.com:yusuf-uthman/hng-internship.git
Cloning into 'hng-internship'...
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
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.
How do I clone the repository without getting the error?

The failure comes from cloning your GitHub repo via SSH URLs. To use that process, one needs to add your public SSH key in your repository.
Instead use HTTP URL method to clone which will most likely circumvent that error.
Use:
HTTP URLs: https://github.com/yusuf-uthman/hng-internship.git
instead of:
SSH URLs: git clone git#github.com:yusuf-uthman/hng-internship.git

but didnt get any notification wether its accepted or not.
Username and Email are just settings in you git config file, no one will accept or decline it. If you commit, the value of the settings will be used to determine the commits author and committer.
Access rights to a repository are usually managed via ssh keys. See Connecting to GitHub with SSH.

Related

Can't clone, can SSH. "Permission denied (publickey)."

I cannot clone or push to a repository on my server.
I have a bare repo that is located is a directory user#host in directory home/user/test.git that I am trying to access via git clone. I used ssh-add <pathtokey> to add my ssh key. It asked me for the passphrase. I can then ssh user#host successfully.
However if I then try to git clone ssh://user#host/~/test.git I get:
Cloning into 'test'...
user#host: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
also tried
git clone ssh://user#host/home/user/test.git
git clone user#host:home/user/test.git
git clone user#host:/home/user/test.git
with the same result
I am guessing the git credential manager isn't picking up the keys?
On the server /var/auth/log says
Feb 20 02:25:36 xxxxx sshd[24674]: Connection closed by authenticating user XXXX x.x.x.x port 56433 [preauth]
Git version: git version 2.30.1.windows.1
Git Credential Manager: Git Credential Manager version 2.0.318-beta+44acfafa98 (Windows, .NET Framework 4.0.30319.42000)
git config -l reports credential.helper=manager-core
Tried both PowerShell and git bash shells, same result
user has read, execute permissions to the repo
To add to #VonC's response
In git-bash things work as normal.
The normal flow of starting the ssh-agent (via eval 'ssh-agent'
), adding the key via ssh-add <path_to_key> enables git clone to work.
In PowerShell Core, or Cmd, via Windows-Terminal more work is required
the ssh-agent starts automatically (assuming you previously started the OpenSSH Authentication Agent service), adding the key works, and you can ssh after this, but git commands do NOT work, initially, but if you do
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
This will replace the (default) ssh that comes with git-for-windows with the Windows10 implementation.
After this it should work fine in things other than git-bash. Confirmed in Powershell-Core, Command Prompt
See also:
https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99
The git credential manager is only involved for caching credentials (username/password) for HTTPS URL, not SSH.
Only the ssh-agent could be involved, for caching a possible passphrase, if the private key was defined with it.
I would try first using the full path, since ~ might not be interpreted by the remote shell, but the local (which has a different path for ~):
git clone ssh://user#host/home/user/test.git
# or
git clone user#host:/home/user/test.git
If not, in a git bash session, type:
export GIT_SSH_COMMAND='ssh -v'
git clone ...
The OP confirms in the discussion it works in a bash session:
In git bash, I started the ssh-agent,
added the key there, then it worked.

Gitlab premission denied

Hello i have a gitlab server and the web interface works just as ssh -T git#mijnstageportaal.nl,
but when i try to upload a folder to a blaco project its says this
git init
git remote add origin http://mijnstageportaal.nl/marijnboeve/sinterklaas-intocht
git add .
git commit -m "Initial commit"
git push -u origin master
Reinitialized existing Git repository in
/Users/marijnboeve/websites/sinterklaasintocht/.git/
fatal: remote origin already exists.
HEAD detached from v8.0.1
nothing to commit, working tree clean
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.
Look at
Please make sure you have the correct access rights
and the repository exists.
Most probably, you don't have a public key id_rsa at path /Users/YOUR_USER_NAME/.ssh.
You should generate it, e.g. ssh-keygen -t rsa -b 2048 -C "email#example.com" (see https://docs.gitlab.com/ee/ssh/).
Or, repository at http://mijnstageportaal.nl/marijnboeve/sinterklaas-intocht really doesn't exist. You can check it with your Web client, if possible, or ask a repository owner.

Git user won't change on Mac

Last week a friend of mine cloned her Github repository and did some work on it on my machine. She changed the user config on my machine using the following bash commands:
git config --global user.name "myFriendsUsername"
git config --global user.email "myFriendsEmail"
When she was done, she used the same commands to change the user config back to my credentials and I verified this using
git config --global user.name
git config --global user.email
which returned my credentials. However, today I cloned a repository of my own, committed some changes and tried to push to origin but it gave me the following error:
remote: Permission to myUsername/myRepo.git denied to myFriendsUsername.
fatal: unable to access
'https://github.com/myUserName/myRepo.git/': The requested URL returned error: 403
Are there any settings that I'm possibly neglecting?
The git config settings you changed are used when committing changes to a repository, not for authorization:
$ git config --global user.name "Full Name"
$ git config --global user.email "user#example.com"
When your friend cloned a git repository, its likely that your computer's credentials manager (Keychain on Mac OS) saved the authorization certificate.
To remove this authorization certificate, open up Keychain, click on All Items and search for git. You will get some items like this:
After deleting these certificates, Git should prompt you to reauthorize on your next action.

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

setting up git/github on a mac: error on reading usr/local/etc/gitconfig

I set up git with
git config --global user.name myuser
git config --global user.email my#email.com
when I try to commit my new repo through github for mac I get this error:
fatal: unable to access '/usr/local/etc/gitconfig': Permission denied
(128)
I have read the documentation on github and followed their instractions, but didn't get anywhere.
Could you help fix it?
git config --global is supposed to write in $HOME/gitconfig, your global config.
Double-check $HOME when you are typing this command, because if /usr/local/etc/gitconfig is more of a system config file, more likely owned by root.

Resources