How to use the SSH key for Bitbucket projects?

2019-07-13 14:24发布

问题:

My steps to generate and use the SSH key in Bitbucket:

  1. ssh-keygen -t rsa -C "my email"
  2. cat ~/.ssh/id_rsa.pub
  3. copy my key ssh-rsa AAAAB3Nz... my email to clipboard
  4. in bitbucket access my configuration > SSH keys
  5. add the key
  6. in console of my ubuntu, I use the command: ssh -T git@bitbucket.org

After using the command from step 6, the following message appears:

$ ssh -T git@bitbucket.org
logged in as ricardoramos.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

When I make a push to my repository, still continues requiring my password.

It is very annoying to have to keep typing the password for every push.

Where am I wrong?

回答1:

You can't login to bitbucket's shell using SSH, but you did set up your key correctly, otherwise you wouldn't have gotten the "Shell access is disabled" message.

What you have to do is change the URL of your repo. Right now you have a HTTPS URL set, which requires a password. You can switch to an SSH URL like this:

git remote set-url origin [ssh url of your git repo]


回答2:

You need to use an ssh agent. try

$ ssh-add

before pushing. Supply your passphrase when asked.

If you aren't already running an ssh agent you will get the following message:

Could not open a connection to your authentication agent. In that situation, you can start one and set your environment up thusly

eval $(ssh-agent)

Then repeat the ssh-add command.

It's worth taking a look at the ssh agent manpage.

Go through this page you would get an better idea http://jonathannicol.com/blog/2013/11/19/automated-git-deployments-from-bitbucket/