how can I make git clone fail on password prompt - bash

I am git cloning ~3000 repositories in a bash script like this:
[loop-sy]
git clone https://foobar.com
[ys-pool]
Most of these are public repositories and it works fine, but some of them are private and they return a username and password challenge. Is there a way to just move to the next repo (i.e. fail and get on with it) rather than having the bash script stop for me to enter the username and password.
I have searched high and low, but I have not found an answer yet.
I am running an Ubuntu 18.04 server and have root privileges.

You can set GIT_TERMINAL_PROMPT to 0, which will prevent Git from prompting for credentials. It will still use any that it can find in any credential helper you may be using, but if those don't work, it will just fail instead of prompting.

Related

Jenkins git authentication failed with correct credentials on Windows

I'm currently using Jenkins on Windows 10, and using git as version control system.
Although I provided correct repository URL and credential, I cannot use jenkins with error below.
Failed to connect to repository : Command "git.exe ls-remote -h REPOSITORY_URL HEAD" returned status code 128:
stdout:
stderr: git#URL: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Credential and URL doesn't seems wrong, since this build success previously with same credential. The only change after successful build was one line in build script.
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
After I success with this script, git setting keeps failed. Is there any problem with that line? And how can I fix it?
EDIT
Problem solved! For anyone who has same problem, it was problem with the system user! Since ssh key stores in each user space, jenkins cannot detect where the ssh key located. Therefore, go to 'service' in windows, and change user of jenkins service to the user who has correct ssh key. It solved my problem!
Seems there is some problem in Jenkins.
It cannot locate OpenSSH folder in System32, and so that I cannot get log with it.
That would explain why the main Jenkins controller (aka "master" in old terminology) cannot contact the Git repository (assuming an SSH URL here, with technical remote user account "git")
Try and remove that git configuration to see if the error persists: Git should fall back to its own ssh.exe, packaged with Git For Windows.
As noted by the OP, this only works if said Jenkins is run as a user account, not as the system account.
Only then will it be able to access the %USERPROFILE%\.ssh folder.

Switching my git bash credentials from virtual machine to my home system

I am about to finish a coding boot camp which had us blindly set up our git and github account info through Vagrant/putty in the beginning using SSH keys. I went ahead and downloaded cmder and set it up to launch bash on terminal open, but when I try to git push or pull, I am getting an error Permission denied(publickey). fatal: could not read from remote repository.
I have checked the username and email, and they are set to my correct credentials. Will the fact that I made the SSH keys while logged in to the schools Vagrant system cause issues, and if so, is there a way to strip and reset my SSH keys or switch my git to use HTTPS credentials to log in?
I've done a good bit of googling and only come across ways to install and setup git bash, which I've of course already done. Thanks in advance for any help.
One benefit of using SSH keys over your username and password is that you can have separate keys for each machine you'll log into GitHub with. Don't transfer the keys; just generate new ones for your home machine, and disable the old VM keys on GitHub's end.

Jenkins issue with Git [Permission denied (publickey).] on Windows

I know that thousands of topics touch my problem but I am fighting this from several days with almost zero progress ;(.
I installed Jenkins on Windows machine.
Then acquired Git plugin and the Git itself.
Everything is latest version for the day of my writing.
I was just happy to start to play with Jenkins but I failed at configuring my Bitbucket repository to be used by Job.
I set the exact path to git.exe (as it seemed the reason for initial problems) [C:\Program Files\Git\cmd\git.exe].
Then I tried accessing the repository by HTTPS with account credentials, many strange errors here so I thought let's try with SSH.
I have generated rsa keys, set the public key in the Bitbucket repository. Then I created credential configuration in Jenkins for SSH authentication with passphrase.
I have many problems here so for temporary workaround I explicitly set the value of private key.
Finaly I got to the place where I am now:
+refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I try to manualy copy repository, it politely asks me about passphrase and the copy is done. When Jenkins job does it the above happens. With help of %USERNAME% and %USERDOMAIN% in the Job's script I get the same values like when I do it manually.
After plenty of hours I can say I can't use Git in Jenkins ;(
UPDATE
I don't believe that it could be so simple. As mainframer mentioned, I left passphrase empty for the whole SSH authentication and it really worked (the repository is cloned even that Jenkins still shows the same error in job's configuration page). I only wonder about any consequences of such setup, but working thing is more valuable for me now.
You mean leaving empty passphrase while generating keys and then also no passphrase config in Jenkins ssh credentials?
Yes, as Jenkins wouldn't be able to feed the passphrase to the ssh session.
But make sure the Jenkins slave service runs with your account (and not with the system account). It needs your account to find the ssh keys in %USERPROFILE%\.ssh\id_rsa(.pub)

Why does this user data script not pull from Git repo?

I have a launch configuration and auto-scaling group set up. The launch config uses an AMI that I've already created, based on Ubuntu 14.04, that installs Nginx, Git, and has my static files stored as a Git repo in Nginx's /usr/share/nginx/html/ directory.
The problem: the static files in my nginx/html directory are only as new as the files that were loaded in the AMI when I created it.
To remedy this, I have tried to add a "User Data" field into the launch config. The field is defined as:
#! /bin/bash
cd /usr/share/nginx/html/
git pull origin master
<my git repo's password>
But when I check to see if the instance has the latest version of the repo, I see that it doesn't. Something is wrong with my script, and I'm not sure what.
I have tested entering these commands one-by-one exactly as is into the EC2 instance via SSH, and it works exactly as expected.
Why doesn't this work in the user data field?
Note: I have verified that the 'bash' file is indeed present in /bin/bash.
You need to pass username and password of your repository with the repo url
Sample example :
#! /bin/bash
cd /usr/share/nginx/html/
git clone https://username:password#yourRepoURL.git
Problem is definitely in the bash script. Everything it contains is executed by bash, so it actually tries to execute your password as a command.
There are multiple ways to provide a password to Git in a script. See for example this question: How to provide username and password when run "git clone git#remote.git"?
It basically depends on how secure do you need it. Maybe it's enough to have a plain text password in Git's config (it doesn't have to be so bad if you set a restricted mode for that file, it would be similar to using a private key without passphrase).
It's been a while since I asked this- I've learned a lot since then.
You can pass your username and password as part of the URL, but that is bad form as if you share the code with anyone or give anyone access to your script then they will know your account credentials.
The best way to do this would be to set up your server to connect to your Git repo over SSH - I believe this is industry best practice as it is more secure and password-less.

Automate Login in Shell Script

I want to create an automate login for github push to repository script in mac terminal. But I met some problem with login issue, like it will ask for username and password, so what command that can automatically insert username when it ask for username same with password?
I found 'expect' command in Linux, but the way of using is different in Mac terminal.
Lunayos-MacBook-Pro:SuperDeals-iPhone Lunayo$ git push origin
Everything up-to-date
Lunayos-MacBook-Pro:SuperDeals-iPhone Lunayo$ git push upstream
Username:
You should refer to GitHub's excellent help articles:
Set Up Git
SSH key passphrases
Remotes
You need to either generate an SSH key with no passphrase (or start ssh-agent before you use your script if you would like to use a passphrase); otherwise, OpenSSH will ask for a password or passphrase.
Also ensure that your remote URL looks like ssh://git#github.com/user/repo.git or git#github.com:user/repo.git. Specifically, the git# part tells Git and OpenSSH that you want to make the SSH connection using the username git (which is correct for all GitHub repositories).

Resources