"git push -u origin --all" fails only from AWS virtual Linux instance - possibly ssh related - linux

Pardon my ignorance here.
I have a local Windows machine using which if I run the following commands on a Windows cmd prompt, they all work:
git config --global user.email "myuser#abc.com"
git config --global user.name "myuser"
cd Try (some dir holding a single readme file)
git init
git add .
git commit -am "initial"
git remote add origin git#mygiturl.git (URL where I want to check into)
git remote -v
git push -u origin --all
However, if I try running the exact same set of commands from a Linux server (EC2 instance spawned in AWS), it throws:
ubuntu#ip:~/try$ git push -u origin --all
GitLab: The project you were looking for could not be found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I'm guessing it's possible got to do with ssh and/or authentication, but it doesn't error out with "permission denied".
If I run these same from Ubuntu Linux subsystem on Windows, the "git push -u origin --all" fails with permission denied instead.
git#gitlab....: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Any inputs are appreciated.

GitLab: The project you were looking for could not be found. fatal:
Could not read from remote repository. Please make sure you have the
correct access rights and the repository exists.
Most likely cause to this is that your Amazon EC2 instance does not have any connectivity to the internet. This maybe be because it is in the private subnet or you have some security group rules to block the outgoing connection. If your instance is in private subnet then you may need to associate a NAT gateway and add a route table entry to allow the ec2 instance reach to the internet.

Related

Jenkins job fails with git "git clone" using ssh key

I am trying to run python test cases through Jenkins, it has the git clone command with ssh key.
Command : git clone -v ssh://user#host:29418/project folder_to_clone
Getting the error like :
Warning: Permanently added '[host]:29418,[100.64.42.4]:29418' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
But while running locally everything fine, On Jenkins only getting this issue.
You need to add create a shh key using ssh-key , add it to both jenkins credentials and the git repository you are trying to fetch the code from.

Git remote pull using GitHub deployment keys - Permission Denied

I have done the following steps to setup ssh deployment keys with our git repo for it to be able to git pull without a username and password:
Note: I am on AWS EC2 / Ubuntu 14.04.3
Run ssh-keygen -t rsa -b 4096 -C "ownersEmail#gmail.com" these are then saved as id_rsa and id_rsa.pub in ~/.ssh/
The deployment public key (id_rsa.pub) is added on the GitHub online UI in the deployment keys section
The directory is already cloned in /var/www/ directory, this is working all good via HTTPS for pulling
Try sudo git pull git#github.com:ownersUsername/OurRepo.git and get the following error
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Another Note: This repository is private under another users account.
Also, when I try ssh git#github.com I get:
Hi userName/Repo! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
And the deployment key comes up as being used. Have been on this issue for greater than 4 hours now and any would would be very much appreciated, thanks.
The problem is you're using sudo, which runs the command as root, and it will try to use the root's keys not your user's keys.
What you want to do is:
give your user/group write access to /var/www
run the pull/clone as the user, not the root user.
When you do a git pull you don't need the link.
git pull <remote> <branch>
You need the full url for the clone command
sudo git clone git#github.com:ownersUsername/OurRepo.git
To test if your ssh key is good use this:
git fetch --all --prune

Not able to access git repo from jenkins

I have configured Jenkins on a Linux machine and my git repo is on an another Linux server. But when I try to give the URL of the repo to Jenkins I get the following error.
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h ssh://user#ip/~/export1 HEAD" returned status code 128:
stdout:
stderr: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What could be the cause for this?
I have seen that both the systems' rsa key is present in each other's .ssh/known_hosts folder.
I am able to pull or clone code from the repo to a folder in Jenkins system as well. So why is Jenkins not able to take it?
I have also tried the URL user#ip:/fullpath/to/repo
You need to make sure Jenkins is running as the right user (the one who has the keys in ~/.ssh/id_rsa(.pub)
That user might not be the same as the one used in the ssh url: user#ip means you are connecting to ip using an account which has your public key in ~user/.ssh/authorized_key.
So the Jenkins process must be run by an account which has the private and public key, whose public key is in ~user/.ssh/authorized_key on the git server side.
And that account should have done (only once) an ssh-keyscan -H ip >> ~account/.ssh/known_hosts before any ssh attempt, in order to record the git server ip as a known host.
Does it being a bare repo make any difference or change in the URL?
No. The .git at the end of the bare repo folder is optional when used as an url.
Further to #VonC's reply, you can also use the Credentials plugin to define a set of credentials on your Jenkins master that your Jenkins job uses to access your Git repo. This allows you to run Jenkins itself as a different user from there one that has access to the Git repo.
The main problem was the security of the systems. I hadnt checked the authentication mechanisms on my server. The password authentication to the git server was causing the problem because the jenkins machine tries to directly fire a ls-remote to the path. When you do the same thing on the terminal you will be prompted for a password and then itl accept. When I set the password authentication and UsePAM to no and enabled the RSA authentication, pubkey authentication and authorised key setting to yes in the sshd_config file, and restarted, it was able to access the repo and I dint get this error.

Cannot create a working Git server

I have installed Git on my machine and finished the setup of every thing. Git is working fine locally, but when i try to access it globally always return the following
fatal: '/Gittest/project.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
I can access the server where the repository is identified through ssh connection. and access the files in the Git directory, though i can't set the directory as my remote origin
what should i do?
I have used the following command to set remote repository
git remote add origin svn#192.168.1.60:MDosoky/Gittest/project.git
and I have checked the connectivity from the client by using the following command
scp svn#192.168.1.60:MDosoky/Gittest/clientm.txt temp
where clientm is in the same location as project.git
It seems that I have entered a wrong public key instead of the user I was working on, the problem is solved by changing the public key in the server file

git clone using ssh failed in Windows due to permission issue

I have created a new GIT repository in my server at /home/myuser/.git/project.git.
I found ssh key for git from C:\Users\Toshiba\.ssh\github_rsa.pub & appended with server's authorized_keys file.
when i try to do git clone using ssh it fails as below.
$ git clone ssh://myuser#mysite.net:2888/home/myuser/.git/project.git
Cloning into 'project'...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Could you please help me in resolving this issue.
If your public/private key doesn't have the standard name C:\Users\Toshiba\.ssh\id_rsa(.pub), but C:\Users\Toshiba\.ssh\github_rsa.pub, then you need an ssh config file
Host mysite
Hostname mysite.net
User myuser
Port 2888
IdentityFile C:\Users\Toshiba\.ssh\github_rsa.pub
That would allow you to do
git clone mysite:/home/myuser/.git/project.git
Test it first wih ssh -Tvvv mysite, and then ssh mysite ls.
Make sure the environment variable %HOME% is defined to C:\Users\Toshiba
You have another example in "SSH error on push to an existing project Permission denied (publickey)"

Resources