38

Everything was working perfectly fine. Did some git pushes with no problems.

Today I decided to update my framework to the latest version, so it changed the directory structure of my project a bit. So within Bitbucket, I created a new repository (dev1.project.com) and renamed my project's folder from OldName to dev1.project.com.

I edited .git/config to point my new repository:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[branch "master"]
[remote "origin"]
        url = https://bitbucket.org/user/dev1.project.com.git
        fetch = +refs/heads/*:refs/remotes/origin/*

When I do git remote -v, I get :

origin  ssh://git@bitbucket.org/user/dev1.project.com.git (fetch)
origin  ssh://git@bitbucket.org/user/dev1.project.com.git (push)

I go back to my project folder, and type:

git init
git add .      
git commit -m 'my first commit'
git push -u origin master

but I keep getting the following error:

ssh: connect to host bitbucket.org port 22: Connection timed out
fatal: The remote end hung up unexpectedly

The command ssh -T git@bitbucket.org gets me the same messages as above.

The command: git config --get remote.origin.url shows:

git@bitbucket.org:user/dev1.project.com.git

status.bitbucket.org shows that everything works fine on their side.

Not sure why it was working before, and not working now.

I'm on CentOS and i'm not sure what I should do next. I've seen a couple iptables-related answers, so I tried this:

iptables -t filter -A OUTPUT -p tcp --match multiport --dport 22 -j ACCEPT

service iptables stop
service ip6tables stop
service sshd reload
service iptables start
service ip6tables start

But still nothing, any ideas?

Ps: I've also updated CentOS from 6.6 to 6.7 and PHP 5.4 to 5.6, but didn't think it would matter.

Update #1

Ran the following commands:

ps x | grep ssh-agent
eval `ssh-agent -s`
ssh-add     # then it asked for my password

Got the message:

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

Then

service sshd restart

But still nothing

Update #2

I email my VPS hosting company, asking if there is anything I can do to open port 22, and they answered:

I have disabled the monitoring system on the host node blocking traffic to Bitbucket.

I don't know what it means, but everything was working after that, and apparently I couldn't do anything about it.

Michael
  • 8,362
  • 6
  • 61
  • 88
user3489502
  • 3,451
  • 9
  • 38
  • 66
  • There is a typo: `service sshd restart` should be `service ssh restart` – Joost Döbken Mar 17 '16 at 10:02
  • could you also include links to where you found these solutions? – Joost Döbken Mar 17 '16 at 10:03
  • Up, I the same with this error. But I don't know how to fix them, can you explain about solution? – DinhNguyen Apr 29 '16 at 02:22
  • This was very useful, I am running RHEL 7 on a VM and after your post I temporarily disabled the firewall on my router and I was able to establish a connection. Thank you for posting the solution to your issue. – Eric Mar 04 '17 at 04:55
  • See also my Q: [Cannot `git clone` Bitbucket repo on Windows: `ssh: connect to host bitbucket.org port 22: Network is unreachable`](https://stackoverflow.com/q/76918674/4561887) and [answer](https://stackoverflow.com/a/76925306/4561887). – Gabriel Staples Aug 17 '23 at 21:56

2 Answers2

128

I have done below mentioned things and it started working.

 vim ~/.ssh/config

Add these lines and save it.

Host bitbucket.org
    Hostname  altssh.bitbucket.org
    Port  443

For Windows:

  • Go to the place where your .ssh folder is located (run %USERPROFILE%).

  • open the .ssh folder and create a file with the name config without any extension.

  • Paste the below content and save it.

    Host github.com
              Hostname ssh.github.com
              Port 443
    
    Host bitbucket.org
              Hostname  altssh.bitbucket.org
              Port  443
    
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
Pardeep Kumar
  • 1,629
  • 1
  • 11
  • 9
  • Many thanks! Could you elaborate what is the problem here? – IProblemFactory Jan 08 '18 at 09:34
  • what does altssh do here ? – fireball.1 Jan 09 '18 at 11:37
  • 3
    Please check following links. it will help you to understand the problem https://about.gitlab.com/2016/02/18/gitlab-dot-com-now-supports-an-alternate-git-plus-ssh-port/ http://www.garbers.co.za/2014/03/03/connecting-to-bitbucket-on-https-port/ – Pardeep Kumar Jan 09 '18 at 11:41
  • didn't work! says: ssh: connect to host bitbucket.org port 22: Operation timed out – Sourabh Nov 24 '20 at 21:06
  • how do I save the changes on MacOS? – amm965 Mar 02 '23 at 08:50
  • I ended up discovering the same thing: [The fix: route SSH traffic to Bitbucket.org through port 443 instead...if your network admins are blocking external traffic on port 22](https://stackoverflow.com/a/76925306/4561887). I go into a lot more detail, and explain how to use `nmap` and `ncat` to identify if your network admins are blocking traffic to bitbucket on port 22. – Gabriel Staples Aug 17 '23 at 21:55
0

try to use this command.

ssh-add ~/.ssh/id_rsa

"id_rsa" is the file you create when you generate ssh key.

Murphyst
  • 19
  • 3