Set up SSH to reduce the risk of exposing your username and password. Some reasons you might want to use SSH key base authentication:
- 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.
Url formats of the repository differs from HTTPS
to SSH
:
HTTPS: https://<repo_owner>@bitbucket.org/<accountname>/<reponame>.git
SSH: git@bitbucket.org:<repo_owner>/<reponame>.git
or
ssh://git@bitbucket.org/<repo_owner>/<reponame>.git
- Operating System : Ubuntu 16.04 LTS (64-bit)
The following steps showed the step by step installation guideline.
From the terminal, enter ssh-keygen
at the command line.
The command prompts you for a file to save the key in:
ssh-keygen
It will create two files; one public key file and one private key file. Both file will have your given name.
Keep both of the files in ~/.ssh
location.
- In Bitbucket go to
Bitbucket settings>Account settings>SSH keys>Add key
- Copy the contents of your public key file using the following command:
cat ~/.ssh/id_rsa.pub
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
.
Return to the terminal window and write:
ssh -T git@bitbucket.org
For github
ssh -T git@github.com
Give your passphrase which you have given when generating the key files. If your connection is successful then you will get output like following:
logged in as YOUR BITBUCKET USERNAME.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
For Github:
Hi YOUR GITHUB USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
- Set up an SSH key: Bitbucket documentation
- Change existing folder remote url: Github documentation
very useful article mister