Retrieve a git repository on windows, can't use "keychain" - windows

my client sent me two keygen files (one is public and the other is private) and asked me to follow these steps to get their source:
$ vim .ssh/config # create a ssh config
Host git.xxx.com
IdentityFile ~/.ssh/keys/yourSource
$ keychain ~/.ssh/keys/yourSource # load the private key with keychain
$ git clone git#git.yourSource.com:something.git
$ cd something
I've put the keygen files they sent me in ~/.ssh/keys. I gave them my public key and they said they'd set it up.
But I have problems after creating the config file. I wasn't allowed to use "keychain" command on windows platform. (Git bash displays "command not found".) Is there any way else I can load the private key?

I doubt you need the keychain command. This one is used on Unix environments (Linux/Mac) only.
What you need on Windows is this setup:
in your c:\Users\.ssh folder, have two key files (default names id_rsa and id_rsa.pub). Use those provided or generate some with ssh-keygen
provide the contents of the public key to your client for setup with git repository
test the setup with git clone.
It is a bit strange that the client has provided you with both private and public keys rather than asking you to generate your own. The whole purpose of the public/private keys in security is to ensure that the private remains private so that the identity of one user/commiter can't be duplicated. If they have your private key then someone might (even accidentally) use your identity to access the git repository.

Related

github ssh key names

I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).
I had previously been using password-based authentication, which is repetitive to keep typing in my passwords. I followed the steps (using windows) to set up SSH keys in github. I gave my key a specific name, anticipating that I will need more than one SSH key at some point. It doesn't make sense to always have id_rsa for github! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key. But running a git clone gave me this error:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I then had the idea to try it with the default name (id_rsa), rather than my custom name, and of course it works. So my question is how do I avoid this? I don't want the default name to be reserved for github.
You can set up an ssh configuration file to tell the ssh command to use that specific key when connecting to github.
Create the file .ssh/config with the content:
Host github.com
IdentityFile ~/.ssh/github_rsa_key
Assuming that you've named your private key ~/.ssh/github_rsa_key.
Now try connecting to github:
$ ssh git#github.com
You should see:
Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.

using specific ssh key with git instructions

I have generated a pair of keys on my windows local machine.
I have a folder c:/users/me/.ssh containing :
the private key
the public key
the known_hosts file
I have uploaded the public key to my github profile.
When I open a powershell terminal and run any git command to interact with my repository, like :
git fetch my_repo_name
everything is working well.
The problem is that, I do not want to use the default private key located in the default .ssh folder, and I want to be able to specify my private key, but when I run the following command :
ssh-agent $(ssh-add C:/Users/Me/Pictures/id_rsa; git fetch my_repo_name)
I get the following error :
Identity added: C:/Users/Me/Pictures/id_rsa (C:/Users/Me/Pictures/id_rsa)
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
ps : the pictures folder is just used for the example, the point is that I want to be able to use a specific located private ssh key other than the default one.

How to setup SSH with Mercurial and Bitbucket on Mac OSX?

I cannot find a simple step-by-step guide to setup an OSX machine with Bitbucket and SSH.
So it requires me to google for different pages (to create SSH keys and to set them up in Bitbucket) whenever I'm setting up a new machine. It seems valuable to have one complete list available in StackOverflow.
It's actually pretty straightforward.
Check if you have a public key already that you could reuse:
ls -a ~/.ssh
If there is NO public key file id_rsa.pub then generate one:
ssh-keygen
Accept defaults. I don't enter password because I prefer to keep my hard drive encrypted whenever the repository contents are critical.
Copy your public key to clipboard:
pbcopy < ~/.ssh/id_rsa.pub
Let Bitbucket know the identity of your computer:
Go to https://bitbucket.org
Open your account settings under your avatar
Find "SSH keys" and choose to add a new one
Paste your public key from pbcopy
Clone (pull, push or whatever) your repository using SSH:
hg clone ssh://hg#bitbucket.org/<username>/<repository>
First time you will get a warning similar to this:
The authenticity of host 'bitbucket.org (104.192.143.1)' can't be established.
RSA key fingerprint is 97:...:40.
You should google for "Bitbucket fingerprint" and compare what you see in terminal with what Atlassian documentation gives because fingerprints could change and can be faked.
Have fun!

