github who am I? (OSX) - macos

I think I'm github USER_A, but github thinks I'm USER_B. First, I check who I am:
$ git config --list
color.ui=auto
push.default=simple
user.name=USER_A
user.email=USER_A#gmail.com
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/USER_A/MY_REPO.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
Then, I git clone my repo:
$ git clone https://github.com/USER_A/MY_REPO.git
Cloning into 'MY_REPO'...
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 6
Unpacking objects: 100% (9/9), done.
Checking connectivity... done.
Then I change something, commit, and push:
$ git push
remote: Permission to USER_A/MY_REPO.git denied to USER_B.
fatal: unable to access 'https://github.com/USER_A/MY_REPO.git/': The requested URL returned error: 403
This the only thing Github says about this error.
Why does git/github think I'm pushing as USER_B?!
EDIT: based on comments, I ran this test:
$ ssh -T git#github.com
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of
known hosts.
Hi **USER_A**! You've successfully authenticated, but GitHub does not provide
shell access.
I don't have a ~/.ssh/config or /etc/ssh/ssh_config file. I'm on a Mac FWIW.

I found the problem, my Mac keychain had USER_B. I found it when I searched for "github" in the Keychain app. I've updated the question to reflect this is a Mac-specific problem/solution.

I had the same problem. I was able to find out what key has been used by git using following command:
ssh -v -T git#github.com
Then, I saw another key is being used by github; So, I added my default key to SSH Agent:
ssh-add ~/.ssh/id_rsa
Then, problem solved :-)

Here are a couple things I would do if your having trouble:
Run
Vics-iMac:ansible vic$ git config --list
Explanation: When you configure git typically for the first time there are a lot of things that are done during the setup phase. One of them is configuring who you are, and what email address you use. If you examine the following output from the command above. You will see the user.name being used.
user.name = BlahBlah Name
user.email = blahadklhf#gmail.com

Related

Jenkins pipeline Git error: “Host Key Verification Failed” when connecting to remote repository

I am using my PC as a server to build my Jenkins script with declarative pipeline.
when running a git clone on the git bash, it works well:
$ git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
remote: Counting objects: 889, done
remote: Finding sources: 100% (203/203)
Receiving objects: 79% (121769/152721), 48.11 MiB | 10.35 MiB/s
but running it on the same machine through pipelining :
sh "git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware"
gives me the following error
[Pipeline] sh
+ git clone ssh://guillaumed#myserver.com:29418/myProjects/thisProject.git ThisFirmware
Cloning into 'ThisFirmware'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
any hints?
To be sure I was using the same key, thanks to Jens, the pipeline script couldn't find the key.
Doing cat ~/.ssh/id_rsa.pub on the pipeline, resulted in + cat /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub
cat: /c/windows/system32/config/systemprofile/.ssh/id_rsa.pub: No such file or directory
So I copied the ssh file from my guillaumed user ssh path to the SYSTEM ssh path but I can't use it if i'm logged in with SYSTEM user instead of guillaumed user.
what do I have to do?
this link didn't help.
Indeed, you can't checkout with ssh if you are logged as SYSTEM.
To checkout as "thisUser":
You'll need to configure your Jenkins.
1/ add a user "thisUser"
2/ add user's ssh credentials "thisUser-ssh-credentials"
3/ use ssh-agent plugin https://wiki.jenkins.io/display/JENKINS/SSH+Agent+Plugin
Then configure your pipeline
dir(server_workspace)
{
sshagent(credentials: ['thisUser-ssh-credentials'] )
{
sh "git clone ssh://thisUser#domain.com:port/yourProjects/thisProject.git"
}
}

Git remote push: failed to load advapi32.dll

I am new to Git and Github; and I came across a problem. There is a similiar question here (git bash failed to load advapi32.dll), but they are experiencing a different problem and there are no answers either. I have searched online and was unable to fix this. Here is the issue:
I am using Git Bash to push/pull commits to Github. When I try to push my work, I get this error saying "failed to load advapi32.dll ". I do have this file in my registry. The full Git message is bellow. It is worth noting here, that despite this error, Git is uploading and downloading commits perfectly fine; I just want to fix this problem in case it causes more issues in the future.
$ git push origin master
failed to load advapi32.dll
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 418 bytes | 418.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/khash021/reflections.git
98a7bd9..b982ba4 master -> master
Thanks,
Khash
This problem occurs because the credential halper has been set to wincred and you do not have wincred installed. To verify this, run the command
git config --global credential.helper
if the result says "wincred", this is your problem. To unset the credential helper, run the command:
git config --global --unset credential.helper
That should solve the problem.
First, check your Git version: if it was v2.16.1.windows.2, from 4 days ago, it was quite buggy.
Try with the one released today: v2.16.1.windows.3: uncompress PortableGit-2.16.1.3-64-bit.7z.exe anywhere you want, and define a simplified PATH for testing.
well you could adding the flag:
$ git push origin master --all
Also, given that the .dll file is a system file, check that git has the permission to access it.

Why do Git commands fail via Win32-OpenSSH on Windows 10?

