36

First, I am an absolute noob with git, repos and command line. I have repo on Bitbucket and I basically want to be able to push to the repository via gitbash without entering a password each time.

What I have:

  • A repository on Bitbucket with the code already set up.
  • A local directory where the repository is cloned.
  • A public key and a private key generated via PuTTY.
  • Public key added to Bitbucket via the Manage SSH keys page.

How do I now make it work so that I don't have to enter the password each time I push from the gitbash terminal? I'm using Windows 10.

Alex
  • 865
  • 13
  • 24
Sujan Sundareswaran
  • 2,324
  • 2
  • 11
  • 25
  • Try following the steps given in this page: https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html – user Apr 23 '16 at 15:18
  • 1
    I had this problem too: For clarity, I cloned the repo to my local machine from bitbucket using the suggested 'git clone' command which had https, THEN I added an SSH key to bitbucket. It would always still ask for the password. Then I realised the suggested 'git clone' command had changed to use the git/ssh protocol after adding the key... you need to update the remote. – Jetski S-type Mar 06 '19 at 23:14

7 Answers7

60

Please follow the steps to add ssh key into bitbucket account to solve your issue.

  1. Open git bash terminal and enter the command ssh-keygen -t rsa -C "your email address"
  2. Enter passphrase (leave it blank) and enter
  3. Enter the same phrase again (leave it blank) and enter
  4. Copy the id_rsa.pub file content from where it is residing in your system (C:\Users\username\.ssh)
  5. Login to bitbucket account and click top right most user icon ->bitbucket settings->ssh keys under security menu then paste into key field and save it.
  6. Restart your git bash terminal and enter git init command and add ssh git repository location git@bitbucket.org:username/repository_name.git which is present in your bitbucket repository.

Enjoy!

Olaf
  • 10,049
  • 8
  • 38
  • 54
Rajesh Kumar
  • 718
  • 6
  • 8
  • Works like a charm. FYI the public key and private key will be created ensure to add it to /home/.ssh file – Doogle Nov 16 '18 at 11:04
  • I kept having to input the password when cloning too. This solved my problem, because I created they keys without the password. How I didn't think of that, I don't know! I guess I thought it would be less secure? Are there any severe security implications to not having a password on this? – Steve Borland Jun 25 '19 at 06:41
  • Thanks a lot, perfect. Wasted ton of time on each Windows I had been working with - thanks to this solution now I waste only 3min instead of half an hour to get it running on a new machine. – FlorianH May 09 '23 at 14:54
  • https://bitbucket.org/skillservice/workspace/settings/ssh-keys - Direct Link to reach – Ajay Gangarde Aug 19 '23 at 11:02
10

There are two ways to load a remote git repository: using SSH and using HTTPS.

SSH will use a key pair, and requires the public key to be added to your BitBucket/GitHub profile.

HTTPS requires your BitBucket/GitHub username and password. You will be prompted for your password every time you interact with the remote server (for common git commands like clone, fetch, push, pull).

If you are currently being prompted for a password, that means the remote URL is currently set to use HTTPS. You can determine this be running git remote -v. To change to use SSH, you need to update the remote URL to the SSH URL by running git remote set-url <remote alias> <SSH URL>. If you only have one remote server, <remote alias> will be origin. You can find the SSH URL in BitBucket/GitHub under the clone option of the repository.

Prem G
  • 162
  • 3
  • 8
Andrew
  • 1,226
  • 2
  • 13
  • 20
  • 2
    I think this is frequently the issue for users. They don't realize they were using the HTTPS protocol rather than SSH. As Andrew says, if you are seeing a password prompt, it means you are using HTTPS rather than SSH. – james Nov 17 '18 at 21:25
  • This is the answer. – Jetski S-type Mar 06 '19 at 23:17
7

1) create .ssh folder under your home directory like: mkdir C:\Users\USERNAME\.ssh

2) Copy id_rsa and id_rsa.pub into directory from previous step

3) Close and open cmd (console window)

4) You need to clone the repository as SSH repository, like: git clone ssh://git@bitbucket.test.com:USERNAME/repository.git

Then it should work.

vagovszkym
  • 1,432
  • 12
  • 16
3

Following this guide

I think you are missing that after you have generated the SSH keypair, you need to add the SSH private key to pageant, PuTTY’s key management tool.

First, run pageant, which can be found in the directory where you have installed PuTTY package (remember, by default: c:\Program Files\PuTTY). You will see a small icon in your system tray (see the screenshot to the right), which indicates pageant is started. Click on the icon and in pageant window click “Add Keys”. Add the private key that was generated by puttygen in the previous step. The private key has extension .ppk, that is the easiest way to distinguish it from the public key you have created.

After you add the SSH key, you should see it in pageant key list.

Alex
  • 865
  • 13
  • 24
1

Don't use PuTTY to generate the key. Create a new key with ssh-keygen in .ssh. Leave passwords blank. Open that new key in PuTTY. Copy and paste it into the Bitbucket Key field. Save key with PuTTY and Bitbucket. It should work.

0

if you need to update multiple putty sessions on windows via powershell:

set-Itemproperty -path HKCU:\Software\SimonTatham\PuTTY\Sessions\sessionname -name PublicKeyFile -value "C:\Users\username.ssh\putty.ppk"

Jamin
  • 146
  • 4
0

For Windows 7 users:

  1. Open Git Bash and type ssh-keygen, and press Enter three times (one for location, and two for empty passphrase).
  2. Now, a dir .ssh should list these two files: id_rsa id_rsa.pub
  3. Add the public key to your Bitbucket settings, as described in Set up an SSH key , Step 3. You basically copy paste the contents of file "id_rsa.pub" to your profile in BitBucket via the web interface (no admin rights required of course).
  4. Restart Git Bash.
  5. Go the destination directory, where you would like to clone your repository and do a git init
  6. Get the ssh from the Clone of the repo, and then do git clone ssh://git@bitbucket.test.com:YOURUSERNAME/myrepository.git
gsamaras
  • 71,951
  • 46
  • 188
  • 305