'Git Clone Error: The requested URL returned error: 403

We had bitbucket over http till recently and it was working fine. We are behind proxy. Recently we changed bitbucket to https and then we started getting this error.

The issue is as soon as we enter the git command, we are not prompted for credentials which was not the case earlier. I tried providing credentials in git command like git clone https:\\username:[email protected] .Still same error.

Telnet works fine to the bitbucket server. SSL connection also works fine.

The exact error is fatal: unable to access 'https://ourbitbucket.dummy/vcs/scm/devops/docker-builds.git/': The requested URL returned error: 403

⚡ root@dummyserver ~ cd gitrepo
 ⚡ root@dummyserver ~/gitrepo git clone https://ourbitbucket.dummy/vcs/scm/devops/docker-builds.git
Cloning into 'docker-builds'...
fatal: unable to access 'https://ourbitbucket.dummy/vcs/scm/devops/docker-builds.git/': The requested URL returned error: 403
 ✘ ⚡ root@dummyserver ~/gitrepo 
 ✘ ⚡ root@dummyserver ~/gitrepo telnet ourbitbucket.dummy 443
Trying 10.82.25.14...
Connected to ourbitbucket.dummy.
Escape character is '^]'.
^CConnection closed by foreign host.
 ✘ ⚡ root@dummyserver ~/gitrepo cd ..
 ⚡ root@dummyserver ~ java SSLPoke ourbitbucket.dummy 443
Successfully connected

Any idea whats wrong.



Solution 1:[1]

we are not prompted for credentials which was not the case earlier.

Check first if this is because the (wrong) credentials are cached and used automatically by Git

root@dummyserver
  git config credential.helper

If there is an entry for https://ourbitbucket.dummy, that would explain why there is no credential prompt.

Check also if there is a proxy configuration (git config -l | grep -i proxy) or a NO_PROXY environment variable (which might avoid the proxy for http URL, but not for https URL): env|grep -i proxy.

Solution 2:[2]

If you are trying to access a intranet/company bitbucket, you might not need a proxy to access it. If you are trying to access the company intranet bitbucket with a proxy, you can get the error 403.

If that is the case, you can try unsetting the proxy for the bitbucket address, for example:

export no_proxy=localhost,127.0.0.*,<example.bitbucket.company.com>
export NO_PROXY=localhost,127.0.0.*,<example.bitbucket.company.com>

After setting it, please check if no_proxy is correctly set by executing the following commands, if in bash:

echo $no_proxy

and

echo $NO_PROXY

You can also permanently set your proxies environmental variables and/or check if your proxies are set correctly across your linux. In both cases, this post can help you to check the environmental variables possible locations: https://unix.stackexchange.com/a/249922/525771 For RedHat, you can check here: https://access.redhat.com/articles/2133021

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 vcmorini