首页 > 解决方案 > Git:VS Code 中的克隆返回“权限被拒绝,请重试” - 终端中的 git clone 有效

问题描述

Git: Clone在 Mac 上的 Visual Studio Code 中返回Permission denied, please try again. 从 Visual Studio Code 中的终端,它可以执行git clone.

在 Mac 上的 Visual Studio Code 中,我执行以下操作:

  1. 我愿意Git: Clone
  2. 我输入以下格式的 ssh 存储库 URL:ssh://<username>@<repository-host>/<path>/<rep>.git

  3. 我“选择存储库位置”文件夹,并得到以下对话框:

Git失败时的对话框

此功能从不要求我输入任何密码!

如果我打开 Git 日志,输出是这样的:

> git clone <ssh-repository-URL> <path>
Cloning into '<path>'...
Permission denied, please try again.
Permission denied, please try again.
Received disconnect from <IP> port 22:2: Too many authentication failures for <username>
Disconnected from <IP> port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

在终端它工作:

mac:rep username$ git clone 
Cloning into '<repository>'… <ssh-repository-URL>
The authenticity of host ‘&lt;repository-host> (<repository-ip>)' can't be established.
ECDSA key fingerprint is SHA256:<fingerprint>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<repository-host>,<repository-ip>' (ECDSA) to the list of known hosts.
Password:
remote: ...
remote: ...
remote: …
Receiving objects: 100% (.../...), ... | ... MiB/s, done.
Resolving deltas: 100% (.../...), done.

Git: Clone关于为什么Visual Studio Code 从不询问服务器密码的任何线索?

标签: gitmacosvisual-studio-code

解决方案


在设置存储库 URL 并选择目标文件夹后,底层功能Git: Clone似乎与用户没有任何交互。

要让 ssh-repository 与 Visual Studio Code 一起使用,您需要执行以下操作:

  1. 打开终端
  2. 运行ssh-keygen生成 ssh 密钥对
  3. ssh-copy-id -i ~/.ssh/id_rsa <username>@<repository-host>

源自this question和this answer

VS Code 版本控制用户指南在常见问题下有以下问题/答案:

我可以在 VS Code 中使用 SSH Git 身份验证吗? 是的,尽管 VS Code 最容易使用没有密码的 SSH 密钥。如果您有带有密码的 SSH 密钥,则需要从 Git Bash 提示符启动 VS Code 以继承其 SSH 环境。


推荐阅读