# Setting an SSH key for bitbucket

**URL:** <https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829>\
**Category:** Build Environment\
**Tags:** ssh\
**Created:** [May 24, 2017, 9:00am UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829 "2017-05-24T09:00:29Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 24, 2017, 9:00am UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/1 "2017-05-24T09:00:29Z")

</div>

Hello,

I’m trying to SSH to circleci after enabling debugging, but I get a “Permission denied (publickey)” error.  
So according to [this](https://circleci.com/docs/1.0/ssh-build/) article I generated a new key pair and added an access key for my repository in bitbucket and then added the private key in the project settings under “SSH Permission” with host name “[bitbucket.org](http://bitbucket.org)” according to the steps described [here](https://circleci.com/docs/1.0/adding-read-write-deployment-key/).  
I also deleted the deploy key from circleci’s project settings under “Checkout SSH keys”.  
Now builds in cricleci are not starting, and there is an error "Your build was not run - reason code (:no-ssh-key)."  
This is the build: [https://circleci.com/bb/fleetonomy/main/53](https://circleci.com/bb/fleetonomy/main/53)

There are lots of combinations for SSH key configurations and there isn’t any clear documentation regarding that.  
I assume that if I’d like to SSH to circleci, I need to generate a private key, and circleci should have the public key.  
How should it be done?

Note - I have beta 2.0 enabled for my project, but the when I fallback into using circle.yml with old format, builds are working.

Thanks,  
Edi.

---

<div class="post-metadata">

**Author:** ![rohara](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rohara/32/5744_2.png) [@rohara](https://discuss.circleci.com/u/rohara)\
**Post date:** [May 24, 2017, 3:27pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/2 "2017-05-24T15:27:58Z")

</div>

Are you able to run `ssh -Tv git@bitbucket.org`?

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 24, 2017, 3:49pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/3 "2017-05-24T15:49:16Z")

</div>

Yes.

edi@ubuntu-edi:~/.ssh$ ssh -i id\_bitbucket -Tv [git@bitbucket.org](mailto:git@bitbucket.org)  
OpenSSH\_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug1: /etc/ssh/ssh\_config line 19: Applying options for \*  
debug1: Connecting to [bitbucket.org](http://bitbucket.org) [104.192.143.1] port 22.  
debug1: Connection established.  
debug1: identity file id\_bitbucket type 1  
debug1: key\_load\_public: No such file or directory  
debug1: identity file id\_bitbucket-cert type -1  
debug1: Enabling compatibility mode for protocol 2.0  
debug1: Local version string SSH-2.0-OpenSSH\_7.2p2 Ubuntu-4ubuntu2.1  
debug1: Remote protocol version 2.0, remote software version conker\_1.0.295-04975b3 app-131  
debug1: no match: conker\_1.0.295-04975b3 app-131  
debug1: Authenticating to [bitbucket.org:22](http://bitbucket.org:22) as 'git’  
debug1: SSH2\_MSG\_KEXINIT sent  
debug1: SSH2\_MSG\_KEXINIT received  
debug1: kex: algorithm: [curve25519-sha256@libssh.org](mailto:curve25519-sha256@libssh.org)  
debug1: kex: host key algorithm: ssh-rsa  
debug1: kex: server-\>client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none  
debug1: kex: client-\>server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none  
debug1: expecting SSH2\_MSG\_KEX\_ECDH\_REPLY  
debug1: Server host key: ssh-rsa SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A  
debug1: Host ‘[bitbucket.org](http://bitbucket.org)’ is known and matches the RSA host key.  
debug1: Found key in /home/edi/.ssh/known\_hosts:8  
debug1: rekey after 4294967296 blocks  
debug1: SSH2\_MSG\_NEWKEYS sent  
debug1: expecting SSH2\_MSG\_NEWKEYS  
debug1: rekey after 4294967296 blocks  
debug1: SSH2\_MSG\_NEWKEYS received  
debug1: SSH2\_MSG\_SERVICE\_ACCEPT received  
debug1: Authentications that can continue: publickey  
debug1: Next authentication method: publickey  
debug1: Offering RSA public key: id\_bitbucket  
debug1: Server accepts key: pkalg ssh-rsa blen 279  
debug1: Authentication succeeded (publickey).  
Authenticated to [bitbucket.org](http://bitbucket.org) ([104.192.143.1]:22).  
debug1: channel 0: new [client-session]  
debug1: Entering interactive session.  
debug1: pledge: network  
debug1: Sending environment.  
debug1: Sending env LC\_PAPER = he\_IL.UTF-8  
debug1: Sending env LC\_ADDRESS = he\_IL.UTF-8  
debug1: Sending env LC\_MONETARY = he\_IL.UTF-8  
debug1: Sending env LC\_NUMERIC = he\_IL.UTF-8  
debug1: Sending env LC\_TELEPHONE = he\_IL.UTF-8  
debug1: Sending env LC\_IDENTIFICATION = he\_IL.UTF-8  
debug1: Sending env LANG = en\_US.UTF-8  
debug1: Sending env LC\_MEASUREMENT = he\_IL.UTF-8  
debug1: Sending env LC\_TIME = he\_IL.UTF-8  
debug1: Sending env LC\_NAME = he\_IL.UTF-8  
debug1: client\_input\_channel\_req: channel 0 rtype exit-status reply 0  
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:

fleetonomy/main: bitbucket\_circleci – bitbucket\_circleci  
debug1: channel 0: free: client-session, nchannels 1  
Transferred: sent 3192, received 1856 bytes, in 0.4 seconds  
Bytes per second: sent 8680.5, received 5047.3  
debug1: Exit status 0

---

<div class="post-metadata">

**Author:** ![rohara](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rohara/32/5744_2.png) [@rohara](https://discuss.circleci.com/u/rohara)\
**Post date:** [May 24, 2017, 3:54pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/4 "2017-05-24T15:54:54Z")

</div>

What happens when you hit the `Add SSH Key` button on your build?

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 24, 2017, 3:59pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/5 "2017-05-24T15:59:26Z")

</div>

After I click on it, it creates automatically a deploy key under “Checkout SSH keys” section, and the build are working. But I still can’t connect to the session with SSH.

edi@ubuntu-edi:~/.ssh$ ssh -i id\_bitbucket -Tv -p 64539 [ubuntu@52.15.226.190](mailto:ubuntu@52.15.226.190)  
OpenSSH\_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016  
debug1: Reading configuration data /etc/ssh/ssh\_config  
debug1: /etc/ssh/ssh\_config line 19: Applying options for \*  
debug1: Connecting to 52.15.226.190 [52.15.226.190] port 64539.  
debug1: Connection established.  
debug1: identity file id\_bitbucket type 1  
debug1: key\_load\_public: No such file or directory  
debug1: identity file id\_bitbucket-cert type -1  
debug1: Enabling compatibility mode for protocol 2.0  
debug1: Local version string SSH-2.0-OpenSSH\_7.2p2 Ubuntu-4ubuntu2.1  
debug1: Remote protocol version 2.0, remote software version OpenSSH\_6.6.1p1 Ubuntu-2ubuntu2.6  
debug1: match: OpenSSH\_6.6.1p1 Ubuntu-2ubuntu2.6 pat OpenSSH\_6.6.1\* compat 0x04000000  
debug1: Authenticating to 52.15.226.190:64539 as 'ubuntu’  
debug1: SSH2\_MSG\_KEXINIT sent  
debug1: SSH2\_MSG\_KEXINIT received  
debug1: kex: algorithm: [curve25519-sha256@libssh.org](mailto:curve25519-sha256@libssh.org)  
debug1: kex: host key algorithm: ecdsa-sha2-nistp256  
debug1: kex: server-\>client cipher: [chacha20-poly1305@openssh.com](mailto:chacha20-poly1305@openssh.com) MAC: compression: none  
debug1: kex: client-\>server cipher: [chacha20-poly1305@openssh.com](mailto:chacha20-poly1305@openssh.com) MAC: compression: none  
debug1: expecting SSH2\_MSG\_KEX\_ECDH\_REPLY  
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:RyNJSBdmMAc7oJFN6Kpg2EKehY2VGEvNvxk59ccBwUo  
debug1: Host ‘[52.15.226.190]:64539’ is known and matches the ECDSA host key.  
debug1: Found key in /home/edi/.ssh/known\_hosts:15  
debug1: rekey after 134217728 blocks  
debug1: SSH2\_MSG\_NEWKEYS sent  
debug1: expecting SSH2\_MSG\_NEWKEYS  
debug1: rekey after 134217728 blocks  
debug1: SSH2\_MSG\_NEWKEYS received  
debug1: SSH2\_MSG\_SERVICE\_ACCEPT received  
debug1: Authentications that can continue: publickey  
debug1: Next authentication method: publickey  
debug1: Offering RSA public key: id\_bitbucket  
debug1: Authentications that can continue: publickey  
debug1: No more authentication methods to try.  
Permission denied (publickey).

---

<div class="post-metadata">

**Author:** ![rohara](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rohara/32/5744_2.png) [@rohara](https://discuss.circleci.com/u/rohara)\
**Post date:** [May 24, 2017, 4:39pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/6 "2017-05-24T16:39:08Z")

</div>

Can you push a build with these commands in the config?

```auto
ls -la ~/.ssh
cat ~/.ssh/authorized_keys

```

You can cancel it or let it run, but you need to rebuild it with SSH.

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 24, 2017, 9:49pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/7 "2017-05-24T21:49:18Z")

</div>

Did it.  
it’s under build [https://circleci.com/bb/fleetonomy/main/58](https://circleci.com/bb/fleetonomy/main/58)  
Can you see it?

Thanks

---

<div class="post-metadata">

**Author:** ![rohara](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rohara/32/5744_2.png) [@rohara](https://discuss.circleci.com/u/rohara)\
**Post date:** [May 24, 2017, 9:56pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/8 "2017-05-24T21:56:04Z")

</div>

Do either of those keys match your local key? The file is definitely populating correctly.

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 24, 2017, 10:05pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/9 "2017-05-24T22:05:38Z")

</div>

Actually neither of the keys match.  
Maybe you generate the public key from the private key with non default parameters?  
I used this one to generate the public key from my private key:  
ssh-keygen -y -f “private key file”

---

<div class="post-metadata">

**Author:** ![rohara](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rohara/32/5744_2.png) [@rohara](https://discuss.circleci.com/u/rohara)\
**Post date:** [May 24, 2017, 10:35pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/10 "2017-05-24T22:35:54Z")

</div>

You need to add the key to your Bitbucket account manually. From [https://circleci.com/bb/fleetonomy/main/edit#checkout](https://circleci.com/bb/fleetonomy/main/edit#checkout) :

```auto
1. Open Inspect Element in your browser's developer tools.
2. Click Create User Key
3. Find the new public key generated in the Network tab.
4. Go to your Bitbucket account and add it manually.

```

Sorry for this inconvenience. It is a Bitbucket specific issue that is being addressed, but not fixed.

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 25, 2017, 10:35am UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/11 "2017-05-25T10:35:08Z")

</div>

Did it (still connecting to VM doesn’t work).  
But I don’t understand how it helps me connecting to the VM.  
Maybe I need to have the private key of this “user key”?

---

<div class="post-metadata">

**Author:** ![Eric](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eric/32/2759_2.png) [@Eric](https://discuss.circleci.com/u/Eric)\
**Post date:** [May 26, 2017, 8:38am UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/12 "2017-05-26T08:38:45Z")

</div>

Hi Edi,

I responded to your support ticket, but I’m copying the instructions for anyone else who wants to SSH with Bitbucket projects.

* * *

To get Bitbucket SSH working:

1. Add the CircleCI-generated User Key to Bitbucket. This is the current workaround while we work with Bitbucket automate this via their API:

2. Add my local public key to Bitbucket. (Also: “Bitbucket settings” -\> “SSH Keys” -\> “Add Key”, more info [here](https://confluence.atlassian.com/bitbucket/add-an-ssh-key-to-an-account-302811853.html))

3. Only after 1 and 2 are complete, run a new build with “Rebuild with SSH”. I tried to SSH into a build that I started before verifying steps 1 or 2 and they still failed.

---

<div class="post-metadata">

**Author:** ![edifleetonomy](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@edifleetonomy](https://discuss.circleci.com/u/edifleetonomy)\
**Post date:** [May 27, 2017, 4:37pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/13 "2017-05-27T16:37:32Z")

</div>

Thanks Eric.

Just for documentation - it worked for me only when in step 1.d. and step 2, I copied the key to my user’s SSH keys section. When copying it to team’s SSH keys or repository access keys, it doesn’t work.

Best,  
Edi.

---

<div class="post-metadata">

**Author:** ![powerman](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/powerman/32/2135_2.png) [@powerman](https://discuss.circleci.com/u/powerman)\
**Post date:** [October 2, 2017, 6:21pm UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/14 "2017-10-02T18:21:35Z")

</div>

Thanks! Any plans to fix this issue?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:39am UTC](https://discuss.circleci.com/t/setting-an-ssh-key-for-bitbucket/12829/15 "2018-06-18T11:39:30Z")

</div>


