git问题记录

1.从http切换到ssh,github在本地pull时发生

ERROR: Repository not found.

fatal: Could not read from remote repository.

总之遇到这种问题,把key重新生成一遍在github上重新加一次。具体

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account

Generating a new SSH key

$ ssh-keygen -t ed25519 -C "your_email@example.com"

Adding your SSH key to the ssh-agent

 

  1. Start the ssh-agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566

Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file. $ ssh-add -K ~/.ssh/id_ed25519 Note: The -K option is Apple's standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent. If you chose not to add a passphrase to your key, run the command without the -K option. If you don't have Apple's standard version installed, you may receive an error. For more information on resolving this error, see "Error: ssh-add: illegal option -- K."

 

Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.

$ pbcopy < ~/.ssh/id_ed25519.pub


注意:因为我本地要上传两个github的账号,所以还必须在~/.ssh目录下增加config配置,不同key针对不同账号,把相应zjhgx.pub里面内容拷贝到github setting里的ssh and gpg keys.
  1 Host zjhgx163.github.com                                                                                                                                                                                                                            
  2     HostName github.com
  3     PreferredAuthentications publickey
  4     IdentityFile ~/.ssh/zjhgx163
  5 
  6 Host zjhgx.github.com
  7     HostName github.com
  8     PreferredAuthentications publickey
  9     IdentityFile ~/.ssh/id_ed25519

 

 2. 不知怎么回事,sshkey添加到github过两天,再git pull 发现permission denied(public key).又得

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/zjhgx

 3. 又出现了可怕的  ERROR: Permission to zjhgx163/proxy.git denied to zjhgx.

这次是zjhgx163上新建了个仓库,然后本地clone下来想提交时又出现了这个问题。我的golbal user.name 是zjhgx,但是把这个工程的local user.name改成zjhgx163

也没用。把zjhgx账户上的key给删了就好了,不知道是什么缘故。我猜是以前误操作把zjhgx163的key加到了zjhgx账户上,这样就有一个key在zjhgx,zjhgx163账户上都存在过。然后github上有个bug把以前的缓存在那里,导致虽然已经把那个key删了但还是出问题?

 

4. 如果出现“

ERROR: Repository not found.

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

需要把key重新加入到agent “ssh-add --apple-use-keychain ~/.ssh/zjhgx163

===========================

上面问题其实是两个github的account配置错误,remote url 和config配的域名不匹配

Host github.com-zjhgx163                                                                                                                                                                                                                                      
    HostName github.com
    PreferredAuthentications publickey
    AddKeysToAgent yes 
    UseKeychain yes 
    IdentityFile ~/.ssh/zjhgx163

Host github.com-zjhgx
    HostName github.com
    PreferredAuthentications publickey
    AddKeysToAgent yes 
    UseKeychain yes 
    IdentityFile ~/.ssh/id_ed25519y

 相应的,remote url应该配置成,黑体字部分要匹配

git remote set-url origin git@github.com-zjhgx:zjhgx/cheap-java.git

git remote set-url origin git@github.com-zjhgx163:zjhgx163/cheap-vue.git

 

5. 想用

brew install --cask mark-text 结果

Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-cask /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask --origin=origin` exited with 128.

得启用代理

git config --global http.proxy 'socks5://127.0.0.1:1081'
git config --global https.proxy 'socks5://127.0.0.1:1081'

安装结束后

git config --global --unset http.proxy
 
git config --global --unset https.proxy

 

 6.  ex_exchange_identification: Connection closed by remote host

   fatal: Could not read from remote repository.

最近出现这个问题,需要用https来连接ssh,把config文件改下:注意黑体字部分,

Host github.com-zjhgx163                                                                                                                                                                                                                                      
    HostName ssh.github.com
    Port 443 
    User zjhgx163
#    PreferredAuthentications publickey
#   AddKeysToAgent yes
#   UseKeychain yes
    IdentityFile ~/.ssh/zjhgx163

Host github.com-zjhgx
    HostName ssh.github.com
    User zjhgx
    Port 443 
#    PreferredAuthentications publickey
#    AddKeysToAgent yes
#    UseKeychain yes
    IdentityFile ~/.ssh/id_ed25519
~                                      

在修改前先测试一下:

To test if SSH over the HTTPS port is possible, run this SSH command:

$ ssh -T -p 443 git@ssh.github.com
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.

https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

https://github.com/orgs/community/discussions/55269

 

posted @ 2021-05-29 19:47  zjhgx  阅读(84)  评论(0编辑  收藏  举报