Git: How to change password of credentials used to clone a repository - linux

I am working on linux and I clone a private repository using my github account credentials. But over the period of time my password has changed for github and whenever I try to use git pull it is giving me an error
remote: Invalid username or password.
How can I change the password which I used while cloning the repository for the first time?

You the issue an git remote -v and check what kind of auth you are using. I always use git protocol (which uses SSH). You can freely edit those remote urls in ./git/config file. I believe you cloned it using HTTP (or using SSH w/o .ssh key file being present).
If you want to use SSH, you can follow this: https://help.github.com/articles/generating-ssh-keys
Then you will never need to worry about passwords again.

Related

Git pull/clone with username and password in AWS Code Commit

I Need to do a git pull using https url as a oneline command . this command I need to integrate in a bash script . But all the time it is asking the usernmae and password .
The repository is in AWS codecommit
Try this:
git clone https://username:password#git-codecommit.us-east-1.amazonaws.com/v1../repos../..
This way worked for me for CodeCommit (AWS) repository
Check this link: Enter user password in command
As is described perfectly in that post, you basically have three options:
Store the password in .netrc file (with 600 permissions). Make sure you clone the repo specifying the username in the url.
Clone the repo with https://user:pass#domain/repo . Take into account that your password will be visible in several places...
Use the credential helper.
As an update, AWS has released their remote git remote codecommit. With proper IAM setup, you can do oneline pulls without even passing username and passwords. This is now the recommended method by AWS. It can be setup on your local or on a container that's running in an AWS Pipeline for example.
i.e. git clone codecommit://HelloWorldRepo myLocalHelloWorldRepo
And then you can git pull as normal.
Full documentation is here:
https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-git-remote-codecommit.html

Git requires username and password for git push, git pull using HTTPS method

So, when I use HTTPS method for cloning git repository and do some changes and push or pull to git it will always be prompting me for username and password. what's the solution for that?
Apart from changing to SSH, you can also keep using HTTPS, if you don't mind to put your password in clear text. Put this in your ~/.netrc and it won't ask for your username/password (at least on Linux and Mac)
Make one .netrc file in your home directory.
machine github.com
login <user>
password <password
The solution to your problem is this git command which is kind of remember me of GIT.
git config credential.helper store
Read this for details:
GIT credentials store

How to skip password typing for Git against Kerberos?

I have a problem with git clone from TFS. Client is Ubuntu 14.04,
TFS certificates are available because https works properly. Proxy is unset in Git and global env.
Working scenarios:
A. git clone https://url.to.my.tfs/
B. git clone https://user#url.to.my.tfs/
A. requests username and password, type them, all proceed good.
B. Git don't request a password. Cloning is proceed good. So communication linux(git)-kerberos(TFS) is already OK.
Modified A.) pressed Enter when git request for username and password I get:
fatal: Authentication failed for https://url.to.my.tfs
So, where is the problem? How to skip password typing?
fatal: Authentication failed for... is exactly because of that you didn't type user/pass when requested.
And git clone https://user#url.to.my.tfs/ and no password requests from Git can be because of Git credential.helper cache used on HTTPS protocols.
https://git-scm.com/book/gr/v2/Git-Tools-Credential-Storage
This answered question relates to HTTPS on Github but it also applies to your scenario. Is there a way to skip password typing when using https:// on GitHub?
There you can find option that suits you best.

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.

Only one user can push/pull to github

I have two CentOS servers that are set up the same. I created a git repo on server A and pushed it to github. I then cloned the repo on server B. At first, all seemed to be in order. I could commit on either server, push to the remote, and the pull on to the other server.
The problem is that my co-workers now cannot push or pull on server B (they can run git status or commit). Strangely, this applies to ALL repos on server B, not just the one I cloned. Here is the error they see:
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I checked that they are in the collaborators lists (both as owners and on the team assigned to the repo).
I also tried changing to the root user and cloning the repo again--as root I received the same error as above. The global .gitconfig does not reference my user or key, and the local .git/config files are set to use SSH (git#github.com).
What would cause this error to happen all users but one? Where else should I be looking?
Add '-v' to your git command as you run it to get more verbose output, that should tell you what's wrong.
I did resolve this issue. I found the problem by running ssh -T -vvv git#github.com which showed different keys being used for my user vs. the other users on the server. The key being used generally was not tied to a user in our github account. The fix:
Generated a new SSH key
Added key to shared user on github account
Updated .ssh/config to use the new key when accessing github.com
I am not certain how the SSH key got messed up, because it worked before. But this fixed it.

Resources