Programing

Git이 계속 암호를 묻는 메시지를 표시합니다.

lottogame 2020. 10. 3. 09:43
반응형

Git이 계속 암호를 묻는 메시지를 표시합니다.


나는 한동안 Git을 사용해 왔지만 암호에 대한 끊임없는 요청이 나를 막기 시작했습니다.

저는 Mac OS X 및 GitHub를 사용하고 있으며 GitHub의 Git 설정 페이지 의 지침에 따라 Git 및 SSH 키를 설정했습니다 .

또한 GitHub의 SSH 키 암호 페이지 에 언급 된대로 Mac OS X 키 체인에 github SSH 키를 추가했습니다 . 내 공개 키가 Git에 등록되었습니다.

그럼에도 불구하고 Git 풀을 시도 할 때마다 사용자 이름과 비밀번호를 입력해야합니다. 이를 위해 설정해야하는 SSH 키 외에 다른 것이 있습니까?


잘못된 Git 저장소 URL이 있다고 생각합니다.

.git/config[remote "origin"] 섹션을 열고 찾습니다. SSH를 사용하고 있는지 확인하십시오.

ssh://git@github.com/username/repo.git

복제 또는 다운로드 를 클릭 하고 ssh를 선택 하면 저장소의 기본 페이지에서 SSH URL을 볼 수 있습니다 .

https또는 git하나가 아닙니다 .

https://github.com/username/repo.git
git://github.com/username/repo.git

이제 사용자 이름과 암호 대신 SSH 키 만으로 유효성을 검사 할 수 있습니다 .

망할 놈의 그 불평하는 경우 'origin' has already been added, 열린 .config파일을 편집 url = "..."한 후 일부 [remote origin]등을url = ssh://github/username/repo.git


credential.helper 구성

OS X (현재 macOS)에서는 터미널에서 다음을 실행합니다 .

git config --global credential.helper osxkeychain

이를 통해 Git은 Keychain.app 파일을 사용하여 사용자 이름과 암호를 저장하고 키 체인에서 개인 SSH 키에 대한 암호를 검색 할 수 있습니다.

Windows의 경우 :

git config --global credential.helper wincred

문제 해결

Git 자격 증명 도우미가 올바르게 구성된 경우 macOS는 키 체인에 암호를 저장합니다. 때로는 SSH와 키 체인에 저장된 암호 사이연결 이 끊어 질 수 있습니다. ssh-add -K또는 ssh-add ~/.ssh/id_rsa키를 다시 키 체인에 추가하려면 실행 하십시오.

macOS v10.12 (Sierra)에서 ssh로 변경

macOS v10.12 (Sierra)의 경우 ssh-add -K재부팅 할 때마다 실행해야합니다. 이를 방지하려면 ~/.ssh/config이 컨텐츠로 작성 하십시오.

Host *
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/id_rsa

ssh_config man10.12.2 페이지에서 :

UseKeychain

macOS에서 특정 키를 사용하려고 할 때 시스템이 사용자의 키 체인에서 암호를 검색해야하는지 여부를 지정합니다. 사용자가 암호를 제공 한 경우이 옵션은 암호가 올바른 것으로 확인 된 후 암호를 키 체인에 저장할지 여부도 지정합니다. 인수는 '예'또는 '아니요'여야합니다. 기본값은 '아니오'입니다.

Apple은 무슨 일이 일어 났는지 설명하는 Technote 2449추가했습니다 .

macOS Sierra 이전에는 ssh암호를 묻는 대화 상자를 표시하고 키 체인에 저장할 수있는 옵션을 제공합니다. 이 UI는 얼마 전에 사용되지 않으며 제거되었습니다.


macOS v10.12 (Sierra)로 업그레이드했을 때 이런 일이 발생했습니다. 업그레이드시 SSH 에이전트가 지워진 것 같습니다.

$ ssh-add -L
The agent has no identities.

단순히 실행하면 ssh-add내 기존 ID를 찾았습니다. 나는 암호를 입력했고 다시 갈 수 있었다.


