Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH GitLab pull always asks for password

Tags:

git

ssh

gitlab

(GitLab specifically! (No issues with GitHub))
I'm trying to create a script to pull a project from main GitLab branch without asking for password. A couple of remote computers have a kiosk-mode project. It's kind of boring to always connect manually to them - instead of having a cron-job to pull automagically.

I've setup to use SSH and created and added my SSH ed25519 key.
Added the proper url in ./.git/config like:

[remote "origin"]
    url = [email protected]:<ME>/<REPO>.git

where <ME> and <REPO> are my username and repository :)

Using git pull or fetch always asks for password. The same does not happens on my GitHub repos.

The only way I managed to make it work was using a Personal Access Token like:

[remote "origin"]
    url = https://oauth2:<MY P. A. TOKEN>@gitlab.com/<ME>/<REPO>.git

But I don't like the token being in plaintext and having to do stuff out of the scope of SSH handshakes.

Is there something GitLab-specific I'm missing? Every help-page I was able to search just talks about setting the correct SSH URI ([email protected]..... etc) which I already did. But every time I trigger a git pull it keeps asking for password.

Windows. Git Bash.

Appreciate any help, trick or insight.

like image 306
Roko C. Buljan Avatar asked Apr 28 '26 23:04

Roko C. Buljan


2 Answers

I've just solved this problem for my gitlab.com repos: I've just followed the steps in their tutorial at Use SSH keys to communicate with GitLab.

There they explain how to create keys, but since mine already existed all I had to do was to follow the steps in the section Configure SSH to point to a different directory. They're only:

  1. Type the commands

    eval $(ssh-agent -s)
    ssh-add <full path to private SSH key>
    

    In Linux, the SSH keys are usually saved in the folder ~/.ssh/

  2. Edit the ~/.ssh/config file to have the lines

    Host gitlab.com
       PreferredAuthentications publickey
       IdentityFile <full path to private SSH key>
    
like image 64
Hilton Fernandes Avatar answered Apr 30 '26 12:04

Hilton Fernandes


I had the same problem on Windows, even the ssh -T [email protected] didn't work! The solution was a lot simpler that I thought: I had to open git bash as an administrator

like image 33
StardustOviedo Avatar answered Apr 30 '26 14:04

StardustOviedo