Gitolite hook doesn't work - windows

I've set a GIT server on Windows with Cygwin and gitolite as it's described in the article.
On a client Windows machine I use TortoiseGit.
Right after the setup everything works ok. I can clone gitolite-admin repository with TortoiseGit using my SSH key and see the repository content.
But right after I try to push a new content of /conf/gitolite.conf the server is not accessible anymore using my SSH key (it's removed from *authorised_keys* on the server by gitolite).
The new content of gitolite.conf (I would like to add new repository Project):
repo gitolite-admin
RW+ = alexey
repo Project
RW+ = alexey
repo testing
RW+ = #all
What's wrong with it?

The problem was in sshd service environment. See this link for details.
To fix the problem reinstall the service with proper PATH variable setting. To do this on Windows Server 2008 use:
cygrunsrv -R sshd
cygrunsrv -I sshd -d "CYGWIN sshd" -p /usr/sbin/sshd -a "-D" -y tcpip -u cyg_server -w {cyg_server_password} --env "PATH=/usr/local/bin:/usr/bin:/bin:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem"
cygrunsrv -S sshd
If you don't remember cyg_server account password you can rerun ssh-host-config.
To restore access for your public key use:
gl-setup ~/YourKey.pub
After these you can access and modify your gitolite-admin repository remotely.

Related

Pushing commits to an SSH-cloned repo via VS Code on WSL returns "Host key verification failed" - it's ok on HTTPS

I'm on a Windows 10 machine and I have both Git Bash and Ubuntu for Windows Subsystem for Linux (WSL) installed. When I use GitHub's official desktop app to clone a repo via HTTPS everything works fine and I can push my commits via Visual Studio Code with no problems whatsoever. I then try to clone a repo via SSH with Hyper (WSL Bash) and get this:
The authenticity of host 'domain.com (a.b.c.d)' can't be established.
RSA key fingerprint is XX:XX:...:XX.
Are you sure you want to continue connecting (yes/no)?
After answering yes and openning that repo in VS Code and try to push my new changes to GitHub, I get this error:
Git: Host key verification failed.
And this is what I get as Git Log in Output:
Host key verification failed.
fatal: Could not read from remote repository.
I have set up my SSH key on WSL using this method and I didn't set up any passphrase. I tried this on my brother's PC which is exactly set up like mine and it worked just fine. I would appreciate any help!
UPDATE: I typed ssh -T git#github.com in Hyper and got this as an answer: You've successfully authenticated, but GitHub does not provide shell access.
P.S. I'm a newbie in programming and stackoverflow, so please be concise and give me step by step instructions. The more you use technical terms, the more I'll probably get lost!
Try first, for that new push, to do it in command line:
cd c:\path\to\local\repo
git status
git log
git remote -v
git push -u origin master
Make sure that:
git status is clean (no pending changes)
git log shows you at least one commit
git remote -v shows you as origin the URL of your remote GitHub repository
(as an SSH URL git#github.com:<you>/<yourRepo>)
Then push, and go back to VSCode.
Should be faster than the other solution:
In vscode open a new terminal of type "Command Prompt"
Run: git push and accept the new key when prompted.
This will store the remote key for future use.

Git remote add origin: correct URL and path to add remote repo on the local network

I am trying to set up a remote repository on a Mac on my local network. I have done the following:
Set the sharing privileges on the remote, allowing access to all users (using System Preferences/Sharing)
confirmed that I can SSH to the remote machine
created the repo in the remote directory
created a repo in the local machine directory
executed this command from the local repo directory:
git remote add origin FSM13#192.168.1.51:/Library/FileMaker\ Server/HTTPServer/htdocs/fm-php
when I attempt to push:
git push -u remote origin master
I get these errors:
fatal: 'remote' does not appear to be a git repository
fatal: Could not read from remote repository.
I get the same error using this syntax to set the remote
git remote add origin ssh://FSM13#192.168.1.51/Library/FileMaker\ Server/HTTPServer/htdocs/fm-php
FMS13 is the administrator user account on the remote machine.
What steps might I be missing?
There were three things I needed to do in order to solve this issue:
set up the SSH Keys correctly
initialize the remote repo correctly (using --bare) (this worked but I need to try a few more things. a bare repo does not have any files, just the history: http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/ )
set the path correctly for the git remote add command
Note that I am using OS X.
This youtube vid and blog post laid it out perfectly:
https://www.youtube.com/watch?v=DDzeiI2yZL8
http://crosbymichael.com/setup-password-less-login-over-ssh.html
SSH Keys:
On the local machine, starting from home directory:
cd .ssh
cat id_rsa.pub
then copy the printed public key. I happened to already have one. The blog post above explains how to create one.
SSH into the remote:
ssh FMS13#192.168.1.51
ls -a
Is there a .ssh directory? If not create one. It needs to be in the home directory.
mkdir .ssh
cd .ssh
then create a keys file
touch authorized_keys
nano authorized_keys
Then paste the key and save the file.
Confirm the install of the key by ssh'ing from the local machine:
ssh FMS13#192.168.1.51
No password was requested, so the key install was successful
Correct repo initialization:
On the remote machine, cd to the desired parent directory and:
mkdir remote-git
cd remote-git
git init --bare
On the local machine from the repo directory, the correct path was as follows to set the remote origin:
git remote add origin ssh://FMS13#192.168.1.51/Users/FMS13/Desktop/remote-git
Where FMS13 is the user on the remote computer, followed by the ip address and then the full path to the directory of the remote repo.
Push to remote:
Then back in the local machine, cd to the repo directory and:
git push origin --all
I have used something similar to this command recently which worked for me:
git remote set-url origin ssh://FSM13#192.168.1.51/USERNAME/REPOSITORY.git
Check out this link for more information. For your case, you may need to be adding the following instead. I have not seen using an IP address with this, though- so refer to the link.
ssh://git#192.168.1.51/USERNAME/REPOSITORY.git
You may also need to generate a new ssh key. Here is a link on that:
ssh-keygen -t rsa -C "your_email#example.com"

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

How to stop git via ssh on windows from resolving the wrong path?

I have a windows 2003 box with an ssh server setup. I have msysgit (git version 1.6.2) installed both locally and on the server.
The server has the following absolute path to my repos:
e:\vc\git\myrepo.git
when a user logs in he/she will be put in the following working directory:
e:\vc\git\
When running the following cmd on my dev machine:
git clone ssh://myuser#myip/myrepo.git testrepo
I get the following error:
fatal: ''/myrepo.git'' does not appear to be a git repository
According to my ssh logs it appears that git is executing this cmd on the server:
'cmd.exe /c git-upload-pack '/myrepo.git''
Executing that command locally (on the server) fails for the same reason. I'm thinking the problem is related to git prefixing the path with a '/'. How do I tell git not to do this? Should this be working?
Note: git-upload-pack is working because I added \gitinstallpath\libexec\git-core to the path. Apparently this is a bug and will be fixed in the future, this was my work around.
I resolved this by switching my ssh server from winssh to openssh (via the cygwin layer). I was able to connect fine (as noted above) using winsshd, but winsshd wasn't correctly handling paths prefixed with "/". I could probably get winsshd to work, but switching to cygwin and openssh was faster.
Here's a good blog post to kick start the setup if your in a similar situation:
Have you tried the following?
git clone ssh://myuser#myip/myrepo testrepo
Note the removal of ".git" from the end of the SSH path. You only need that suffix at the end if the remote directory name has it.
Also, have you tried any other SSH URL format? To use a relative path, you can try:
git clone ssh://myuser#myip/~/myrepo testrepo
See the git clone man page for details on other URL formats.
If somebody still interested in workaround:
The problem is - cmd.exe doesn't understand single-quoted parameters. So we use sh instead.
Create file gup.sh with line
git-upload-pack.exe $*
and grp.sh with
git-receive-pack.exe $*
on server!
Then run:
git clone -u 'sh gup.sh' ssh://myuser#myip/e/vc/git/myrepo.git testrepo
git config remote.origin.uploadpack 'sh gup.sh'
git config remote.origin.receivepack 'sh grp.sh'

Hosting Git Repository in Windows

Is there currently a way to host a shared Git repository in Windows? I understand that you can configure the Git service in Linux with:
git daemon
Is there a native Windows option, short of sharing folders, to host a Git service?
EDIT:
I am currently using the cygwin install of git to store and work with git repositories in Windows, but I would like to take the next step of hosting a repository with a service that can provide access to others.
Here are some steps you can follow to get the git daemon running under Windows:
(Prerequisites: A default Cygwin installation and a git client that supports git daemon)
Step 1: Open a bash shell
Step 2: In the directory /cygdrive/c/cygwin64/usr/local/bin/, create a file named "gitd" with the following content:
#!/bin/bash
/usr/bin/git daemon --reuseaddr --base-path=/git --export-all --verbose --enable=receive-pack
Step 3: Run the following cygrunsrv command from an elevated prompt (i.e. as admin) to install the script as a service (Note: assumes Cygwin is installed at C:\cygwin64):
cygrunsrv --install gitd \
--path c:/cygwin64/bin/bash.exe \
--args c:/cygwin64/usr/local/bin/gitd \
--desc "Git Daemon" \
--neverexits \
--shutdown
Step 4: Run the following command to start the service:
cygrunsrv --start gitd
You are done. If you want to test it, here is a quick and dirty script that shows that you can push over the git protocol to your local machine:
#!/bin/bash
echo "Creating main git repo ..."
mkdir -p /git/testapp.git
cd /git/testapp.git
git init --bare
touch git-daemon-export-ok
echo "Creating local repo ..."
cd
mkdir testapp
cd testapp
git init
echo "Creating test file ..."
touch testfile
git add -A
git commit -m 'Test message'
echo "Pushing master to main repo ..."
git push git://localhost/testapp.git master
GitStack might be your best choice. It is currently free (for up to 2 users) and open source at the time of writing.
Here's a dedicated git server for windows: https://github.com/jakubgarfield/Bonobo-Git-Server/wiki
If you are working in a Windows environment, have you considered Mercurial? It is a distributed version control system like Git, but integrates far more neatly and easily with Windows.
Installing CygWin is an overkill, read this tutorial on how to do it faster and native:
http://code.google.com/p/tortoisegit/wiki/HOWTO_CentralServerWindowsXP
If you get the error cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062: The service has not been started. after running the command:
cygrunsrv --start gitd
that means that you did not create the 'base-path' folder.
Creating the folder '/git' and rerunning the command will fix this.
I'm currently using cygwin's ssh daemon on Windows to serve up and allow remote access to my repo. It works quite well, I have complete control over who accesses my repo by their ssh certificates, and the performance blazes, even over remote WAN and VPN links.
Another solution is to use Gitosis. It is a tool that makes hosting repos much easier.
You do not need to host a service, you can also create a shared repository on a shared drive. Just create a bare repository. You can clone an existing repo into a shared one using: "git clone --bare --shared [source] [dest]". You can also init a new repository using "git init --bare --shared=all".
Henk
Have you considered using the cygwin layer? See this link.
Now msysGit supports git daemon ! It works fine (for me at least). I gonna try to make it run as service...
SCM Manager
Lightweight http-server for Git, Mercurial, Subversion repos from a box (only Java is needed)
Web-interface for management of users, ACLs, repos
On Windows, you can also serve Git repositories with Apache over HTTP or HTTPS, using the DAV extension.
The Git repository path can then be protected with Apache authentication checks such as restricting to certain IP addresses or htpasswd/htdigest type authentication.
The limitation of using htpasswd/htdigest authentication is that the username:password is passed in the requested Git URL, so restricting access to the Git URL to certain IP addresses is better.
Edit: Note, you can leave the password out of the Git URL and Git will prompt you for the password on push and fetch/pull instead.
Using HTTPS means all the data is encrypted in transfer.
It's easy enough to set up, and works.
The following example shows the combination of access control by IP address and user:password over standard HTTP.
Example Apache Virtualhost
## GIT HTTP DAV ##
<VirtualHost *:80>
ServerName git.example.com
DocumentRoot C:\webroot\htdocs\restricted\git
ErrorLog C:\webroot\apache\logs\error-git-webdav.log
<Location />
DAV on
# Restrict Access
AuthType Basic
AuthName "Restricted Area"
AuthUserFile "C:\webroot\apache\conf\git-htpasswd"
# To valid user
Require valid-user
# AND valid IP address
Order Deny,Allow
Deny from all
# Example IP 1
Allow from 203.22.56.67
# Example IP 2
Allow from 202.12.33.44
# Require both authentication checks to be satisfied
Satisfy all
</Location>
</VirtualHost>
Example .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:password#git.example.com/codebase.git
[branch "master"]
remote = origin
merge = refs/heads/master
At work I'm using GitBlit GO installed on a Windows Server. Work flawlessly and integrate well with ActiveDirectory for user authentication and authorization. It is also free and opensource (Apache licensed)
GitBlit homepage
Only HTTP(S) access is supported, no SSH, but under Windows you shouldn't need anything more.
this is a 2015 answer to a question that is over 7 years old.
For $10 one time payment, from https://bitbucket.org/product/server, one can purchase a 64-bit Windows licence for up to 10 users.
Apparently 32-bit versions are only available via their archive.
Bitbucket Server was previously known as Stash.
Please note that i have not tried this version but $10 seems like a good deal; here i read that Atlassian gives the $10 to charity. FWIW
I think what Henk is saying is that you can create a shared repository on a drive and then copy it to some common location that both of you have access to. If there is some company server or something that you both have ssh access to, you can put the repository someplace where you can SCP it back to your own computer, and then pull from that. I did this for my self a little while, since I have two computers. It's a hassle, but it does work.
For Windows 7 x64 and Cygwin 1.7.9 I needed to use /usr/bin/gitd as the args argument of cygrunsrv
cygrunsrv --install gitd \
--path c:/cygwin/bin/bash.exe \
--args /usr/bin/gitd \
--desc "Git Daemon" \
--neverexits \
--shutdown
Also, I needed to run bash as an Administrator to install the service.

Resources