I found this after searching a lot. It will work perfectly fine for me.
ssh-keygen
.ssh
folder.id_rsa.pub
. Open it on notepad. Copy all text from it.Now give it a shot and it will work for sure.
Step 1:
Added a config file in ~/.ssh/config
file which looks like
User git
Hostname gitlab.com
IdentityFile ~/.ssh/id_rsa_gitlab
TCPKeepAlive yes
IdentitiesOnly yes
Step 2: Just clone the git repo WITHOUT sudo.
Documentation: https://gitlab.com/help/ssh/README#working-with-non-default-ssh-key-pair-paths
** sometimes you have the config in your ~/.ssh/config
, but, IdentityFile path is not correct. you can check the file name like this ls ~/.ssh/
. the file is normally is id_ed25519
for gitlab. thus the correct config is IdentityFile ~/.ssh/id_ed25519
I think the simple solution is to add private key to authentication agent (if your key is not ~/.ssh/id_rsa
),
ssh-add ~/.ssh/<your private key>
You basically let the ssh-agent
take care of it.
Additionally, you can add it permanently.
There is a very simple solution to this: instead of working with ssh - move to https. to do this: in your project folder you have a .git folder in there - you have a config file - open it in a text editor and change the line
url [email protected]:yourname/yourproject.git
to
url = https://gitlab.com/yourname/yourproject.git
In my case it did not work in the WSL (Windows Subsystem for Linux).
When I start the WSL, I must
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
Now the connection works.
We can test this with ssh -T [email protected]
notes:
make sure you are not running sudo git clone [email protected]:project/somethiing.git
, otherwise ssh will look in /root/.ssh
instead of the key you uploaded ~/.ssh/id_rsa
if you are in Linux or macox , just try this in terminal:
ssh-add -l
if it return nothing, try this:
ssh-add
it must create identity in ~/.ssh/id_rsa
after retry :
ssh-add -l
it must return your identity, so after retry to clone, it's must work
NB: don't forget to add your ssh key in your profile gitlab
thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With