Git이 원격 GitHub 저장소에 잘못된 사용자로 푸시
업무용 GitHub 계정과 개인 계정이 있습니다. 먼저 테스트 프로젝트에 개인용 계정을 사용한 다음 다른 계정으로 동일한 컴퓨터에서 저장소를 만들었습니다.
이제 개인 계정에 새 저장소를 다시 만들고 싶었고 global 및 local을 변경 user.name
하고 GitHub 설정 페이지에 입력 된 새 ssh 키 쌍을 수행했습니다. 그런 다음 디렉토리를 설정했습니다.
git init
git remote add origin <url>
git push origin
하지만 지금은 말해
오류 : personaluser / newrepo.git에 대한 권한이 거부되었습니다.
다른 계정이이 계정에 어떻게 연결되어 있는지 모르겠습니다. 관련 항목이 .git/config
없습니다 workusername
.
Windows 10을 사용하는 경우 시간을내어 Rajan의 답변을 읽으십시오.
이것은 나의 현재 작업 설정과 매우 유사하게 들립니다. 이미 별도 ssh-keys
의 ~/.ssh/config
파일을 설정 한 것으로 보이므로 파일 을 만들고 다음과 유사한 정보로 채워야합니다.
Host work.github.com
HostName github.com
User WORK_GITHUB_USERNAME
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_work_rsa
IdentitiesOnly yes
Host personal.github.com
HostName github.com
User PERSONAL_GITHUB_USERNAME
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_personal_rsa
IdentitiesOnly yes
모든 속성은 매우 자명하지만 IdentitiesOnly
하나입니다. 나는 그것이 무엇을위한 것인지 설명하려고하지 않을 것이지만 그것은 나의 현재 설정에 있고 잘 작동합니다.
Host URL
는 올바른 사용자 설정을 가져 오기위한 포인터 일 뿐이며 파일을 대상 HostName
URL로 올바르게 가져 오는 데 아무런 영향을 미치지 않는다는 점도 주목할 가치가 있습니다 .
이제 귀하의 origin
(또는 remote
일반적으로) URL이 Host
사용자 이름에 따라 각 저장소 의 올바른 URL 과 일치 하는지 확인하기 만하면 됩니다. 기존 개인 저장소가 이미있는 경우 .git/config
텍스트 편집기에서 해당 저장소의 파일을 편집 할 수 있습니다 .
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@personal.github.com:PERSONAL_GITHUB_USERNAME/project.git
또는 명령 줄을 통해 수행하십시오.
git remote set-url origin git@personal.github.com:PERSONAL_GITHUB_USERNAME/project.git
당신의 일과 마찬가지로 :
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@work.github.com:your_work_organization/project.git
또는 다시 명령 줄을 통해 :
git remote set-url origin git@work.github.com:your_work_organization/project.git
물론 파일 의 Host
URL 중 하나를 다음과 같이 설정할 수 있습니다.~/.ssh/config
Host github.com
work.github.com
구성 관계를 더 쉽게 볼 수만 있었습니다.
이 모든 설정이 완료되면 각 리모컨으로 푸시 할 수 있습니다.
편집하다
내가 방금 알아 낸 한 가지 주목할 점은 값에 대해 전역 git 구성 값을 설정 한 경우 user.email
( user.name
다른 값도 보낼 것 같음 ) git이 해당 이메일 사용자로 커밋을 표시한다는 것입니다. 이 문제를 해결하려면 로컬 저장소 내에서 전역 git 구성 설정을 재정의 할 수 있습니다.
$ git config user.name "John Doe"
$ git config user.email johndoe@example.com
이제 해당 저장소의 올바른 사용자로 커밋을 보내야합니다.
제어판> 사용자 계정> 자격 증명 관리자> 일반 자격 증명으로 이동합니다.
git 자격 증명을 제거하십시오. 그런 다음 git push를 실행하십시오. 그러면 git 자격 증명을 묻는 메시지가 표시됩니다. 올바른 자격 증명을 입력하십시오.
ssh 대신 https로 전환 할 수도 있습니다. https를 사용하는 경우 .git / config 설정을 따릅니다. 따라서 .git / config에서 다음을 변경하십시오.
url = git@github.com:USER/PROJECT.git
...에
url = https://USER@github.com/USER/PROJECT.git
(이 값은 git 프로젝트 페이지에 있으며 SSH
및 HTTP
버튼을 클릭하여 새 값을 생성합니다.)
github는 git의 설정이 아닌 ssh 키로 사용자를 식별합니다.
따라서 개인 계정으로 푸시를 시도 할 때 업무용 계정의 ssh 키가 키링에 없는지 확인해야하며 그 반대의 경우도 마찬가지입니다. 사용 ssh-add -l
당신의 열쇠 고리에있는 키를 결정하고, ssh-add -d keyfile
당신의 열쇠 고리에서 키를 제거 할 수 있습니다.
또한 ~/.ssh/config
특정 ssh 키를 github에 제공하도록 구성했는지 확인해야 할 수도 있습니다 . 마지막으로, github가 동일한 ssh 공개 키를 가진 두 개의 계정을 어떻게 처리하는지 모르겠으므로 그렇게하지 마십시오.
최근에 새 github 계정을 만들었 기 때문에 동일한 문제가 발생했습니다. 위의 답변을 시도했지만 도움이되지 않았습니다. 그런 다음 Keychain Access 에서 github를 삭제하는 방법에 대한 게시물을 보았습니다 ( mac을 사용하는 경우에만 해당 ). 내가 git push하면 사용자 이름과 암호를 요청하고 작동했습니다!
나는 같은 문제가 있었다. 동일한 SSH 키를 사용하는 GitHub에 두 개의 계정이 있고 GitHub는 기본적으로 내가 원하는 저장소에 대한 권한이없는 잘못된 계정을 사용하는 것으로 나타났습니다. 예상대로 작동하지 않는 계정에서 SSH 키를 제거했습니다.
GitHub가 자신을 인증하는 계정을 다음과 같이 테스트 할 수 있습니다.
ssh -T git@github.com
나에게 이것은 원래 잘못된 사용자 이름을 표시했지만 해당 계정에서 중복 SSH 키를 제거한 후 올바른 사용자 이름을 표시하고 내 저장소에 대한 가져 오기 및 푸시가 잘 작동했습니다.
이것이이를 수행하는 방법입니다. 다른 ssh 계정에 대해 다른 ssh 구성을 사용할 수 있습니다.
2 월 22 일 업데이트 :
이 링크를 확인하십시오 : https://gist.github.com/2351996
나는 이것이 조금 늦을 수도 있다는 것을 알고 있지만 꽤 오랫동안 이것을 고수했고 마침내 다음과 같이 고쳤습니다.
키 체인 액세스 (osX)로 이동
git 검색 (모든 항목을 선택했는지 확인하십시오)
- 여기에서 범인 자격 증명을 찾을 수 있습니다. 그들을 삭제하십시오.
도움이 되었기를 바랍니다!
계정과 연결된 SSH 키 변경이 작동하지 않으면 계정과 연결된 이메일을 변경하십시오.
Go to Github > Account Settings > Emails and verify the email address you are using to commit matches the email on the account.
To see what email address you're using to commit, run the following command: git config --global user.email
. If you need to change the email address that you are using to commit, run git config --global user.email "your_email@youremail.com"
.
I got the same issue. Below is what happen in my case:
I previously made git to not ask my credential every time I talk with remote repository by this: git config --global credential.helper wincred
I resolved the issue by running the same command with "none" replacing "wincred" git config --global credential.helper none
Then git ask my username/pass again and everything go well
I had this problem as well but none of the other solutions worked for me. It turns out that for work we had created a .netrc
file that had entries for github authentication. The git
command always used the .netrc
, which had my old user name and password. I had to edit the entries in my .netrc
file to use the new username and password.
Never had any problems with git till at work they recently connected our macbooks to Active Directory & added a few admin accounts to my machine. However, after that git would work fine till i locked my screen and came back. Then I would get a vague error similar to
No user exists for uid 1927040837
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I only have one ssh key on this particular machine for my user and am using zsh in my term. The user email and name were correct so that wasn't the issue. Ergo, restarting after every time i lock my machine is futile. The solution for me was to edit my .zshrc
file and uncomment the line that exports the ssh-key (which i've never had to do before and have been using zsh for years).
The line should look something like this:
# ssh
export SSH_KEY_PATH="~/.ssh/<your_rsa_id>"
Once you do this just run a reset
in terminal and everything works fine.
I hope this helps someone else.
I would like to add - If you are working on another user's account make sure you add yourself to the collaborators area under the repositories settings.
I ran into this problem as well and none of the above solutions worked even after I deleted my ssh key and made a new one. Turns out ssh-agent was using a cached key, so I had to run killall ssh-agent
and then it worked.
Found the solution here. http://fzysqr.com/2012/08/28/quick-tip-wrong-ssh-key-cached-with-github-after-changing-users-and-keys/
I have found a temporary solution in which first run killall ssh-agent
then add the ssh keys generated for the account you need to use ssh-add ~/.ssh/id_4shameer
This is the one way in which we can work on the multiple github account when we will get the error of type ERROR: Permission to user/repo-git.git denied to username
.
참고URL : https://stackoverflow.com/questions/4665337/git-pushing-to-remote-github-repository-as-wrong-user
'development' 카테고리의 다른 글
이스케이프 된 유니 코드로 문자열을 어떻게 디코딩합니까? (0) | 2020.10.20 |
---|---|
ASP.NET MVC Razor : HTML의 조건부 속성 (0) | 2020.10.20 |
IIS-401.3-권한 없음 (0) | 2020.10.20 |
다른 변수 세트로 템플릿 모듈을 사용하는 방법은 무엇입니까? (0) | 2020.10.20 |
STL 벡터를 정렬하는 방법은 무엇입니까? (0) | 2020.10.20 |