I have set up Win32-OpenSSH on a Windows 10 system, and I am using Git for Windows 2.16.1.
I have created a bare test repository, from which I can clone just fine via the file URL:
git clone file:///c:/test.git
Cloning into 'test'...
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 33 (delta 11), reused 0 (delta 0)
Receiving objects: 100% (33/33), done.
Resolving deltas: 100% (11/11), done.
SSHD is also running fine, I can open a shell from my tablet, and access the repository directory via SFTP:
> sftp oli#localhost
oli#localhost's password:
Connected to oli#localhost.
sftp> pwd
Remote working directory: /C:/Users/Oli
sftp> cd /c:/test.git
sftp> pwd
Remote working directory: /c:/test.git
sftp> ls
HEAD config description hooks info objects packed-refs refs
sftp> bye
But cloning via SSH fails for some reason:
> git clone ssh://oli#localhost:22/c:/test.git
Cloning into 'test'...
oli#localhost's password:
fatal: ''/c:/test.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
User "Oli" definitely has the correct access rights, and we have seen above that the repository exists and is a valid Git repository. I also tried many different syntax variants on the path.
I have read every Q/A here on Git/SSH/Windows, and the Git Pro book, and the Git reference, and the OpenSSH manuals, and the Win32-OpenSSH wiki.
What am I missing?
This has been answered by Konstantin in this question (Thanks for the link, Aurel):
The problem is - cmd.exe doesn't understand single-quoted parameters.
Git passes the path to the repository enclosed in single quotes, which does not work in cmd.exe.
This can actually be seen in the Git error message above, if you look close enough:
fatal: ''/c:/test.git'' does not appear to be a git repository
So I have set up the workaround that Konstantin suggested:
create shell scripts gup.sh and grp.sh in my home directory on the server, each containing the single line git-upload-pack.exe $* resp. git-receive-pack.exe $*
use parameter -u 'sh gup.sh' in the initial clone operation (when doing this in cmd.exe, use double quotes...)
configuring the cloned repository with commands git config remote.origin.uploadpack 'sh gup.sh'and git config remote.origin.receivepack 'sh grp.sh'
...and it works.
Sadly, Konstantin's answer is not the accepted one, and the least upvoted one. So if this helps you, too, upvote his answer!

Using a network drive as git repository

So, I've created a git repository on the networked drive:
git init --bare --shared
and that works fine. Then, I clone it to a local drive with
git clone z:/testgit
and that also works fine. Then I add a file, stage, and commit
git stage *
git commit -m "test commit"
and that ALSO works fine. BUT! When I try to push to the origin, I get this error.
git push origin
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: unable to write sha1 filename ./objects/f3/e6e90a7465421306fae05c18153260973542e3: Permission denied
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To z:/testgit14
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'z:/testgit'
When attempting to use git stage * directly on the server (on a non --bare git project) I get similar errors.
I have full access to the drive in file explorer, and even able to initialize the repository with git. SSH shouldn't even apply here since it's not a server, it's a networked drive. Everything I've read about git says that this should work. I've read dozens of "how to's" that all say these exact steps, but no one complaining about permission denied, UNLESS they're talking about SSH public keys missing on servers (which, as I've said, shouldn't apply).
What permissions am I missing? Where should I look for and set the proper permissions?
What happens when you try to create the file that git is complaining about?
echo test > ./objects/f3/e6e90a7465421306fae05c18153260973542e3
It's possible that git is creating a new folder (f3) and the folder is not getting the correct permissions, either due to ACL inheritance misconfiguration or because the local machine is trying to adjust the permissions on newly created folders and getting it wrong.
If it were Linux, it could be because the network drive was connected with the wrong mount options, or the umask was set incorrectly, but I'm not sure whether those are available to be changed on a Windows machine.

setting up ssh-keys for bitbucket account (with mac osx)

I have a BitBucket account. Despite setting up the ssh key on the computer and then adding it on my bitbucket account, I fail at connecting:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I did the following:
$ cd ~/.ssh
$ ssh-keygen -f ~/.ssh/my-key -N ''
$ vim config
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/my-key
$ ls -l
-rw------- 1 me ... 229 Jul 8 15:50 config
-rw------- 1 me ... 1679 Jul 8 14:07 my-key
-rw-r--r-- 1 me ... 411 Jul 8 14:07 my-key.pub
Then I added the content of my-key.pub in my bitbucket account's ssh keys. Then I retried cloning my repository:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I repeated the identical procedure on another machine, it worked:
$ git clone git#bitbucket.org:my-account/myrepo.git
Initialized empty Git repository in /home/me/.ssh/myrepo/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
I need to do the same on my first machine now.
As a last resort, I followed some advises on the net using the ssh-agent:
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/my-key
But still no luck:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have no idea what is different on the first machine, why does it reject my request?
EDIT 1
Of course I tried doing it the very basic way, as suggested by D.Samchuk:
Generating the id_rsa
$ ssh-keygen -t rsa
enterx3
Copied the exact content of the key
$ cat ~/.ssh/id_rsa.pub
And I added id_rsa.pub's content in my BitBucket account's ssh keys.
Git clone will still not allow me to access the repository, whit the same output error message as above.
EDIT 2
I have no idea maybe it is related to mac configurations? Since The other machine is a redhat linux I just wondered but couldn't find any reported similar issue.
just do following:
$ ssh-keygen -t rsa
name: id_rsa
passphrase: just press enter twice to avoid print keyword everytime you connect
$ cat ~/.ssh/id_rsa.pub
copy output
open bitbucket --> profile --> bitbucket settings --> add ssh key --> paste your output
If you are not using a passphrase for the ssh key you shouldn't need the ssh-agent
https://help.github.com/articles/working-with-ssh-key-passphrases/
Solved. As I delved deeper in the issue I found it is absolutely not related to ssh keys but to missing repository as the error message suggested. It was all about experimenting the global config using git config --global that messed up my git configuration on that computer. I detailed my steps in another thread here: https://unix.stackexchange.com/questions/294780/git-retains-remote-information-from-a-deleted-repository/294809#294809.

Resources