SSH keys for Bitbucket on Windows + TortoiseGit - windows

I am trying to connect to Bitbucket using the ssh keys on Windows.
I am using the console and TortoiseGit to manage the git repository.
What have I done?
I have ssh key pair generated using command "ssh-keygen"
Ssh key files have been inserted into "E:/Windows/Documents/ssh-keys/"
My user name is "hyb", so in "C:\Users\hyb\.ssh" I have created "config" file with content:
IdentityFile E:/Windows/Documents/ssh-keys/hyb_pc_repository
And great - when I enter the command:
eval $(ssh-agent)
everything works fine except TortoiseGit.
Console also stops working after rebooting the system...
I have changed TortoiseGit setting:
Still no luck.
I want to work with TortoiseGit and ssh-agent should start automatically.
What am I doing wrong?
Services:
#edit
Of course, the public key has been assigned to the bitbucket account (everything works fine on Ubuntu...)

Related

Git prompting for password when using SSH, even when SSH keys are present (but running as admin works). What is the issue?

In a corporate environment running Windows I have the following issue:
Using git via SSH via
git clone git#server:repo.git
I am prompted for a password:
git clone git#server:repo.git
Cloning into 'repo'...
git#server's password:
The SSH Key is not found, although my SSH key resides in C:\Users\[USERNAME]\.ssh.
However, running the command shell (CMD) as administrator, everything works just fine.
What is the issue and how can it be fixed?
(Note: I am answering my own question since the issue wasted hours of my time and I did not see it in other issues having similar "access denied" symptoms).
Getting "access denied" or haven SSH keys not recognised may have a variety of reasons, see also
https://serverfault.com/questions/194567/how-do-i-tell-git-for-windows-where-to-find-my-private-rsa-key
The issue above - where git works when run as local admin, but not as user - is possibly related to a specific setup in a corporate environment. In my case the machine had a folder C:\Users\[USERNAME] but also a profile on a network mounted drive (say N). The .ssh folder with my key resided in C:\Users\[USERNAME] but git was looking in N:
Running as (Local) Administrator on the Machine changed the behaviour and used the profile from C:\Users\[USERNAME].
To find your home folder:
open Git Bash on Windows
type cd ~;pwd
The issue is ultimately related to different settings of the environment variables HOMEDRIVE, HOMESHARE or USERPROFILE, see also Git bash home directory different from Git extension than Git Bash

push via ssh not working

Windows 10, using git via the Git Bash program installed. I have this working for bitbucket. I can't seem to get this working though with my server.
Have my keys on the Windows laptop: ~.ssh\id_rsa.pub & ~.ssh\id_rsa
The laptops public key is also on the server in the correct authorized_keys file
git remote add tillvaxt ssh://root#example.com:51022/srv/repo/tillvaxt.git
git add . -A
git commit -a
git push tillvaxt master
example.com's password:
How does one het to the root of the issue here? It doesn't exactly give one much information to work with.
After logging on my linux laptop and looking at all of the files the issue was found.
I had a ssh connection to my server working with my windows laptop via kitty. I added my key to a openssh docker container (I run two ssh servers, one for root server access, one for the specific container).
After adding my new key to the authorized_file in the docker container kittys terminal seemed to mess up the line breakings in the file, resulting in a very weird key mixup. It should be one key per row but the ssh-rsa bit was shifted to the end of the next line. I just fixed the lines and saved = works.

Setting up SSH keys for Bitbucket on Windows

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.
Please follow the steps to add ssh key into bitbucket account to solve your issue.
Open git bash terminal and enter the command ssh-keygen -t rsa -C "your email address"
Enter passphrase (leave it blank) and enter
Enter the same phrase again (leave it blank) and enter
Copy the id_rsa.pub file content from where it is residing in your system (C:\Users\username\.ssh)
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!
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 promoted for your password every time you interact with the remote server (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.
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.
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.
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.
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"
For Windows 7 users:
Open Git Bash and type ssh-keygen, and press Enter three times
(one for location, and two for empty passphrase).
Now, a dir .ssh should list these two files: id_rsa id_rsa.pub
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).
Restart Git Bash.
Go the destination directory, where you would like to clone your repository
and do a git init
Get the ssh from the Clone of the repo, and then do git clone ssh://git#bitbucket.test.com:YOURUSERNAME/myrepository.git

