10

I'm trying clone a repository with http using the username and password lik e this:

git clone https://username:password@gitlab.com/user/repo.git

However I get this error:

fatal: unable to access 'https://username:password@gitlab.com/user/repo.git': Illegal port number

I'm trying to do this on a EC2 Instance that is using AWS Linux. I can get this working if I do it manually, and use only the username in the clone and then put the password to the prompt, but I'm trying to clone the repository with a bash script.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Miika
  • 402
  • 4
  • 13
  • 1
    Please specify whether you can reproduce this with the exact URL given (including the username `username` and the password `password`, f/e). If it can only be reproduced with a username and password that have certain characteristics, then the example given here need to have those characteristics; most particularly, the content of the literal password is relevant. – Charles Duffy Jan 12 '18 at 20:58
  • 1
    Alternately, I'd suggest running `bash -x yourscript`, and presenting the exact line for the `git clone` invocation -- if there are hidden, nonprintable, or otherwise surprising values in the variables you're suggesting, `xtrace` logs (with a new enough bash) should display them. – Charles Duffy Jan 12 '18 at 21:00
  • 2
    (I suspect strongly that this is a duplicate of [How can I escape `@` of password in git URL?](https://stackoverflow.com/questions/44733982/how-can-i-escape-of-password-in-git-url), but the question isn't detailed enough to permit certainty on that count). – Charles Duffy Jan 12 '18 at 21:03
  • Hey! Thanks for your comments. I did research, but the thing really is that I might not know what to research about, because that was all that I got from the error. I posted this question honestly only after 4 hours of trying to find some answers to the problems beforehand. The password contains characters such as # and % so that might cause some weird behavior there? I'll proceed to test this out. Thanks a lot! – Miika Jan 12 '18 at 21:28
  • 1
    I'm curious to hear the results of those tests -- please do [edit] the question based on what you find. If you need to know how to make a password with a literal `%` work, for example, that's a lot more concrete; just be sure that whatever placeholder or example password you include generates the same problem. – Charles Duffy Jan 12 '18 at 22:01
  • 1
    Placeholder validity should be easy to test, since this error happens before the remote server has been contacted, much less had a chance whether to test whether a given credential pair is correct -- so if a dummy password generates an authentication error instead of an "illegal port number", we know the issue at hand is resolved. Best of luck! – Charles Duffy Jan 12 '18 at 22:04

1 Answers1

4

With Charles' comments I figured out the reason why this error occurred. The password contained a %-character and a 4-character, which is the URL Encoded value of @-character. This caused it treat it as a proxy password (if I understood correctly.. basically the solution here.)

So what I did was I changed the password, and now it works just fine!

Miika
  • 402
  • 4
  • 13