Home > Back-end >  SSH GitLab pull always asks for password
SSH GitLab pull always asks for password

Time:10-02

(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.

CodePudding user response:

Your ssh key is generated with a passphrase and that's why it asks you for the passphrase.


SSH login without password

Your aim

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase: (THIS IS THE CATCH, just press enter here to leave it empty): 
Enter same passphrase again: (press enter again)
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

a@A:~> ssh-copy-id remote_username@remote_domain

or

a@A:~> ssh-copy-id remote_username@remote_IP

/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote_username@remote_domain password: 

There it will ask you to enter the password for the remote user on that remote server

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -p '22' 'remote_username@remote_domain'"
and check to make sure that only the key(s) you wanted were added.

Now try to login with

a@A:~> ssh remote_username@remote_domain

and you should get in


Source: http://www.linuxproblem.org/art_9.html

  • Related