This is a guide on port forwarding port 22 (SSH) in Windows and Linux for Bitbucket Server. This is done so that your users would not need to enter any port number when interacting with your Bitbucket Server.
If you attempt to clone a Bitbucket Server repository on SSH, you might stump into this problem:
D:\Documents\repos>git clone ssh://git@localhost/test/test-repo.git Cloning into 'test-repo'... ssh: connect to host localhost port 22: Connection refused fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Bitbucket Server listens for SSH connections on port 7999 by default.
Your users will need to include the port in the URL they use to clone from Bitbucket Server, for example:
git clone ssh://git@localhost:7999/test/test-repo.git
Rather than have the port number in the URL, you may wish to set up port forwarding so that connections to the default SSH port are forwarded to the port Bitbucket Server is listening on (e.g. you could forward port 22 to port 7999).
This would allow your users to use a URL without a port number in it, like this:
git clone ssh://git@localhost/test/test-repo.git
This simple how-to will guide you on how to port forward the SSH port on a Linux or Windows environment.
Solution for Linux
Solution for Windows
- Open the command line prompt in Administrator’s mode and check if there are any existing routes that might interfere, using the command below:
netsh interface portproxy show all
- If no results are found, you can start to port forward the SSH port using the command below:
netsh interface portproxy add v4tov4 listenport=22 connectport=<BITBUCKET_SERVER_SSH_PORT> connectaddress=<BITBUCKET_SERVER_IP>
- Run the same command as step 1 to check the results of your port forwarding:
C:\WINDOWS\system32>netsh interface portproxy show all Listen on ipv4: Connect to ipv4: Address Port Address Port --------------- ---------- --------------- ---------- * 22 localhost 7999
- Attempt to clone your repository once more:
D:\Documents\repos>git clone ssh://git@localhost/test/test-repo.git Cloning into 'test-repo'... The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is SHA256:jtrT+G9H9TPaZzcknnMsR8yJiK7PF0+xnYuNIxjRZuc. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (RSA) to the list of known hosts. Enter passphrase for key '/c/Users/jalex/.ssh/id_rsa': >warning: You appear to have cloned an empty repository. Checking connectivity... done.