I do the necessary steps to create an ssh key, upload public key to bitbucket ssh keys. I then clone a repo using https. I noticed that cloning using git@XXX doesn't work and it gives a message. Bitbucket git push authentication failed (mac os x) Ask Question Asked 7 years. Press Add key. From the Add SSH key dialog, enter a Label and paste the public key from the clipboard. Press Add key. Bitbucket notifies you by email that you added a key to your repository. If you are using your key for a build system, it is a good idea to confirm the key is working correctly from the service or build server. Aug 01, 2015 BitBucket - Set up SSH key pair for Git. This short video shows how you can create a public/private SSH key pair and register your public key with BitBucket. Mar 29, 2017 Here is the simple video for add ssh key on bitbucket. Here is the simple video for add ssh key on bitbucket. How to create BitBucket Repo and BitBucket CI/CD Pipelines? Tech Primers.
For the past year or so, we’ve been using Git as our version control system. My introduction to the GUIs around Git was SourceTree (although I’ve made an effort to learn the commands) but I have also used poshgit and Git Bash. Recently, we’ve started using SSH keys instead of HTTPS and I had to learn how to set up my repositories with SSH. Everywhere and everyone tells you this is straight forward and it is when the critical path works but when something is wrong, it gets more difficult. A lot of unnecessarily complex documents does not help either. So I’m going to details all the steps that I took in the hope that it could helps someone.
Bitbucket Ssh Key
My setup for this task is Git (you can use the embedded git within SourceTree), SourceTree and BitBucket (previously used Google Drive to host my git repositories).
- Open SourceTree and click on the Terminal icon (this is Git Bash)
- Type the following command in
- ls –all ~/.ssh (this will list any existing ssh keys in C:Users.ssh, this is the default but can be changed when generating the key).
- Next, generate the key
- ssh-keygen –t rsa –b 4096 –C “”
- It will ask you where you’d like to store the files, I accepted the default but you can specify a directory if you wish.
- Then enter a passphrase, I would recommend you provide a passphrase from a security standpoint.
- You should now see this this:
- There should be two key files id_rsa (private) and id_rsa.pub now created.
- Still using the terminal (Git Bash) in SourceTree, type:
- eval $(ssh-agent). There are many ways to start the SSH agent but this is only way it would work for me. It should give you a process id back, something like, Agent pid 1234
- Finally using this command to add the new key
- ssh-add ~/.ssh/id_rsa
- If successful, the output should say that an identity has been created.
- You should never have to type in the passphrase again.
- Log into BitBucket
- Select the icon on the top right of the browser and select Manage Account
- From the Security menu, select SSH Key then Add Key
- Add you public key (id_rsa.pub) to the text area and then Add Key again
Note, your public key in this file is in a different format from what BitBucket expects. My recommendation for this scenario is to go to SourceTree – Tools – Create or Import SSH Keys. This starts a Putty Generator that has the ability to load existing keys. The generator will then show the public key in a user friendly format to be copied and used within BitBucket.
In Stage 1, the SSH key was generated and set up for the Git Bash terminal, now we want to take that SSH key and use it within the SourceTree GUI.
- First step is to go to Tools – Create or Import SSH Key
- Load your existing private key in.
- Click on “Save Private Key”. This has to be saved in the Putty .ppk format. I would recommend that you didn’t save this private key to the .ssh folder in case of conflicts between two keys.
- Next is to launch the SSH agent – Putty comes with SourceTree.
- Make sure Pagent is running ( little computer with a hat on sitting in your windows tray).
- Add the key to the SSH agent by right clicking on Putty Pagent and selecting “Add Key”. It is Pagent that stops the user from entering the passphrase all the time by holding key and making it available to SourceTree.
- A further step is to add the .ppk key to Tools – Options – General – SSH Client Configuration.
That’s it! I was all around the houses trying to fix various errors and configure. Some of the problems I faced were:
- Permission denied (public key). I believe it was a combination of errors on my part. One, I had created too many key files in the .ssh directory and it didn’t know what one to choose. Second, I hadn’t set up SourceTree correctly. The SSH key had to be a .ppk key and not the id_rsa key, which I’d generated.
- Could not open a connection to your authentication agent. I believe this was down to me changing from Putty to OpenSSH. OpenSSH just never launched, no wonder it couldn’t get a connection.
- It took ages to clone a repository. SourceTree GUI doesn’t give a lot of feedback with what is going on, not like Git Bash. I thought it wasn’t working.
My tip would be to test the connection using “ssh –T [email protected]”. This command with provide decent feedback if you have or haven’t authenticated. So open Git Bash and type this in.
A good topic for debate is why go to all the trouble of using SSH keys? Why not, use HTTPS and cache you account details in winstore?
Update:
Discovered this morning that if you shut SourceTree down, if you use the Git Bash terminal, you will need to repeat Stage 2.
References
Bitbucket Create Ssh Key
You generate an SSH key through macOS by using the Terminal application. Once you upload a valid public SSH key, the Triton Compute Service uses SmartLogin to copy the public key to any new SmartMachine you provision.
Joyent recommends RSA keys because the node-manta CLI programs work with RSA keys both locally and with the ssh agent. DSA keys will work only if the private key is on the same system as the CLI, and not password-protected.
About Terminal
Terminal is the terminal emulator which provides a text-based command line interface to the Unix shell of macOS.
To open the macOS Terminal, follow these steps:
Bitbucket Set Up Ssh Key
- In Finder, choose Utilities from the Applications folder.
- Find Terminal in the Utilities listw.
- Open Terminal.
The Terminal window opens with the commandline prompt displaying the name of your machine and your username.
Generating an SSH key
An SSH key consists of a pair of files. One is the private key, which should never be shared with anyone. The other is the public key. The other file is a public key which allows you to log into the containers and VMs you provision. When you generate the keys, you will use
ssh-keygen
to store the keys in a safe location so you can bypass the login prompt when connecting to your instances.To generate SSH keys in macOS, follow these steps:
- Enter the following command in the Terminal window.This starts the key generation process. When you execute this command, the
ssh-keygen
utility prompts you to indicate where to store the key. - Press the ENTER key to accept the default location. The
ssh-keygen
utility prompts you for a passphrase. - Type in a passphrase. You can also hit the ENTER key to accept the default (no passphrase). However, this is not recommended.
You will need to enter the passphrase a second time to continue.
After you confirm the passphrase, the system generates the key pair.
Your private key is saved to the
id_rsa
file in the .ssh
directory and is used to verify the public key you use belongs to the same Triton Compute Service account.Never share your private key with anyone! |
---|
Your public key is saved to the
id_rsa.pub
;file and is the key you upload to your Triton Compute Service account. You can save this key to the clipboard by running this:Importing your SSH key
Now you must import the copied SSH key to the portal.
- After you copy the SSH key to the clipboard, return to your account page.
- Choose to Import Public Key and paste your SSH key into the Public Key field.
- In the Key Name field, provide a name for the key. Note: although providing a key name is optional, it is a best practice for ease of managing multiple SSH keys.
- Add the key. It will now appear in your table of keys under SSH.
Troubleshooting
You may see a password prompt like this:
This is because:
- You did not enter the correct passphrase.
- The private key on your Macintosh (
id_rsa
) does not match the public key stored with your Triton Compute Service account. - The public key was not entered correctly in your Triton account.
What are my next steps?
Right in the portal, you can easily create Docker containers, infrastructure containers, and hardware virtual machines.
In order to use the Terminal to create instances, set up
triton
and CloudAPI as well as the triton-docker
commandline tool.