昨天我創建了一個 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 [email protected]
name = 12345doug
[includeIf "gitdir:/home/doug/Documents/Projects/Zen/"]
path = ~/.git-zen
/.git-zen 看起來像這樣:
[user]
email = [email protected]
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
[email protected]
為了創建我的 ssh 密鑰,我關注了 github.com 上的這篇文章。
ssh-keygen -t rsa -b 4096 -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
I then added the key per this tutorial to my work github settings.
So far I think I have everything set up as it should? But when I try to push from within this 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.
In desperation I renamed the repo and attempted to clone from fresh:
git clone [email protected]: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
On the repo itself, if I go into repo settings > manage access I can see myself, doug-work has admin access rights.
How can I clone and push to the repo? Where should I start in trying to find out why my set up of ssh keys are not working?
uj5u.com熱心網友回復:
首先,一些背景知識:在您在這里使用的 URL 中:
git clone [email protected]:...
這個問題唯一真正重要的部分是[email protected]零件。你也可以拼寫:
git clone ssh://[email protected]/...
(使用完全相同的其余文本代替...)具有完全相同的效果。
接下來,要診斷問題,您需要從命令列運行ssh:
ssh -T [email protected]
如果你的 URL 說[email protected]你想在ssh -T [email protected]這里運行,等等。也就是說,我們user@host參與并運行ssh -T user@host。這使得這項作業適用于各種公司托管的分支變體,而不僅僅是 GitHub。它還允許我們在GitHub 上使用多個登錄名:見下文。
現在,運行后ssh -T [email protected]你可能會得到一個權限被拒絕的錯誤,這意味著你在 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 [email protected]
這會產生大量輸出,所有輸出都以debug1. 這里可能有一些關于出了什么問題的線索。如果沒有,我們可以使用ssh -Tvv, 或ssh -Tvvv來獲得更多的除錯輸出,以debug2and為前綴debug3。在查看所有這些輸出時,這里通常的懷疑是確保 ssh 正在查看正確的.ssh/* 檔案,其中存盤了您的 ssh 密鑰。確保:
- ssh 有正確的路徑;
- ssh 嘗試其中的正確檔案;和
- 它實際上可以讀取這些檔案。
如果沒有,請尋找特定于作業系統的方法來為 ssh 提供正確的權限和/或路徑。
使用多個身份
由于邪惡間諜闖入 MI-5 記錄,我們已經泄露了 M 和 Q 的密鑰,現在我們希望將我們的特洛伊木馬插入系統,以便我們可以對詹姆斯邦德進行過度精心設計的死亡。但是,這對以后:現在,我們正在在為M,但我們需要得到盡可能問:應如何處理?
為了以Q而不是M 的身份進入 GitHub ,我們需要正確配置 ssh。原因很簡單:僅僅列出我們.ssh目錄中的所有鍵是行不通的。ssh 以某種順序嘗試它們,很明顯,我們的 ssh 首先嘗試我們的M密鑰。一旦它起作用,它就會進入,并且 ssh 停止嘗試進一步的密鑰。
We need to have our ssh try our Q key first. We could remove our key for M, but that is annoying: now we can plant our Trojan horse, but we can't find Bond's current assignment, which is only readable by M. What we'd like to have is a way to pick which key we'll try.
This is where the .ssh/config file comes in:
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
Now we can list our two repositories as ssh://as-m/mi5/bond-assignments.git and ssh://as-q/mi5/spy-devices.git, or as-m:mi5/bond-assignments.git and as-q:mi5/spy-devices.git. (That is, once you get this part working, you'll need to update the URLs associated with your clones. Use git remote set-url origin new-url or git config --edit or whatever your favorite way is to achieve this.)
When we ssh as-q, we'll have ssh connect to github.com (Hostname), use git as the user name, and use the stolen Q key as the key. When we ssh as-m, we'll connect to the same host and use the same user, but use the stolen M key this time.
I did all that and ssh works but Git-for-Windows still doesn't
You've run into one other problem:
- Old versions of Windows came with no, or an inadequate, ssh.
- So Git-for-Windows bundles an ssh (in the same way that it bundles a version of bash: git-bash isn't really part of Git, it's just needed to use Git, and the bundled ssh isn't part of Git either, it's just need to use Git).
- But the bundled ssh and the system ssh are different versions that use different config files.
If the system ssh works fine, tell Git to use the system ssh, e.g., git config --global core.sshCommand ssh. If it's inadequate, use the bundled ssh (but then how did your testing above work?).
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329781.html
上一篇:不需要的子模塊推送到GitHub
