Generate Ssh Key File For Bitbucket
To generate an SSH Key, select Tools Create or Import SSH Keys. This window should pop up: 2. Click Generate, and move the mouse randomly until a key is generated: 3. A public key and a private key should appear. This is how the.pub and the.ppk files should appear in your.ssh. Dec 01, 2010 Scroll down to the SSH Keys section. Copy your public key from the PuttyGen window where it says ‘Public key for pasting into OpenSSH authorizedkeys file’ and paste it in the textbox next to the ‘Add Key’ button. Now press ‘Add Key’ and Bitbucket should store the key for you.
Configuring SSH access to servers for your builds and deployments on Bitbucket Pipelines used to be a real pain. We had a manual process that involved generating keys locally, then base64 encoding them to pass through environment variables in your build. You also needed to add hosts to the SSH known_hosts file so various commands didn’t fail with cryptic error messages. We saw an opportunity to make this experience a whole heap better.
Improved SSH configuration for Pipelines
We’ve designed a new configuration screen for your Bitbucket repository that lets you generate and configure SSH keys for your pipelines with a single click. The private key will be encrypted, kept securely within Bitbucket, and automatically registered in your pipeline build container. You then simply copy/paste the public key on to your remote host to give your build access to it.
Adding your remote hosts to the known_hosts file in your build is just as easy. Type in the hostname and Bitbucket automatically pulls down the host’s public key, and lets you verify the fingerprint. If everything looks is okay, add your hosts to the configuration with a single click.
With these small improvements, configuring SSH access for Pipelines now takes just a few seconds instead of half an hour of error-prone tweaking.
Learn more about using SSH keys in Pipelines. Happy Pipelining!
In the previous post I mentioned about what is Continuous Integration and how to configure one such tool, Jenkins. There when configuring a new job we had a setting where we have to specify the git account in order to get the source code from. Today I am going to talk about how to specify credentials to link this git account(bitbucket) with Jenkins.
Pre-requisites
- Jenkins server installed.
- Git installed.
- Bitbucket account.
- Bitbucket repository.
How to Link Bitbucket with Jenkins
Generate SSH key
- Open Git Bash terminal.
- If you have installed ssh the following will be displayed. If not you have to install ssh via your package manager.
- List the contents of your
~/.sshdirectory.
If you have not used SSH on Bash you might see something like this:
/crypkey-cant-generate-site-key-when-remote-desktop.html. If you have a default identity already, you’ll see two id_* files:
Now We can create the ssh keys.
- Enter
ssh-keygenat the command line.
The command prompts you for a file to save the key in: (Press enter to save in default location –c/Documents and Settings/(user)/.ssh/id_rsa) - Enter and renter a pass phrase when prompted. (Do not enter a password)
- The command creates your default identity with its public and private keys. The whole interaction looks similar to the following:
id_rsa id_rsa.pub
Next step is to create SSH config file and update .bashrc profile.
- Copy this config file to ~/.ssh folder ( C:
/Documents and Settings/(user)/.ssh) Then copy this .bashrc file to user folder (C:/Documents and Settings/(user)/)Close gitBash.Reopen gitbash.
Now verify the that the script identity added your identity successfully by querying the SSH agent issuing ssh-add -l command. Something similar to following should display.
20480f:37:21:af:1b:31:d5:cd:65:58:b2:68:4a:ba:a2:46/Users/(user)/.ssh/id_rsa (RSA)

Now we have created the ssh keys. The next step is to add the public key to Bitbucket account.
- Log on to Bitbucket account.
- Choose avatar –> Mange Account
- Click SSH Keys.
- In your terminal window,
catthe contents of the public key (cat ~/.ssh/id_rsa.pub) file or open id_rsa.pub with notepad. - Select and copy the key output in the clipboard.
- Enter a Label for your new key.
- Paste the copied public key into the SSH Key field.
- Click the Add key button.
- Return to the terminal window and verify your configuration by entering the following command.
- The command message tells you which Bitbucket account can log in with that key.
Bitbucket Create Ssh Key
Next we have to add the private key to Jenkins in order give authentication for Bitbucket for Jenkins.
Generate Ssh Key Bitbucket Windows
- In Jenkins Dashboard click Credentials.
- Click Global credentials.
- Next click Add credentials which will open a form where you can add credentials.
- From kind drop down list select SSH username with private key.
- Type a user name and then copy the id_rsa key ( C:
/Documents and Settings/(user)/.ssh/id_rsa)or check From a file on Jenkins master and give the path. ( C:/Documents and Settings/(user)/.ssh/id_rsa) - Click OK.
- Now when you give project repo on Jenkins jobs you can select this private key to give authentication for Bitbucket.