I am new to gitlab and this is my first time using ssh. I could generate ssh key and add it into my account settings. I could clone the repo via ssh, I could checkout to my branch, but thing I still cannot do is push my change to the branch. Here is the step by step I generate the ssh key until I try to push it (by following instruction in here):
PS. I am using windows 10.
- on terminal (as admin), type:
ssh-keygen -o -t rsa -b 4096 -C "myemail@example.com"
. - Press
Enter
for default path of the ssh key - Provide password
- Create config file in
~/.ssh/
. Here is what I wrote in the config file:
Host ahostname
Hostname myhostname.com
User mygitlabusername
Port port
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
- copy the ssh key with this command:
cat ~/.ssh/id_rsa.pub | clip
- Placed the ssh key into my account settings
- Then, run
ssh -T git@myhostname.com
, and here is the result:
The authenticity of host '[myhostname.com]:port ([123.456.789]:port)' can't be established.
ECDSA key fingerprint is SHA256:xxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[myhostname.com]:port ([ipofmyshost]:port)' (ECDSA) to the list of known hosts.
Enter passphrase for key 'C:~/.ssh/id_rsa':
Welcome to GitLab, <myusername>!
- Then I try to clone a repo:
git clone ssh://git@myhostname.com/repo.git
- But, apparently, when cloning, it refer to another IP address. For example, let say
ipofmyhost
on thessh -T git@myhostname.com
is123.456.789
. Then, when I cloning, the IP is changed to123.456.781
(sorry I am afraid I couldn't mention the real IP). So, here is what I got when try to cloning the repo:
Warning: Permanently added the ECDSA host key for IP address '[123.456.781]:port' to the list of known hosts.
Enter passphrase for key '/c/.ssh/id_rsa':
- But, the clone done, then I checkout to my branch with
git checkout mybranchname
- Now, I am in my branch. Make little change. Try to
push
, but here is the error I got:
git@myhostname.com: Permission denied (publickey).
fatal: Could not read from remote repository. Please make sure you have the correct access rights
and the repository exists.
What I missed here? I found this question but sorry I do not understand what the accepted answer suggest me to do to solve this.
update
I've try to re-clone again, but before it, I delete all known_host
. Then, do git clone
again without testing with ssh -T git@myhostname.com
to avoid creating new IP address. But, I still got the same error when push my branch even no new ip address added to the known_host
.