이것을 사용하십시오 : github.com을 적절한 호스트 이름으로 바꿉니다.

git remote set-url origin git@github.com:user/repo.git

다른 사람들이 말했듯이 암호 캐시 도우미를 설치할 수 있습니다. 저는 대부분 Mac뿐만 아니라 다른 플랫폼에 대한 링크 만 게시하고 싶었습니다. Linux 서버를 실행 중이며 도움이되었습니다. Git에서 GitHub 비밀번호 캐싱

Mac의 경우 :

git credential-osxkeychain

Windows :

git config --global credential.helper wincred

Linux :

git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

또한 누가 당신에게 암호를 요구하는지 찾으십시오. Git 또는 SSH 에이전트입니까?

제 경우에는 매번 git pull다음과 같이 질문했습니다.

Enter passphrase for key '/work/username/.ssh/id_rsa':

그래서 나는 그것이 암호를 요구하는 Git이라고 생각했습니다. 그래서 계속해서 솔루션을 찾고 있었지만 나중에 SSH 에이전트가 종료되었다는 사실을 깨달았습니다. 여기에 제공된대로 eval $(ssh-agent)사용하여 수정할 수 있습니다 .ssh-add

Also am pasting below a little snippet you can add to your ~/.bashrc file (or the equivalent) to ensure that your SSH agent is started on your login.

In any case this was a pretty silly mistake I made, but posting it here, just in case it helps someone save some time from barking up the wrong tree, like I did.

# Start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."

    # Spawn ssh-agent
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
    echo succeeded
    chmod 600 ${SSH_ENV}
    . ${SSH_ENV} > /dev/null
    /usr/bin/ssh-add
}

if [ -f "${SSH_ENV}" ]; then
     . ${SSH_ENV} > /dev/null
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi


git config credential.helper store

Note: While this is convenient, Git will store your credentials in clear text in a local file (.git-credentials) under your project directory (see below for the "home" directory). If you don't like this, delete this file and switch to using the cache option.

If you want Git to resume to asking you for credentials every time it needs to connect to the remote repository, you can run this command:

git config --unset credential.helper

To store the passwords in .git-credentials in your %HOME% directory as opposed to the project directory: use the --global flag

git config --global credential.helper store

Guide to Git on Windows and GitHub using SSH to push/pull: An Illustrated Guide to Git on Windows

  1. Download and install PuTTY
  2. Set environment variable 'GIT_SSH' = 'path\to\plink.exe' (in installed putty folder) - very important!!!
  3. Restart Windows Explorer for environment variables to take effect (cannot only restart command prompt)
  4. Run puttygen.exe to generate new key, copy the public key to the GitHub site
  5. Save this new private key somewhere safe on the disk (preferable not Dropbox)
  6. Run putty.exe and connect SSH to github.co
  7. Quickly get to startup folder by running "shell:startup".
  8. Make your private key startup with Windows via pageant. Create a shortcut in Startup folder with syntax "path\to\pageant.exe" "path\to\privatekey"
  9. We do not need to set the 'puttykeyfile' setting inside .git/config of our repositories
  10. Very important is that the "SSH clone URL" of GitHub is used and not HTTPS.

In Windows for Git 1.7.9+, run the following command on the command prompt to open the configuration file in a text editor:

    git config --global --edit

Then in the file, add the following block if not present or edit it accordingly:

    [credential "https://giturl.com"]
        username = <user id>
         helper = wincred

Save and close the file. You will need to provide the credentials only once after the above change.


Use the following command to increase the timeout period so that you could retype password for a while

git config --global credential.helper 'cache --timeout 3600'

I used it for Bitbucket and GitHub it works for both. The only thing you need to do is 3600 is in seconds. Increase it to whatever extent you want. I changed it to 259200 which is about 30 days. This way I re-enter my password for every 30 days or so.


I figure you fixed your problem, but I don't see the solution here that helped me, so here it is.

Type in terminal:

echo "" > ~/.ssh/known_hosts

That will empty your known_hosts file, and you'll have to add every host you used and have connected to, but it solved the problem.


