Why would I get an "Error while opening SSH session" error when checking out source code from Stash in my Bamboo plan?
Asked by mickey13:

I am running Bamboo (5.7.0) and Stash (3.4.1) on the same machine. I have set up applications links and have enabled "Trusted Applications", "OAuth", and "Basic Access" in both Outgoing Authentication and Incoming Authentication. I have a linked a Stash repository in Bamboo. In my Bamboo plan, my first task is "Source Code Checkout" and I reference the linked repository. Here's part of the stack trace. Any ideas?

```
com.atlassian.bamboo.repository.RepositoryException: java.lang.RuntimeException: com.atlassian.bamboo.plugins.stash.repository.StashRepositoryException: com.atlassian.bamboo.repository.RepositoryException: com.atlassian.bamboo.plugins.git.GitCommandException: command /usr/bin/git ls-remote ssh://bd2155f1-ceb1-ffab-87ce-870dffffb824@127.0.0.1:59645/house/myapp.git failed with code 128. Working directory was [.]., stderr:Error while opening SSH sessionstdout:[Warning: Permanently added '[127.0.0.1]:59645' (RSA) to the list of known hosts., BAMBOO-SSH-PROXY: [While connecting to [git@stash.domain.com/11.11.111.111:7999]: Error while opening SSH session: org.apache.sshd.common.RuntimeSshException: Failed to get the session.], fatal: Could not read from remote repository., , Please make sure you have the correct access rights, and the repository exists.]
```


Answers:
author: rsperafico
body: Hello Mickey,

Thank you for your question.

Based on the information you have provided regarding Application Links, you have set them up using different authentication methods so every time a request is made the same not necessarily gets interpreted in the same way on the other end.

When using Bamboo 5.6+ and Stash 3.2+ we would suggest on creating application link with default settings, so could you remove the existent one and recreate it as per following:

* *The servers have the same set of users and usernames **disabled***
* *I am an administrator on both instances **enabled***

will result in application link created with:

* *Trusted Apps authentication **disabled***
* *OAuth authentication **enabled**:*   
  *\* Allow 2-Legged OAuth **enabled***   
  *\* Allow user impersonation through 2-Legged OAuth **disabled***
* *Basic Auth authentication **disabled***

Important to notice the following should be same used to access the application from your web browser.

* Hitting Bamboo from your web browser: http://bamboo.base.url

* Bamboo administration \>\> System \>\> General configuration \>\> Base URL (http://bamboo.base.url)

* Hitting Stash from your web browser: http://stash.base.url
* Stash administration \>\> Settings \>\> Server Settings \>\> Base URL (http://stash.base.url)

* Stash administration \>\> Settings \>\> Server Settings \>\> SSH access
* \* \[x\] SSH enabled
* \* \[x\] SSH access keys enabled
* \* SSH Port: 7999

In case you continue on experiencing issues, I would suggest you on raising a Support ticket and adding this Question to the tickets description along with a Bamboo Support Zip.

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

---

Kind regards,  
Rafael P. Sperafico  
Atlassian Support

comments: author: mickey13
body: Thanks Rafael. I deleted the application link and recreated it. I also verified that the settings you mentioned were correct. I also needed to open up port 7999 on my hardware firewall as well as my server firewall, even though my Bamboo instance and Stash instance run on the same machine.


author: Pierre Penninckx
body: Hi I have exactly the same problem, same error message. I used a default link between the two, resulting in the same configuration as you said. In my case I use Bamboo 5.9.1 build 5914 and Stash v3.10.2.What could it be?


author: Sujit Kumar
body: Hello Pierre/Rafael,I am also running into the same issue and my versions of Bamboo and Stash are same as one specified by Pierre.Kindly let me know the resolution for the same.


author: Pierre Penninckx
body: Hello,It seems I simply needed to open the 7999 and 49366 internet facing ports. Altough, like Mickey, I don't understand why.


Tags: bamboo-administration