![](/img/trans.png)
[英]Intellij IDEA fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists
[英]ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and repo exists
昨天我創建了一個 ssh 密鑰並克隆了一個工作倉庫。 進行一些更改后,我嘗試推送提交:
git push
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我已經閱讀了這個活躍的 SO 帖子。 我的問題仍然存在。 我不知道如何追蹤這個問題,所以將分享我認為相關的所有內容。
在我的筆記本電腦上,我有個人和工作回購。 我的工作位於嵌套在~/Documents/Projects/Zen/Projects/
下的任何目錄中。 其他任何地方,例如~/Documents/Projects/Personal/
用於個人 github。
我的 .gitconfig 看起來像這樣:
[user]
email = 12345+doug@users.noreply.github.com
name = 12345doug
[includeIf "gitdir:/home/doug/Documents/Projects/Zen/"]
path = ~/.git-zen
/.git-zen 看起來像這樣:
[user]
email = doug@work.com
name = doug-work
目前我在一個回購:
pwd
/home/doug/Documents/Projects/Zen/Projects/analytics-psql-action
准備好一些提交:
~/Documents/Projects/Zen/Projects/analytics-psql-action$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
我在這個目錄中的 git 配置似乎是正確的:
git config user.name
doug-work
和
git config user.email
doug@work.com
為了創建我的 ssh 密鑰,我關注了 github.com 上的這篇文章。
ssh-keygen -t rsa -b 4096 -C "doug@work.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
然后我根據本教程將密鑰添加到我的工作 github 設置中。
到目前為止,我認為我已經設置好了一切? 但是當我嘗試從這個 repo 中推送時:
~/Documents/Projects/Zen/Projects/analytics-psql-action$ git push
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
無奈之下,我重命名了 repo 並嘗試從新克隆:
git clone git@github.com:work/analytics-psql-action.git # real path actually used not 'work'
Cloning into 'analytics-psql-action'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
在 repo 本身,如果我進入 repo settings > manage access 我可以看到自己,doug-work 具有管理員訪問權限。
如何克隆並推送到 repo? 我應該從哪里開始試圖找出為什么我的 ssh 密鑰設置不起作用?
首先,一些背景知識:在您在這里使用的 URL 中:
git clone git@github.com:...
這個問題唯一真正重要的部分是git@github.com
部分。 你也可以拼寫:
git clone ssh://git@github.com/...
(使用完全相同的其余文本代替...
)具有完全相同的效果。
接下來,要診斷問題,您需要從命令行運行ssh
:
ssh -T git@github.com
如果你的 URL 是git@corp.com
你會想在這里運行ssh -T git@corp.com
,等等。 也就是說,我們使用user@host
部分並運行ssh -T user@host
。 這使得這項工作適用於各種公司托管的分支變體,而不僅僅是 GitHub。 它還允許我們在GitHub 上使用多個登錄名:見下文。
現在,在運行ssh -T git@github.com
你可以得到一個權限被拒絕的錯誤,這意味着你沒有在github.com嘗試了工作,或者你可以得到這樣的輸出鍵:
Hi M! You've successfully authenticated, but but GitHub does not provide shell access.
(在這里,我們向 GitHub 證明了自己是 James Bond 間諜部門負責人 M 的身份。)
現在,如果 M 有權訪問(讀取和寫入)存儲庫,我們將能夠讀取和寫入存儲庫。 但也許 M 只有讀訪問權限,而實際上Q擁有寫訪問權限。 我們偷了 M 和 Q 的鑰匙,但是我們如何以 Q 的身份進入?
在我們開始之前,讓我們看看如果這種身份驗證完全失敗該怎么辦。 我們的下一步是運行:
ssh -Tv git@github.com
這會產生大量輸出,所有輸出都以debug1
為前綴。 這里可能有一些關於出了什么問題的線索。 如果沒有,我們可以使用ssh -Tvv
或ssh -Tvvv
獲得更多調試輸出,前綴為debug2
和debug3
。 在查看所有這些輸出時,這里通常的懷疑是確保 ssh 正在查看正確的.ssh/*
文件,其中存儲了您的 ssh 密鑰。 確保:
如果沒有,請尋找特定於操作系統的方法來為 ssh 提供正確的權限和/或路徑。
由於邪惡間諜闖入 MI-5 記錄,我們已經泄露了 M 和 Q 的密鑰,現在我們希望將我們的特洛伊木馬插入系統,以便我們可以對詹姆斯邦德進行過度精心設計的死亡。 但是,這對以后:現在,我們正在在為M,但我們需要得到盡可能問:我們該怎么辦?
為了以Q而不是M 的身份進入 GitHub,我們需要正確配置 ssh 。 原因很簡單:僅僅在.ssh
目錄中列出我們所有的密鑰是行不通的。 ssh 以某種順序嘗試它們,很明顯,我們的 ssh 首先嘗試我們的M密鑰。 一旦它起作用,它就會進入,並且 ssh 停止嘗試進一步的密鑰。
我們需要先讓我們的 ssh 嘗試我們的Q密鑰。 我們可以消除我們的M鍵,但這是煩人:現在我們可以種植我們的木馬,但我們無法找到邦德的電流分配,這是只有通過M.可讀,我們想什么有一種方法來挑我們將嘗試哪個鍵。
這是.ssh/config
文件的來源:
Host as-q
Hostname github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/stolen-q-key
Host as-m
Hostname github.com
User git
IdentitiesOnly yes
IdentityFile ~/.ssh/stolen-m-key
現在我們可以將我們的兩個存儲庫列為ssh://as-m/mi5/bond-assignments.git
和ssh://as-q/mi5/spy-devices.git
或as-m:mi5/bond-assignments.git
ssh://as-q/mi5/spy-devices.git
as-m:mi5/bond-assignments.git
和as-q:mi5/spy-devices.git
。
當我們ssh as-q
,我們將 ssh 連接到 github.com ( Hostname
),使用git
作為用戶名,並使用偷來的 Q 密鑰作為密鑰。 當我們ssh as-m
,我們將連接到同一台主機並使用同一用戶,但這次使用被盜的M密鑰。
您遇到了另一個問題:
如果系統 ssh 工作正常,告訴 Git 使用系統 ssh,例如, git config --global core.sshCommand ssh
。 如果它不夠用,請使用捆綁的 ssh(但是你上面的測試是如何工作的?)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.