developer tip

Git은 푸시 할 때마다 사용자 이름을 묻습니다.

optionbox 2020. 10. 3. 10:32
반응형

Git은 푸시 할 때마다 사용자 이름을 묻습니다.


내 저장소에 밀어 넣으려고 할 때마다 git은 둘 다 요구합니다 username & password.

매번 비밀번호를 다시 입력하는 데 문제가 없지만 사용자 이름을 입력하는 데 문제가 있습니다. https내 저장소를 복제 하는 사용 합니다.

따라서 username.NET에서 요청하지 않도록 git을 구성하려면 어떻게해야합니까 git push?

나는 리눅스를 처음 접했지만 Windows의 IIRC는 git push암호 만 묻습니다.


편집 (조정자와 댓글이 제안한대로 @ dk14에 의해)

경고 : credential.helper store답변에서 사용 하는 경우 암호는에 완전히 암호화되지 않은 ( "있는 그대로") 저장됩니다 ~/.git-credentials. 특히 고용주가 보안 문제를 전혀 용납하지 않는 경우 아래의 의견 섹션 또는 "연결됨"섹션의 답변을 참조하십시오.

수락되었지만 사용자 이름 만 (비밀번호 아님) 생략에 대한 실제 OP의 질문에 대답하지 않습니다. 정확한 문제가있는 독자에게는 @grawity의 답변 이 유용 할 수 있습니다.


원래 답변 (@Alexander Zhu 작성) :

다음 명령을 사용하여 자격 증명을 저장할 수 있습니다.

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

또한 나는 당신이 읽을 것을 제안합니다
$ git help credentials


.git/config로컬 저장소 파일 에서이 작업을 수행 할 수 있습니다 . 이 파일에는 'url'항목이있는 'remote'섹션이 있습니다. 'url'항목은 당신이 말하는 저장소의 https 링크를 포함해야합니다.

호스트 'url'앞에 git사용자 이름을 붙이면 사용자 이름을 더 이상 묻지 않아야합니다. 예를 들면 다음과 같습니다.

url = https://username@repository-url.com

Git 리포지토리로 영구 인증

자격 증명 캐싱을 활성화하려면 다음 명령을 실행하십시오.

$ git config credential.helper store
$ git push https://github.com/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

캐싱 만료 도 지정해야합니다.

git config --global credential.helper "cache --timeout 7200"

자격 증명 캐싱을 활성화하면 7200 초 (2 시간) 동안 캐시됩니다 .


자격 증명 문서 읽기

$ git help credentials

GitHub의이 문서에 설명 된대로 새 SSH 키를 추가 합니다.

힘내는 여전히 사용자 이름 및 암호를 요청하는 경우, 변경 시도 https://github.com/git@github.com:원격 URL에서 :

$ git config remote.origin.url 
https://github.com/dir/repo.git

$ git config remote.origin.url "git@github.com:dir/repo.git"

내가 찾은 가장 쉬운 방법은 다음 명령을 사용하는 것입니다.

git config --global credential.https://github.com.username <your_username>

이것은 사이트별로 작동하며 전역 git 구성을 수정합니다.

변경 사항을 보려면 다음을 사용하십시오.

git config --global --edit

ssh 대신 https를 사용하는 경우 .git/configuser701648이 말한대로 "url"을 편집 할 수 있지만 원하는 경우 비밀번호도 추가 할 수 있습니다.

url = https://username:password@repository-url.com

You can set your username for all repositories at a given site by putting something like the following in your Git configuration file. You'll want to change "https://example.com" and "me" to the actual URL and your actual username.

[credential "https://example.com"]
    username = me

(This is directly from "git help credentials")


Make sure that you are using SSH instead of http. Check this SO answer.


When I only git pull, git pull origin xxx, git asks for both username & password.

git config credential.helper store

it works.


Changing the cloned repo works:

git remote set-url origin git@github.com:gitusername/projectname.git

Using cached credentials works, and setting the timeout period makes things less annoying. If you use the Windows credential helper, that should be the easiest method (especially if SSH is blocked).


In addition to user701648's answer, you can store your credentials in your home folder (global for all projects), instead of project folder using the following command

$ git config --global credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

The easiest way is to create a ~/.netrc file with the following contents:

machine github.com
login YOUR_GITHUB_USERNAME
password YOUR_GITHUB_PASSWORD

(as shown here: https://gist.github.com/ahoward/2885020)

You can even close up the permissions on this file so that no one can read your password by typing:

chmod 600 ~/.netrc

git config --global credential.helper cache


If you use SSH version, you will not have any problems with passwords.Only one time you generate SSH key, to tell git, that this pc will work with this github account and never ask me again about any access (for this pc).

How To Generate SSH for Github


To avoid entering username, but still be prompted to enter a password, then you can simply clone your repository including the username:

git clone user_name@example.gitrepo.com/my_repo.git

  1. $ git config credential.helper store

  2. $ git push/push https://github.com/xxx.git

  3. Then enter your user name and password.

  4. Done

You can just run

git config --global credential.helper wincred

after installing and logging into GIT for windows in your system.


Quick method

get url of your git when inside working dir :

git config remote.origin.url

then :

git config credential.helper store

git push "url of your git"

will ask username and password last one time

done.

참고URL : https://stackoverflow.com/questions/11403407/git-asks-for-username-every-time-i-push

반응형