0

I have a Bitbucket repo from which I am able to pull and push over HTTPS. Now, I'm trying to change HTTPS to SSH.

I have created an SSH key pair locally and I have added the public key to Bitbucket.

I have set the remote the following way:

git remote set-url origin git@my-repo.com:7999/my-project.git

Then, when I do git pull I am asking for my password three times and then I am denied permission:

Password:
Password:
Password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,keyboard-interactive).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I have two questions:

1.Why am I asked for my password if I'm using SSH?(and I haven't setup a password when creating the SSH key)

2.Why can I not connect to the server?

bsky
  • 19,326
  • 49
  • 155
  • 270
  • You'll need to tell ssh to use your private key as identity. Not sure how that works on Windows; on Linux one might use `ssh-agent` or edit the ssh configuration file to set `IdentityFile` value. See [more here](http://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command-with-or-without-ruby) – mustaccio Mar 17 '17 at 14:18
  • https://stackoverflow.com/questions/1558719/using-a-remote-repository-with-non-standard-port – Josh Lee Mar 17 '17 at 14:18
  • Is 7999 supposed to be a port number or a path? – Josh Lee Mar 17 '17 at 14:21
  • @mustaccio I did try the solution from that question, but I get the same error – bsky Mar 17 '17 at 15:02
  • @JoshLee 7999 is a port number – bsky Mar 17 '17 at 15:03

3 Answers3

1

You havn't added your private key to the ssh.agent.exe

You havn't told us about your environment.

This is how I use ssh keys daily.

Set alias for where my ssh-add is located. This just makes everything pretty.

Set-Alias ssh-add "C:\Program Files\Git\usr\bin\ssh-add.exe"

Start the SSH Agent - which servers your ssh keys

Start-SshAgent  -Quiet

Add your private key to your session

ssh-add C:\Users\username\.ssh\privateKey

Thats all.

I run those three commands in my $profile for powershell on windows.

kkflf
  • 2,435
  • 3
  • 26
  • 42
  • From Git Bash: `/c/Program\ Files/Git/usr/bin/ssh-add.exe /c/Users/my-user/.ssh/id_rsa`. For this, I am getting: `Could not open a connection to your authentication agent.` – bsky Mar 17 '17 at 15:57
  • Check if ssh agent is running in git bash with: `eval `ssh-agent.exe` If it is running it will printout something like this: `Agent pid 8772` If it is running, then you can add your ssh key: `ssh-add c:/path_to_key/.ssh/id_rsa` Are you sure that your ssh key is located `/c/Users/my-user/.ssh/id_rsa`? I have had exprience with keys being saved to `/c/Users/my-user/` so maybe the key is not actually in the .ssh folder? – kkflf Mar 18 '17 at 18:46
0

This URL is parsed as SSH over the standard port 22 with a path of 7999. Most likely the SSH server on port 22 does not authorize your git public key.

The syntax is

[user@]host.xz:path/to/repo.git/

Note that there's no room for a port.

The full SSH syntax is

ssh://[user@]host.xz[:port]/path/to/repo.git/

which should allow you to connect to the correct SSH port.

I often prefer to add an entry to my .ssh/config specifying the server details:

Host git
HostName git.example.net
User git
Port 7999
PasswordAuthentication no

Then I can use the short syntax of git:path/to/repo.git/.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
0

Check the permission of your public key. Are you pulling it for first time, then your key needs to have certain privileges.

You have locate your key file where you have save in your windows.

To set, view, change, or remove permissions on files and folders

  • Right-click the file or folder for which you want to set permissions, click Properties, and then click the Security tab.
  • Click Edit to open the Permissions for dialog box. Do one of the following:
  • To set permissions for a group or user that does not appear in the Group or user names box, click Add. Type the name of the group or user you want to set permissions for, and then click OK.

  • To change or remove permissions from an existing group or user, click the name of the group or user.

Do one of the following: - To allow or deny a permission, in the Permissions for box, select the Allow or Deny check box.

  • To remove the group or user from the Group or user names box, click Remove.

For more information you can check this link to setup the rights: https://msdn.microsoft.com/en-us/library/bb727008.aspx

danglingpointer
  • 4,708
  • 3
  • 24
  • 42