cloning private repo using ruby-git - ruby

I'm using ruby-git to programmatically perform some operations git repos hosted on GitHub.
Everything works fine when I do it on public repos however, I'm not able to clone private repos even if I have created an ssh key on the machine when the code runs and added the public one on GitHub. To make sure the key is properly setup I have cloned the repo directly from the terminal and the repo was successfully cloned. The key has also been added to the ssh-agent and $SSH_AUTH_SOCK is set.
So, I think the issue is related to how I use the ruby-git gem.
Here my (simple) code
#repo = Git.clone("git#github.com:#{repo_full_name}.git", path)
And here, if it may be helpful teh error
Git::GitExecuteError: git clone '--' 'git#github.com:USER/REPO.git' '/var/www/repo-root/USER/REPO' 2>&1:Cloning into '/var/www/repo-root/USER/REPO'... Permission denied (publickey). fatal: Could not read
Am I missing anything here?
Thanks

Do you have your Git env config pointing at your ssh key path?
Git.configure do |config|
# If you want to use a custom git binary
config.binary_path = '/git/bin/path'
# If you need to use a custom SSH script
config.git_ssh = '/path/to/ssh/script'
end

Related

composer install does not use ssh key on private repo (permission denied public key)

I have a Laravel project with some dependencies to private packages, secured through ssh, working on windows 10 with Laragon.
On composer install I get a permission denied (public key), however, if I clone the repo directly I get my regular prompt to type the ssh-key password for authentication and the clone works with no problems (using git#gitlab...., so no https).
The output looks like this:
Failed to execute git clone ...
Cloning into 'project/path/foo/bar'...
Permission denied (public key).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I already added the host (a private GitLab server) to my git config file, including the path to my ssh key, which seems to work due to git clone succeeding.
I expected that composer install would prompt for the password, but it just stops.
Any ideas how to solve this problem? I normally work on Ubuntu and didn't have such a problem before.
Edit:
Tried out the same commands with git bash (Git for windows) and it worked. But if I use Powershell or ConEmu(through Laragon) it won't work, any ideas?

Cloning repositories from github fails

I am unable to clone any repositories from github. I always get this error message
fatal: Could not read from remote repository. Please make sure you have the
correct access rights and the repository exists
I have taken care of the following :
Set my path variable to ;C:\Program Files (x86)\Git\cmd; and C:\Program Files (x86)\Git\bin;
I have generated the public key and linked id_rsa.pub with git
I have seen all the related links and am unable to resolve this issue.
If you have issue with the ssh key, you can at least use as a workaround https url:
git clone https://github.com/username/reponame
Regarding ssh, make sure that:
environment variable HOME is defines, and that your private/public ssh keys are in:
%HOME%\.ssh\id_rsa
%HOME%\.ssh\id_rsa.pub
your public ssh key is added to your GitHub account.

Gitolite, can't clone new repo

I've just installed gitolite on my Debian server.
Then I cloned gitolite-admin repo and and new public key + following lines to conf file:
repo wallr_common
RW+ = wall
New repo was created after push.
At first I go to authorized_keys and saw that key for new user not exists, then I run ~/.gitolite/keydir$ gl-setup, and the key appears in authorized_keys.
Now I'm trying to clone it but I'm getting error:
git.exe clone --progress -v "ssh://wall#192.168.1.110:/wallr_common.git" "D:\wallr_common"
Cloning into 'D:\wallr_common'...
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
git did not exit cleanly (exit code 128) (5834 ms # 04.07.2013 0:27:46)
What can be the root cause of this?
You must use the git or gitolite account for your ssh session. Not the user account wall that you registered in gitolite.
That means ssh://git#..., instead of ssh://wall#....
Replace 'git' with the account you used to install gitolite.
See more at "How do programs like gitolite work?".
This is a similar mistake as in this question.

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.

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