orkoden's answer on using the keychain with Git in your terminal was incomplete and raises errors. This is what you have to do to save the username and password you enter in the the terminal in your keychain:

curl http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain -o git-credential-osxkeychain
sudo mv git-credential-osxkeychain /usr/local/bin
sudo chmod u+x /usr/local/bin/git-credential-osxkeychain

Then enter

git config --global credential.helper osxkeychain

If you have already done the part with Git configuration before the curl stuff, it's no problem; it'll work.


Step 1: check your current configuration

cat .git/config

You will get:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/path_to_your_git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = your_username
    email = your_email
[branch "master-staging"]
    remote = origin
    merge = refs/heads/master-staging

Step 2: remove your remote origin

git remote rm origin

Step 3: add remote origin back with your username and password

git remote add origin https://your_git_username:your_git_password@github.com/path_to_your_git.git

As static_rtti said above, change

https://github.com/username/repo.git
git://github.com/username/repo.git

to

ssh://git@github.com/username/repo.git

I myself changed the https in the .git/config file to ssh, but it still wasn't working. Then I saw that you must change github.com to git@github.com. A good way to get the actual correct URL is to go to your project page and click this:

Change HTTPS to SSH to get the right URL

Then add this URL to the configuration file.


I feel like the answer provided by static_rtti is hacky in some sense. I don't know if this was available earlier, but Git tools now provide credential storage.

Cache Mode

$ git config --global credential.helper cache

Use the “cache” mode to keep credentials in memory for a certain period of time. None of the passwords are ever stored on disk, and they are purged from the cache after 15 minutes.

Store Mode

$ git config --global credential.helper 'store --file ~/.my-credentials'

Use the “store” mode to save the credentials to a plain-text file on disk, and they never expire.

I personally used the store mode. I deleted my repository, cloned it, and then had to enter my credentials once.

Reference: 7.14 Git Tools - Credential Storage


I agree with "codehugger" and using the instruction of "orkoden" it worked for me - on NetBeans 7.3 - when you right-click on the file and select context menu - push - a 'push to remote' window opened - there are two options here:

  1. origin:https://github.com/myaccount/myproject.git/

  2. https://github.com/myaccount/myproject.git/

As you can see, the difference is the origin parameter in the URL - you do not want to choose this option (1) you want to check option (2), and that works just fine for me.


If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository.

Using an HTTPS remote URL has some advantages: it's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials every time you pull or push a repository.

You can configure Git to store your password for you. For Windows:

git config --global credential.helper wincred

There are different kind of authentications depending on your configuration. Here are a few:

  1. git credential-osxkeychain.

    If your credential is invalid, remove it by:

      git credential-osxkeychain erase
    

    or:

      printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
    

    So Git won't ask you for the keychain permission again. Then configure it again.

    See: Updating credentials from the OS X Keychain at GitHub

  2. Your SSH RSA key.

    For this, you need to compare your SSH key with what you've added, check by ssh-add -L/ssh-add -l if you're using the right identity.

  3. Your HTTPS authentication (if you're using https instead of ssh protocol).

    Use ~/.netrc (%HOME%/_netrc on Windows), to provide your credentials, e.g.

      machine stash1.mycompany.com
      login myusername
      password mypassword
    

Learn more: Syncing with GitHub at Stack Overflow.


Before you can use your key with GitHub, follow this step in the tutorial, Testing your SSH connection:

$ ssh -T git@github.com
# Attempts to ssh to GitHub

Having a typo in the URL will make Git asking you for username and password, stupid Git.

It was tested on Kali Linux, Git version 2.7.0,

Try:

git clone https://github.com/thisrepodoesntexists/doesntexists.git


If you're using Windows and this has suddenly started happening on out of the blue on GitHub, it's probably due to GitHub's recent disabling support for deprecated cryptographic algorithms on 2018-02-22, in which case the solution is simply to download and install the latest version of either the full Git for Windows or just the Git Credential Manager for Windows.

참고URL : https://stackoverflow.com/questions/7773181/git-keeps-prompting-me-for-a-password

반응형