Oct 14, 2014 Generate SSH Public Key for GitHub and Bitbucket By Zainul Abdin Tuesday, October 14, 2014 This post demonstrate how to generate SSH private and public key with simple steps and help you to add public key inside your GitHub and Bitbucket account. To authenticate your Rasa X server with the remote repository, you need to set up an SSH key that Rasa X can use for authentication. Please create a new, single-use SSH key for this (see instructions below). Also, make sure to restrict the SSH keys to only apply to your assistant’s repository. To generate a new SSH key pair follow these steps.
- Git Generate Ssh Key For Bitbucket
- Git Generate Ssh Key Bitbucket
- Git Bash Ssh Keys
- Puttygen
- Git Ssh Key Bitbucket
This is a starting point for using Bitbucket Pipelines in a Java project thatuses Maven. It does the following:
- Adding your SSH key to the ssh-agent. Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key. When adding your SSH key to the agent, use the default macOS ssh-add command, and not an application installed by macports, homebrew, or some other external source.
- When you set up SSH, you create a key pair that contains a private key (saved to your local computer) and a public key (uploaded to Bitbucket). Bitbucket uses the key pair to authenticate anything the associated account can access. This two-way mechanism prevents man-in-the-middle attacks. This first key pair is your default SSH identity.
- Automatic tasks:
- All branches: Build the project (
mvn clean verify
) master
branch: Deploy the build artifact (mvn deploy
)
- All branches: Build the project (
- Manual tasks (can be invoked within the Bitbucket UI):
- Release major version
- Release minor version
- Release patch
The manual release tasks
- Incrememnt the major, minor, or patch component of the
version
propertyin the project's pom.xml - Commit the change to pom.xml to
develop
- Tag
develop
with the updated version - Merge
develop
intomaster
For this to work, you should follow these rules:
- Create a new branch for all new features, bugfixes, etc.
- Merge branches into
develop
only. Don't merge directly intomaster
. - Don't merge branches with broken builds into
develop
. - Only use semver versions in pom.xml, but stick to
MAJOR.MINOR.PATCH
(no suffixes, e.g.-beta
) otherwise version bumpingwill fail. - Don't use snapshot versions.
To set up an Artifactory server and to configure Java projects for deploymentto Artifactory, seesteve-taylor/artifact-server-config.
Configuring Bitbucket Pipelines
bitbucket-pipelines.yml by itself isn't quite enough to fully configure yourproject for Bitbucket Pipelines. You will need to provide some additionalsettings in Bitbucket.
Environment variables
The following environment variables need to be set withing Bitbucket.Fortunately, you can set all of these at the team level and they will beapplied to all repositories within the team.
Name | Example | Description |
---|---|---|
DEPLOYER_NAME | Deploy Bot | Deployment script name (appears in git logs) |
DEPLOYER_EMAIL | [email protected] | Deployment script email address (appears in git logs) |
MAVEN_REPO_URL | https://artifactory.example.com/artifactory | Maven repository URL |
MAVEN_REPO_RELEASES_KEY | libs-release | Public releases cache repo ID |
MAVEN_SETTINGS_PROFILE | artifactory | Profile name |
MAVEN_REPO_READER_USERNAME | me | CI/CD Maven read-only username |
MAVEN_REPO_READER_PASSWORD | swordfish | CI/CD Maven read-only password |
MAVEN_REPO_PUBLISHER_USERNAME | cicd | CI/CD Maven read-write username |
MAVEN_REPO_PUBLISHER_PASSWORD | super-secret | CI/CD Maven read-write password |
MAVEN_REPO_RELEASES_LOCAL_KEY | libs-release-local | Private releases repo ID |
ssh
Unfortunately, the ssh keys provided by Bitbucket Pipelines don't allow tasksto push back to their git repository. You will need to generate a new ssh keypair that allows Bitbucket Pipelines to push to git.
- Go to Settings / Security / SSH keys in your Bitbucket team.
- Click Add key
- Generate an ssh key pair and paste the public key into into the Keyfield. (The dialog contains links to instructions to generate an ssh keypair.)
- Provide a label and click Add key to finish adding the team-level sshkey.
- Navigate to your repo and go to Settings / Pipelines / SSH keys.
- If there is already a key, delete it.
- Provide the private and public keys from step 2.
For additional projects, repeat steps 5 to 7.
Note: Bitbucket will log warnings each time it pushes using the team-levelssh key, as it is a deprecated feature and they unfortunately recommend usingan individual account's ssh key instead. You're quite welcome to follow thatrecommendation if it makes you sleep better at night.
June, 2017 update: Setup SSH key for local dev box and use agent forwarding for servers
Create/setup the key on your server:
Git Generate Ssh Key For Bitbucket
- Login to server using SSH/terminal.
- Depending on your setup, you may need to
$ su -
and enter the root user’s password (depending on the steps you take below, this will create files in that user’s home directory with root permissions). - List the contents of
.ssh
directory:$ ls -a ~/.ssh
and check for an existingid_rsa.pub
; use that default identity in BitBucket (skip to next heading) or … - At the command prompt, type:
$ ssh-keygen
. - Follow the on-screen instructions (on a production machine, a password should be entered for security purposes).
- For comparison’s sake, list the contents of
.ssh
directory:$ ls -a ~/.ssh
. - Check to see if
ssh-agent
is running:$ ps -e | grep [s]sh-agent
. - If not (above command returns nothing) then run:
ssh-agent /bin/bash
. - Add newly-created key to the
ssh-agent
:$ ssh-add ~/.ssh/id_rsa
. - View list of keys the
ssh-agent
is managing:$ ssh-add -l
. - Run
$ cat ~/.ssh/id_rsa.pub
and copy the output to your clipboard.
Reversing the above process is easy:
Add key to BitBucket
Git Generate Ssh Key Bitbucket
- On BitBucket, choose
avatar
>Manage Account
. - Switch to the account you want to manage and click
SSH keys
; add a new key which should be named to match the server name (e.g.,dev.foodomain.com
). - Paste the key into the
Key
field and clickAdd key
.
Clone BitBucket repo
- Go to your repo in BitBucket and copy the
SSH
URI (e.g.,[email protected]:user-name/repo-name.git
). - SSH to your server and navigate to the location you want to clone the repo to.
- From the command line, run:
$ git clone [email protected]:user-name/repo-name.git
. Note: If you want to specify the folder name that the repo clones into, add that to the end of the command (e.g.,git clone [email protected]:user-name/repo-name.git target-folder-name
).
Git Bash Ssh Keys
Done!
Pulling updates
- SSH to your server.
- Navigate to your repo:
$ cd target-folder-name/
. - Run
$ git remote update && git status
$ git fetch
. - If there are changes to pull, then run
$ git pull
. - Optionally re-run
$ git remote update && git status
$ git fetch && git pull
to see if everything is clean.