Http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/
OK-Let me start this post by saying this is absolutely not for the faint hearted. this was a serious-and I re-emphasize this-serious pain in the arse to the do. having almost no experience in Linux before-copssh emulates the Linux environment through cygwin-let me tell you that this process was not easy. if you are an expert and thought-"pfftt, this process was easy "-I will reserve my language and ask you to kindly move along for those of you with no clue at all (Ala me)-then this post is for you.
firstly, full credit goes to the fantastic team at msysgit-these guys rock for porting git to Windows-Git is an unreal DVCs and so I cant thank them enough for making this all possible. secondly, full credit goes out to the guys at stackoverflow-Unreal website and lots of fantastic users that have helped answer questions which have allowed the making of this guide possible. please feel fre E to ask me questions, but I stronugly recommend stackoverflow as your first port-of-call as I may take longer in getting back to you than they will. also, this instruction guide is how I have set it up -if you start changing things-May the force be with you!
Finally, if this process worked for you-please leave a comment telling me (and everyone else) that it works and share this article around. it took me quite a bit of time to figure all this out on Windows-not to mention the time to type up this Guide-so I wowould appreciate a link back
Pre-Setup
- Download copssh [SourceForge link]
- Download msysgit
- Download tortisegit
- Download putty Installer
- * Optional download git Install guide (this guide as a printable PDF)
Step 1-installing copssh
- You 've got copssh-Now go on and install it.
- Install copssh into the c: \ SSH directory
- Write down the svccopssh password-you will probably never need it-but just in case.
- It will install and create a bunch of directories-(Aside: I have found that you don't need to create a password on your Windows User Account-it's not necessary if you use the settings I have later)
- GotoStart-> Programs-> copssh-> activate a user
- You can only activate existing users on Windows-so you can chooseYour Own AccountOrAdministrator(Or indeed another account but I 've used the primary)
- Uncheck the option-Create keys for Public Key Authentication-We will do this ourselves.
- Finish the installation process.
Step 2-setup copssh
- Open Windows Explorer-goC: \ SSH \ etcAnd open both yourSsh_configAndSshd_configIn WordPad (ASIDE: note-one has a "D" and one doesn't-it's an important difference)
-
- Ssh_config-Delete the # (pound) Key next to "Port" and change this to something like 4837 (or whatever port you want to use)
-
- Sshd_config-Delete the # (pound) Key next to "Port" and change this the same as that inSsh_config-I. e. in this example 4837
-
- Sshd_config-Delete the # (pound) Key nextMaxauthtriesAnd make this 2
-
- Sshd_config-Delete the # (pound) Key nextRsaauthentication& Also next toPubkeyauthentication
- Sshd_config-Delete the # (pound) Key nextPasswordauthenticationAnd make thisNo.
-
- Save all the changesSsh_configAndSshd_config.
-
- Open your router IP address (or however you access your router) and open the port you are using-I. e. in this example 4837(ASIDE: If you don't know it-c: \ cmd-> ipconfig/all-will tell you)
-
- Save these port changes in your router(& Restart your router if needed)
-
- OpenWindows Firewall with Advanced Security SettingsAnd create a rule which allows the port you set in bothSsh_configAndSshd_config-In this case 4837(Also do this in your firewall if your firewall requires it-maybe/maybe not)
- Restart your PC.
Step 3-installing putty
-
- Welcome back after the restart-now open the putty installer you downloaded.
-
- Install everything
-
- Navigate to the putty installed directory (usuallyC: \ Program Files \ putty)
-
- OpenPuttygen.exe
-
- Enter inNumber of BITs in a generated key4096
-
- Move your mouse around und randomly as your ucted until finished-Don't closePuttygen!
-
- Open Windows Explorer and navigateC: \ SSH \ home \ <user> \. Ssh \-I. e in our caseC: \ SSH \ home \ Administrator \. Ssh \ (Aside: If. SSH doesn' t exist-you can only create it via a cmd.exe prompt-open cmd.exe and enter cd c: \ SSH \ home \ <user> \ then enter mkdir. SSH)
- Create a new file calledAuthorized_keys (Aside: If it's not there-Right click-New Text Document-delete everything (including the *. txt)-name the file authorized_keys)
-
- OpenPuttygenAnd copy/pastePublic Key for pasting into OpenSSH authorized_keys filesCode.
-
- Still inPuttygen-Save the private keyPrivate_key.ppkIn the sameC: \ SSH \ home \ <user> \. Ssh \-I. e. I. e in our caseC: \ SSH \ home \ Administrator \. Ssh \ private_key.ppk
-
- You shoshould now have 2 files in this directory-Authorized_keysAndPrivate_key.ppk
-
- To test our connection-load upPutty.exeFrom the sameC: \ Program Files \ putty
- Enter yourIP addressAndPortInSessionWindow (ASIDE: If you don't know your IP-c: \ cmd-> ipconfig/all-will tell you)
-
- Click onSSHIn the left hand menu and select-Auth-Then navigate to your private keyC: \ SSH \ home \ <user> \. Ssh \ private_key.ppk
-
- HitOpenAnd a terminal will open asking youEnter Login Name:-Enter your <user>-I. e. In our caseAdministrator
-
- You may get a message aboutAccept Public Key-Type Yes & if you get logged in great!
Step 4-installing msysgit
-
- OpenMsysgitInstaller package.
- Ensure itsC: \ Program Files \ git(X32 bit) orC: \ Program Files (x86) \ git (X64 bit)
-
- SetUse git bash only (Aside: I wanted to only use git bash console but if you want to run git from the Windows Command Prompt then you have to select this option-I wocould recommend only options 1 & 2 unless you really know what you are doing)
-
- SelectUse (tortoise) plinkAvailableC: \ Program Files \ tortoisesvn \ bin \ tortoiseplink.exe. if it's not available in the installer then set the variable in the Windows environment to git_ssh =/path/to/tortoiseplink.exe. (aside: I set this as using just putty plink.exe as opposed to tortoiseplink.exe-wocould recommend settings this instead to c: \ Program Files \ putty \ plink.exe but it's up to you)
-
- Let it install and have a laugh in the meantime.
- Once it's installed-You now have 2 windows which I will name 1.Git bash (Right click mouse on a file/folder in Explorer)And 2.Start-> Programs-> copssh->Start a Unix bash shell-Unix bash.
-
- Finally, Goto your Git-core folder in the GIT installed directory-C: \ Program Files \ git \ libexec \ Git-core(X32 bit) orC: \ Program Files (x86) \ git \ libexec \ Git-core (X64 bit)-and copy the filesGit.exe, git-receive-pack.exe, git-upload-archive.exeAndGit-upload-pack.exeAnd paste these into yourC: \ SSH \ bin.
Step 5-Modify the user environment
- The problem with copssh is that it sets its $ home environment toC: \ Users \ <Name>OrC: \ Documents ents and Settings \ <user>Variable-and git looksAuthorized_keysIn this folder. Of course, we don't want this-we setup our server environment inC: \ SSH \ home \ <user> \. SSHAnd so we want git to look for keys in there.
-
- Open Windows Explorer-go into C: \ SSH \ home \ <user> \And open. BashrcFile Using a text editor(Aside: Be sure not to attempt to format this file as it has UNIX encodings not dos encodings-I. e. just open it in a text editor and don't use another viewer unless you want encoding errors-you don't need to read the text in this file if you are following these instructions to tee .)
- Put the cursor at the beginning of. BashrcFile and use Ctrl + F to find the following text-Bashrc File. # User dependent. bashrc file #
-
- After the text. Bashrc file #(After the pound with a space)-paste in-Export Home =/C/ssh/home/<user> -I. e. In our case Export Home =/C/ssh/home/Administrator
-
- Ensure there is a "space" before and after this paste in-I. e.. bashrc file # <space> Export Home =/C/ssh/home/Administrator <space> shell options #
-
- Save this file and close it.
-
- Copy this file and navigate to your windows assigned home directory(Aside: git will still be looking for your path in this directory so we need to set to refer to ourC: \ SSH \ home \ <user> \ directory instead)
- Paste this in yourC: \ Users \ <Name>OrC: \ Documents ents and Settings \ <user>-So it now hasC: \ Users \ <Name> \. bashrcFor example.
-
- Open bothGit bash (Right click mouse in Explorer)AndStart-> Programs-> copssh->Start a Unix bash shell-Unix bashShell
-
- TypeEcho $ home-Into both-They shoshould both spit out-/C/ssh/home/<user>
-
- If one does not-you need to set it-Export Home =/C/ssh/home/<user>
Step 6-install tortisegit
- Install tortisegit per the standard installer usingPlink.exe(Aside: This shoshould be the same as that setting at Step 4.4)
- Once the install has completed, Open Windows Explorer.
- Right click on anything and gotoTortisegit-> Settings
- SelectGeneralAnd ensure the msysgit path is setingC: \ Program Files \ git \ bin (X32) orC: \ Program Files (x86) \ git \ bin(X64)
- SelectNetworkAnd ensure that this is set to the samePlink.exePath that we set in step 6.1.
- SelectSaveThenOK.
Step 7-using git and plink
- NavigateC: \ SSH \ home \ <user>And create a new directory called <MyApp>. Git-I. e.C: \ SSH \ home \ Administrator \ MyApp. Git
-
- Right click on this new directory and selectGit bash
-
- When the window loads enterGit-bare init
-
- You'll now see(Bare: Master)Appear and can close the window.
- navigate to C: \ Program Files \ putty and open pageant.exe - A small icon will appear in your system tray at bottom right hand corner of your screen (a PC with a hat on it) -open this and add your key from C: \ SSH \ home \ Administrator \. SSH \ private_key.ppk (aside: I recommend adding pageant.exe to your start-> Startup Folder so this will load each time you start your PC. to do this, Goto start-> putty and right click on pageant.exe. then change the target path to c: \ \ pageant.exe dir: \ \ private_key.ppk. then drag pageant.exe to your Startup Folder-this will then load both pageant.exe and your private key each time the system loads. refer here if confused .)
- Now it's time to clone this repository to our local development environment and finally start using git
-
- Navigate to where you want to have your local repository-in my caseD: \ git \
-
- Right click inside this directory and hitGit clone
-
- Enter your URL as SSH: // <user >@< ip_address >:< port number>/ssh/home/<user>/<git directory>-I. e. in our caseSSH: // administrator@127.0.0.1: 4837/ssh/home/Administrator/MyApp. Git
-
- The directory shoshould have the correct path-I. e. In my caseD: \ git \ MyApp
-
- There is no needLoad putty keyAs we have already done this usingPageantIn step 7.5.
-
- Hit OK and with a bit of luck (a lot of luck) you will get a successful clone.
Step 8-the real test
- Cloning is one thing-the real test is pushing a new commit.
- Go to your newly cloned directory-D: \ git \ MyApp
- AddNew text document.txt
- Go back to justD: \ git \-> right click on the folder-> Git commit-> "master "...
- Enter a new commit message "test" & tick the checkboxNot versionedCOMMIT on the fileNew text document.txt.
- HitOK& Then hitPush.
- EnsureLocal: MasterToRemote: Master(For this test) &Remote: Origin
- HitOKAnd you shoshould get below
Counting objects: 1, done.
Compressing objects: 100% (1/1)
Writing objects: 100% (1/1)
Writing objects: 100% (1/1), 244 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To SSH: // administrator@127.0.0.1: 4837/ssh/home/Administrator/MyApp. Git
0526eba .. a1bf4a4 master-> master
If yes (get a beer), if no (seeProblem GuideAnd get ready for tears, profane language and keyboard bashing)
Problem Guide
Copssh
- I don't understand how to install copssh-can't you add some pictures?No, but this guy can.
- I want to add another directory instead of installing my git repo in the home account?OK, see here which must be doneUNIX bash.
- When I check services. MSC-I can see that the service has stopped-what can I do?You can setup a dependent copssh service if you are brave.(Tip: If you don't know what you are doing, don't stop the service ever-when you make changes to c: \ SSH \ etc \ directory restart your PC instead)
Putty
- Can I create keys with less encryption than 4096 from step 3.5?You can never have enough encryption so no(Well at least it's my opinion !)
- I cant connect via putty?You may have to regenerate your keysPuttygen.exeAnd put them back into your/. Ssh/authorized_keysFile perStep 3 instructionsAbove.
Git
- I keep getting "Fatal: the remote end hung up unexpectedly "?Open a git bash window and typeEcho $ home-Ensure it is set to/C/ssh/home/<user>/. If it is not-enterExport Home =/C/ssh/home/<user>
- I get "Fatal: Connection refused "?Check that you have correctly opened the port you have set on the service per step 1.
- I get "Fatal: no authorized methods accepted "?You will have to regenerate your keysPuttygen.exeAnd follow steps per 3.
- I get "Git-upload-Pack: Command not found "?You must ensure that you have completed step 4.7 and copied the relevant files into yourC: \ SSH \ binDirectory.