Unable to clone git repository from siteground

I'm trying to set up MS WebMatrix to use a Git repository from my siteground hosting account. I created the repository using their cpanel plugin and it tells me that I can clone it using this command
git clone ssh://username#sm3.siteground.biz:18765/home/username/public_html/
I replaced username of course and I created an rsa key using ssh-keygen. In the Webmatrix GUI it just opens a window saying "Clone is in progress" but it doesn't to anything.
And when I run that command in PowerShell, this is the output:
Cloning into 'public_html'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any help is highly appreciated!
EDIT:
I haven't used github before but I'm pretty sure I'm not connecting to it. The repository is on siteground's server I think. Anyway, I couldn't figure it out in PowerShell so now I'm using putty to load the appropriate key and connect using an external git tool (source tree) that doesn't use the same ssh client as PowerShell. That is the solution that's working for me now.
I'll leave this question open as maybe someone comes around and can help with how to set this up using PowerShell.
The missing piece to the Siteground guide is:
Create a blank file in ~/.ssh/ or C:\Users\username\.ssh on your computer. It does not matter what you name it. I named it siteground_dsa. You could also name it id_dsa_siteground.
Copy the private ssh key that you get from siteground.com and paste the whole of it in the this newly created file.
Open Git Bash locally on your computer and run the following command
$ eval ssh-agent -s
Then run the following. Remember to use the filename that you gave it.
$ ssh-add ~/.ssh/siteground_dsa
Now you need to enter the passphrase for the ssh key. You will have defined it when creating the ssh key.
Now you should be logged in and you can run git clone the directory of your wish.
git clone ssh://username#ams14.siteground.eu:18765/home/username/public_html/
To permanently add the SSH key extend ~/.ssh/config with the following and updating server_name and username.
Host server_name
User username
Port 18765
IdentityFile ~/.ssh/siteground_dsa
keep in mind that for Windows operators, you should write eval $(ssh-agent)
eval $(ssh-agent)
chmod 600 file_name
ssh-add C:\Users\username\.ssh\siteground
Then you can easily clone your file into your local server following inserting your passphrase of the SSH key.
GitHub isn't able to authenticate you. Probably your key isn't associated with your GitHub account.
Take a look to GitHub's recommended method

Source Tree for Windows doesn't seem to work with valid SSH key

I have created an ssh key pair using putty within Source Tree on Windows, and then added that to my repo client (I use Gitlab on a personal server).
This works fine from gitbash (cloning and pushing etc) and via SourceTree for OSX but after adding the .ppk key to pageant, which is actively running and seems to have loaded the key correctly, I cannot seem to clone via SourceTree. I get a "This is not a valid source Path/URL" when adding the repo path with details stating:
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and repository exists.
If I add an existing repo that I have cloned using the same ssh key pair via git bash (by just drag dropping the folder into Source Tree for Windows) that seems to work up to a point - I can commit and see history etc. When I try to Push, however, it fails with much the same message (I've altered the repo path):
git -c diff.mnemonicprefix=false -c core.quotepath=false push -v
--tags origin master:master Pushing to git#MyServer.com:MyRepo.git
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and the repository exists.
Completed with errors, see above.
As far as I can tell Pageant is up and running with the correct (well only) ssh key on my machine.
Any help is very welcomed.
Ok so this is a little embarrasing/confusing.
It would seem that I did not copy the correct public key onto my repo management web interface. The thing is, I copied the public key from git bash using the command:
clip < ~/.ssh/id_rsa.pub
But that seems to give me a different public key from what I actually get opening id_rsa.pub in a text editor...
Is that normal? Why is it different? Why does it work within gitbash and not in SourceTree (via pageant).
Anyway, copying the contents of my public key in directly from the file when opened in notepad got things to work with SourceTree and Pageant etc.

Resources