6

I am trying to integrate gitlab CI on my node project, I have SSH access, but my script stop with error :

fatal: could not read Username for 'https://gitlab.com': No such device or address
debug2: channel 0: written 83 to efd 7
debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: chan_shutdown_write (i3 o1 sock -1 wfd 6 efd 7 [write])
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
#0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/7 sock -1 cc -1)
debug3: send packet: type 1
debug1: fd 0 clearing O_NONBLOCK
debug3: fd 1 is not O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Transferred: sent 3560, received 3156 bytes, in 0.7 seconds
Bytes per second: sent 5437.2, received 4820.2
debug1: Exit status 1
Cleaning up file based variables
00:01 ERROR: Job failed: exit code 1

I already tried

git config --global credential.helper store

git config --global user.password "myPassword"

git config --global user.email "myEmail"
  • I see that git does not offer a no interaction option...

  • image: node:latest with debian server

  • My ssh credentials and access is OK

  • When I test directly on the server, it still asks for my connection information

  • it's a private repository

Sacha Durand
  • 473
  • 1
  • 5
  • 11
  • 1
    `user.password` is not used. Never set it, because it's generally *readable* by anyone and you should generally not store your password where anyone can see it. But *Git* never *looks* at this value (it reads the file and sees it and throws it away because it's not looking for anything named `user.password`), so all you did was write your password in large clear letters where everyone *except* Git will see it. – torek Aug 23 '21 at 08:36
  • 1
    Meanwhile: *credential helpers* exist for `http` and `https`, but when using `ssh`, Git hands the operation off to a separate `ssh` command, which does not use Git's credential helpers at all. So the `credential.helper` setting is not relevant *unless* you ask Git to use `http` or `https` (which you seem to be doing here). Last, the `user.email` setting is used when you run `git commit` (only), not when you run `git push`. – torek Aug 23 '21 at 08:37

2 Answers2

24

Try changing your repo origin on server using this command:

git remote set-url origin https://username:access_token_or_password@gitlab.com/path_to_your_repo/repo.git

This way it won't ask for credentials while git pull or git push

Harshit Rastogi
  • 1,996
  • 1
  • 10
  • 19
  • thanks for your response ! with your command, I have this message : error: insufficient permission for adding an object to repository database .git/objects. Is there a way to not go through the protocol associated with git, but rather with the classic https ? – Sacha Durand Aug 23 '21 at 10:03
  • check out this answer https://stackoverflow.com/a/6448326/8269427 – Harshit Rastogi Aug 23 '21 at 10:24
  • it works now, it was necessary to execute set-url origin command, as well as to change the rights on the .git file and his components, and set group mod ! Thanks you very much ! – Sacha Durand Aug 23 '21 at 10:43
  • Glad it helped :) – Harshit Rastogi Aug 23 '21 at 11:24
1

This solution worked for me from gitlab https://wahlnetwork.com/2020/08/11/using-private-git-repositories-as-terraform-modules/ . In summary I setup a token and I executed the git config command from the pipeline

d4n13lbc
  • 11
  • 1
  • 4
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33332853) – Aaron Meese Dec 08 '22 at 21:51