What does SSH Keys do in Github / Bitbucket?
Set up SSH to reduce the risk of exposing your username and password.Some reasons you might want to use SSH key base authentication:
Apr 10, 2018 Open the repository settings and select the “Access keys” link. Add access key. Select “Add key” and paste your copied key into the box. We only need read access for this purpose so select that and the click the “Add key” button. Add access key. Now you should see your key in the list. Install jenkins plugin for bitbucket and enable. Apr 10, 2019 You need to add your repository credential. We have already created the SSH public & private keys for Bitbucket. Also, we have added the public key content to the Bitbucket SSH key. In this step, we will need to add private key content to Jenkins credentials. For “Kind”, select “SSH Username with private key”. Feb 12, 2018 A private key(idrsa) saved to your Jenkins 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. Steps taken Create an SSH keypair. Add the public key as a deployment key for the repository on BitBucket. Install the SSH key and username (have tried both 'git' and my BB account name) in the Jenkins Credentials manager plugin. Attempt to clone the repository in the build using a URL in form of. Configure the SSH public key component of this key pair (which you can copy and paste from the Blue Ocean interface) for the remote Git server’s user account (e.g. Within the authorizedkeys file of the machine’s gituser/.ssh directory). Note: This process allows your Jenkins user to access the repositories that your Git server’s user account (e.g. Gituser) has access to.
- Is more effective if you push and pull from Bitbucket many times a day.
- Removes the need to enter a password each time you connect.
Environment
- Operating System : Ubuntu 16.04 LTS (64-bit)
Add SSH Keys in Ubuntu 16.04
The following steps showed the step by step installation guideline.
Set up your default identity
From the terminal, enter
ssh-keygen
at the command line.The command prompts you for a file to save the key in:It will create two files; one public key file and one private key file.Both file will have your given name.
Add Key files in local machine
Keep both of the files in
~/.ssh
location.Add the public key to your bitbucket settings
- In Bitbucket go to
Bitbucket settings>Account settings>SSH keys>Add key
- Copy the contents of your public key file using the following command:
N.B.:
id_rsa
is the name I have given when generating the key files. It might be something else for your case.3. Copy and paste the public key in the key
field in Bitbucket and include proper label. Click Save
.Ensure Bitbucket SSH connects successfully
Add Ssh Key Bitbucket
Return to the terminal window and write:
Jenkins Git Ssh Key
For github
Generate Ssh Key Bitbucket Windows
Give your passphrase which you have given when generating the key files.If your connection is successful then you will get output like following:
For Github:
References
- Set up an SSH key: Bitbucket documentation
- Change existing folder remote url: Github documentation