I need to create a git working environment on my Windows 10 installed desktop, I then setup the git account, add the ssh key of the machine through the gitlab control panel but gitlab replied me with no access right when trying to git pull my project.
I tried
I tried
- Re-generate the RSA key and load again
But not working...
Solution
Turn out the username and the user account must match the one created in gitlab, git client will make use that account for the verification process with git server. I misunderstand that the user account can be arbitrary created on the fly.
Procedure
Due to ssh-agent cannot find the keys attached, in such case we need to add the private key identities by running command
ssh-add
repeat step 6 and the remote origin may now be read
But in case... If it sill fails to log in for some error messages like no access rights to the repo, navigate to ~/.ssh/config, add the entry as follows.
Note: You can also specify multiple IdentityFile entries if you have same hostname using different key pairs, just add 1 more IdentityFile entry would be done, remember, you should put the private key in the IdentityFile option
And use all the possible keys for login
References
Procedure
- Configure the username and user account (MUST match with the one in gitlab / github, skip the --global parameter if you are managing multiple users)
- git config --global user.name "yourname"
- git config --global user.email“your@email.com"
- Remove known_hosts (may not be necessary, it depends)
- ssh-keygen -t rsa -C "whateverName"
- Copy all text in /Users/your_user_directory/.ssh/id_rsa.pub
- Go to setting in gitlab and add the public key for authentication
- Set the git remote url with "git remote set-url origin https://gitUsername:gitPassword@gitlab.com/yourRepo.git"
Points to Note
Sometimes, login still failed withsign_and_send_pubkey: signing failed: agent refused operation
Permission denied (publickey).
fatal: Could not read from remote repository.
Due to ssh-agent cannot find the keys attached, in such case we need to add the private key identities by running command
ssh-add
repeat step 6 and the remote origin may now be read
But in case... If it sill fails to log in for some error messages like no access rights to the repo, navigate to ~/.ssh/config, add the entry as follows.
Note: You can also specify multiple IdentityFile entries if you have same hostname using different key pairs, just add 1 more IdentityFile entry would be done, remember, you should put the private key in the IdentityFile option
Host gitlab.com
PubkeyAcceptedKeyTypes +ssh-rsa
HostName gitlab.com
IdentityFile ~/.ssh/id_rsa_anywhere /*Private key directory here!!*/
User git
And use all the possible keys for login
ssh git@gitlab.com -vv
After the configuration, gitlab should be able to login and fetch updates againReferences
- https://gitlab.com/gitlab-com/support-forum/-/issues/638#note_32211207
- https://blog.csdn.net/jingtingfengguo/article/details/51892864
- https://stackoverflow.com/questions/4220416/can-i-specify-multiple-users-for-myself-in-gitconfig
- https://askubuntu.com/questions/762541/ubuntu-16-04-ssh-sign-and-send-pubkey-signing-failed-agent-refused-operation
- https://dotblogs.com.tw/Echo/2017/06/28/Linux_AuthorizedKeys_Setting
沒有留言:
張貼留言