SourceTree on Windows: How to connect to SSH?

I have an SSH access to my web hosting, it works great with PuTTY (I just had to enter my domain, username and password), however it seems much more complicated with SourceTree.
While PuTTY has a field for "Host Name", "username" and "password", SourceTree doesn't and requires a special file ".ppk"?!
I need to connect SourceTree to my web hosting via SSH for the obvious reason that I want to use it to push to a remote repository located on my web hosting.
So how do I get a .ppk file generated from my domain/username/password? Any help greatly appreciated!
PS: I've noticed that they made it exceptionally easy to connect to BitBucket by offering two simple fields: "username" and "password", and made it exceptionally difficult to connect to a third-party SSH... Is it an intentional attempt to prevent competition?!
I had to do some additional work from Patoshi's answer.
In Tools > Options > General > SSH Client Configuration, I had to point it to the id_rsa key, and select OpenSSH as the SSH Client (Putty/PLink is selected by default).
Then each time you start SourceTree, a prompt will appear asking for the passphrase to decrypt the id_rsa key (assuming you created it with a passphrase to encrypt it). This looks like so:
At that point, I could go to the Clone page, paste in the SSH address from my Gitlab project (git#localgit.local:Blah/Whatever.git) and it cloned it. No extra prompts for username or password (since it is using SSH keys).
There are two ways to connect SourceTree to any SSH.
1: The Simplest Way
The simplest way is by using your domain name, username and password provided by your Web Hosting Provider:
Simply use the following syntax: ssh://username#example.com/ – SourceTree will then prompt you to enter your password whenever you push to that SSH:
If you check the Remember password checkbox, your password will be saved and you will not be prompted again for it. You can edit or remove the stored password at a later time by going to Tools > Options > Authentication as shown on the image below:
Note: In my case (1&1 Shared Hosting), the username and password were both the same as my main FTP account.
2: The More Complex Way
The more complex way is by using a Private/Public Keys Pair:
This implies generating two keys (one "private" and one "public") using the "PuTTY Key Generator" (in SourceTree go to Tools > Create or Import SSH Keys).
Once generated, save the private key to a .ppk file and load it in SourceTree (Tools > Create or Import SSH Keys > Load). It's not over yet: now you must add the public key to your server. To do that, add it to the following file on your web server: /.ssh/authorized_keys.
If this file doesn't exist, save your public key to a file named authorized_keys and upload it to your server via FTP. You must upload it into a directory named /.ssh/ located at the root (if it doesn't exist, simply create it).
Note: Make sure to use the main FTP account of your hosting account. If it doesn't work, adjust the permissions (chmod) of the authorized_keys file and set it to 777 using your FTP software (Right-click on "authorized_keys" > File permissions):
No need for command line whatsoever.
I had some trouble getting SourceTree working with an existing git repo that resided on gitlab. I also had to figure out why it wasn't connecting as I was using puttygen to generate the keys.
Make sure after you generate your keys to export it to the OpenSSH format
You place this file in your c:\user\MYUSERNAME.ssh folder as the file:
id_rsa
id_rsa.pub
the id_rsa is the private key file and .pub is the public key file that you paste into your other application, which in my case was gitlab.
Generate SSH key, private and public
Source Tree > Tools > Create or Import SSH Keys
Putty
Click Generate
Save public key under .ssh folder
Save private key under .ssh folder
Add private key to Pageant, running in background
Clone the git project using SSH key

How to set up private git server on linux

