Could not read from remote repository with SSH

Viewed 1092

I did all steps and I cannot connect to remote repository.

I added the ssh key to my GitLab account but I have error:

user@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Full output:

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ ssh-keygen -t rsa -b 4096 -C "email@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user/.ssh/id_rsa):
Created directory '/c/Users/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/user/.ssh/id_rsa
Your public key has been saved in /c/Users/user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxxx email@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
...
+----[SHA256]-----+

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git push origin master
The authenticity of host 'gitlab.com (...)' can't be established.
ECDSA key fingerprint is SHA256:....
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,...' (ECDSA) to the list of known hosts.
user@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git remote get-url
usage: git remote get-url [--push] [--all] <name>

    --push                query push URLs rather than fetch URLs
    --all                 return all URLs


user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ git remote get-url origin
ssh://gitlab.com/myaccount/instabot.git

user@DESKTOP MINGW64 ~/Desktop/instabot (master)
$ eval `ssh-agent -s`
Agent pid 1189
1 Answers
user@gitlab.com: Permission denied (publickey).

Try and change the SSH URL to:

cd /path/to/repo
git remote set-url origin git@gitlab.com:myaccount/instabot.git

Note that the SSH user should always be "git@", not "user@"

Related