Setting up a Msysgit Server with copSSH on Windows
时间:2010-05-16 来源:figofuture
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 free to ask me questions, but I strongly 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 would 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)
- Goto Start –> Programs –> copSSH –> Activate a User
- You can only activate existing users on Windows – so you can choose Your Own Account or Administrator (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 – go into C:\SSH\etc and open BOTH your ssh_config and sshd_config in 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 in ssh_config – i.e. in this case 4837
- sshd_config – Delete the # (pound) key next to MaxAuthTries and make this 2
- sshd_config – Delete the # (pound) key next to RSAAuthentication & also next to the PubkeyAuthentication
- sshd_config – Delete the # (pound) key next to PasswordAuthentication and make this no.
- Save all the changes to ssh_config and sshd_config.
- Open your Router IP Address (or however you access your router) and open the Port you are using – i.e. in this case 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)
- Open Windows Firewall with Advanced Security Settings and create a rule which allows the Port you set in both ssh_config and sshd_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 (usually c:\Program Files\PuTTY)
- Open PuttyGen.exe
- Enter in Number of bits in a generated key: 4096
- Move your mouse around randomly as instructed until finished – don’t close PuttyGen!
- Open Windows Explorer and Navigate to c:\SSH\Home\<user>\.ssh\ – i.e in our case c:\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 called authorized_keys (Aside: if it’s not there – Right Click – New Text Document – Delete everything (including the *.txt) – name the file authorized_keys)
- Open PuttyGen and Copy/Paste the Public Key for pasting into OpenSSH authorized_keys files code.
- Still in PuttyGen – save the Private Key as private_key.ppk in the same c:\SSH\Home\<user>\.ssh\ – i.e. i.e in our case c:\SSH\Home\Administrator\.ssh\private_key.ppk
- You should now have 2 files in this directory – authorized_keys and private_key.ppk
- To test our connection – load up putty.exe from the same c:\Program Files\PuTTY
- Enter your IP Address and Port in the Session window (Aside: If you don’t know your IP – c:\cmd –> ipconfig /all – will tell you)
- Click on SSH in the left hand menu and select – Auth – then navigate to your private key c:\SSH\Home\<user>\.ssh\private_key.ppk
- Hit Open and a terminal will open asking you to Enter Login Name: – enter your <user> – i.e. in our case Administrator
- You may get a message about Accept Public Key – type yes & if you get logged in great!
Step 4 – Installing msysgit
- Open the msysgit installer package.
- Ensure its C:\Program Files\Git (x32 bit) or C:\Program Files (x86)\Git (x64 bit)
- Set Use 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 would recommend only options 1 & 2 unless you really know what you are doing)
- Select Use (Tortoise)Plink available via C:\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 – would 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) or C:\Program Files (x86)\Git\libexec\git-core (x64 bit) – and copy the files git.exe, git-receive-pack.exe, git-upload-archive.exe and git-upload-pack.exe and paste these into your C:\SSH\Bin.
Step 5 – Modify the User Environment
- The problem with copSSH is that it sets its $HOME environment to the c:\users\<name> or c:\Documents and Settings\<user> variable – and GIT looks for authorized_keys in this folder. Of course, we don’t want this – we setup our Server Environment in the C:\SSH\Home\<user>\.ssh and so we want GIT to look for keys in there.
- Open Windows Explorer – go into C:\SSH\Home\<user>\ and open the .bashrc file 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 a tee.)
- Put the Cursor at the beginning of the .bashrc file and use CTRL+F to find the following text - bashrc file.
相关阅读 更多 +