Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store a password for my key so I can commit and pull from repository when using git on windows?

Tags:

git

github

Can someone point me in the direction I need look so I can configure my GIT client with the password needed for my private key? Every time I push and pull from my repository it asks me for the password for my key. I use command line and have the windows GIT client installed to use ssh.

Thanks for any pointers.

like image 695
Richard Avatar asked Sep 02 '10 08:09

Richard


People also ask

How do I add a password to a Git repository?

To connect to a Git repository with authentication over HTTP(S), every time it needs to set a username and password. You can configure Git to remember a username and password by storing them in a remote URL or by using Git credential helper.


2 Answers

I just had this problem here. My local git tree was corrupted, so I deleted it and cloned the project again from github. After that, it started to ask for my password on every pull or push. After some time, I realized I cloned the project with the HTTP URL (https://[email protected]/user/project.git). When I cloned again using the SSH URL ([email protected]:user/project.git), it stoped asking for the password.

like image 165
Guilherme Garnier Avatar answered Sep 30 '22 23:09

Guilherme Garnier


Are you sure you’re cloning over SSH?

Run git remote -v. The output below is from a repository that clones via HTTPS: notice the https:// URL scheme.

origin  https://github.com/git/git.git (fetch)
origin  https://github.com/git/git.git (push)

Clone URLs for SSH will have one of two forms:

Assuming your host supports both SSH and HTTPS (as GitHub, GitLab, and Gitorious do), then simply change the remote’s URL rather than recloning the entire history.

git remote set-url origin [email protected]:foo/bar/baz.git

Different hosts will have different URL designs. For example, switch the above GitHub URL from HTTPS to SSH with

git remote set-url [email protected]:git/git.git

GitHub has a related guide for changing a git remote’s URL.

Windows

On Windows, a typical setup uses PuTTY as the SSH client, which means you’ll want to run Pageant, PuTTY's SSH agent. On Windows, I run a quick batch job out of the Startup group:

@echo off
start /b "C:\Program Files\PuTTY\pageant.exe" "C:\Users\Greg\Greg.ppk"

where Greg.ppk is a key that I created with PuTTYgen.

One more step: tell git to use plink, PuTTY's client for non-interactive connections. Set the environment variable GIT_SSH to

C:\Program Files\PuTTY\plink.exe

assuming that's where PuTTY lives.

Unix, Linux, Cygwin, Git Bash

On Unix-like platforms, the fix is straightforward. If ssh-agent isn't running, start it with, for example

$ eval `ssh-agent`

and then add your default identity with

$ ssh-add

If you have an identity somewhere else, run

$ ssh-add /path/to/other/ssh_id

If you're still having trouble, GitHub has a page for troubleshooting issues with GitHub and SSH, but please also update your question so we can make this a more helpful resource.

Downside of a passwordless SSH key

It may seem tempting to create and register an SSH key that has no password or passphrase because you won’t be prompted for it with each git clone, git fetch, git pull, or git push. However, with no passphrase, your SSH key is unencrypted. This means that anyone who is able to obtain a copy of your private key (the file named id_rsa, id_dsa, id_ecdsa — without the .pub extension) can impersonate you with no effort.

The nice design of SSH means that it is possible to make operations both convenient and secure. Go ahead and make your setup secure today. For a few minutes of extra effort now, you won’t have to wonder about it down the road.

If you’ve already set up a passwordless key, encrypt it by running

ssh-keygen -p

You will see prompts for the key file (with a default value), for your new passphrase, and again to confirm that you typed your passphrase correctly.

like image 25
Greg Bacon Avatar answered Oct 01 '22 01:10

Greg Bacon