I have tried following how-set-up-your-own-private-git-server-linux and private-remote-git-repositories-ubuntu-linode but I am still having problems.
My local environment is windows and my remote linux. I have a couple of questions:
In the first article it describes setting up a public ssh key for the server - I've never done this before and I'm not sure where to type the commands (not even sure whether local or remote!!): ssh myuser#server.com mkdir .ssh and scp ~/.ssh/id_rsa.pub myuser#server.com:.ssh/authorized_keys
On my local dev machine should I be running msysgit? Is there an alternative because the version I installed is taking up 1.4 GB! I installed msysGit-netinstall-1.7.4-preview20110204.exe from http://code.google.com/p/msysgit/downloads/list
I tried skipping making the git user and public key, created the repositories on the remote machine but then when I try git remote add origin ssh://[username]#[domain/ip/hostname]/srv/git/[project-name] as root user it says: fatal: Not a git repository (or any of the parent directories): .git
I'm not sure if this should be here or if it would be best migrated over to a different site, but since I might be able to help I'll go ahead and answer.
I just skimmed the articles you linked. It looks like they both deal with accessing a git server over ssh, which you mention, so that's what I'll focus on.
First, on your server:
You need to set up an account on the server so that you can log in. This can be either a generic git account, or your own personal account. For the moment we'll assume that you are setting it up to work with a personal account. What you want to do is create your account, then somewhere accessible to that account (say, in your home directory), create the git repository.
mkdir myrepo.git
cd myrepo.git
git --bare init --shared=all
So now you have a git repository up on the server. Depending on the git client you are using, you might not need to mess with keys right now. If SSH is configured on your server to allow password login then you can probably just connect and enter your password when you need to interact with the server. If you want to set up keys, what you need to do is to generate an ssh public key. I don't know off hand how to do this in windows, but in linux you'd do something like:
ssh-keygen -t rsa -b 1024
That command will generate two files, "id_rsa" and "id_rsa.pub"; whatever tool you use should also generate two files, a public key and a private key. They might have different names, but assume for now that "id_rsa.pub" is the name of your public key file.
You want to copy the public key to the server, you can use scp, ftp, or just move it over using a thumbdrive. Either way, once you get it onto the server, and it's accessible by your user, log in as your user on the server. You want to add the public key to your "authorized_hosts" file, so after logging in to your account on the server, do this:
cd
mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_hosts
rm id_rsa.pub
Now, from your workstation you need to configure your ssh client to use the private key your generated. Again, I don't know how to do this on Windows and it will probably vary depending on what ssh client you are using, so you'll need to get that information somewhere else.
Next, you need to create your local repository, add some files, and make a commit. Note that you can't clone the remote repository you made yet because there's nothing in there. Once you have some commits made locally, you need to set the remote server in your repository.
If you are using the git command line tools, you can run:
git remote add origin user#yourserver:myrepo.git
If you put the repository somewhere other than your home directory, use the full path:
git remote add origin user#yourserver:/path/to/repo.git
Note that you need the ".git" in there, since your directory name has ".git" as part of the name.
If you are using a GUI tool, then you instead just edit the configuration file for the repository. This will be in the top level of your repository under ".git/config". You'll want to add something like
[remote "origin"]
url = user#yourserver:/path/to/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
Now that your remote is configured, and you have some commits locally, you can push your master branch up to the server. If you're using the command line use:
git push origin master
Or, if you're working on a different branch:
git push origin mybranch
If you are using a GUI frontend for get then you'll need to look up the documentation for that tool on how to push.
I would like to recommend to use Gitolite that allows to setup git hosting on central srever with great features like access control and creating/managin repositories etc.
And for windows, the tool called git-scm can be used for setting up git client and also have GUI panel for git repositories. After installation of this git tool, you will get a git bash tool and a git GUI.
Gitolite makes settting up of a git hosting server and client very simple.
I hope this may help new people who are looking for an efficient solution for settting up git hosting server and clients in some easy to understand simple steps.
I followed the most voted answer and I didnt get it to work. I found this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2
and I got it working. I think the problem was that, in the server, the public key is to be copied to a file "authorized_keys" and not "authorized_hosts".
I had been trying to generate the key pairs using putty but couldn't get it to work. In the end I realised that I could generate the keys via the msysgit command line using ssh-keygen -C "git#example.com" -t rsa. Copy the public key to the server using nano /home/git/.ssh/authorized_keys and hey presto!
I had downloaded the full source code hence the size! The non-source app, Git-1.7.4-preview20110204.exe was just 13MB via http://code.google.com/p/msysgit/downloads/list?can=3

Resources