简体   繁体   English

Git clone总是要求个人访问令牌(私人仓库)

[英]Git clone always asks for Personal Access Token (private repo)

Every time I'm trying to clone a private repo I get the prompt to add my username and password. 每次我尝试克隆私人仓库时,我都会收到添加用户名和密码的提示。

I looked around to see what's wrong, because I added my password and didn't work, and found out that I have to use the Personal Access Token. 我环顾四周看看有什么不对,因为我添加了密码并且没有用,并且发现我必须使用个人访问令牌。 Now every time I'm trying to clone a private repo I have to add that (or generate another) token. 现在,每当我尝试克隆私人仓库时,我必须添加(或生成另一个)令牌。

Is there a way to clone a private git repo without the token? 有没有办法克隆没有令牌的私人git仓库? Or at least to be able to add my password instead of that token? 或者至少能够添加我的密码而不是那个令牌?

You can clone using SSH, and authenticate using your SSH key. 您可以使用SSH进行克隆,并使用SSH密钥进行身份验证。 There is a nice guide from GitHub on how to set up git with SSH, and it works very similarly for other providers. GitHub有一个关于如何使用SSH设置git的很好的指南 ,它对其他提供程序的工作方式非常相似。 After you set it up, don't forget to clone the repo using the SSH URL (not the HTTPS one), or to change the origin of your cloned repo to the SSH URL. 设置完成后,不要忘记使用SSH URL(而不是HTTPS URL)克隆存储库,或者将克隆存储库的origin更改为SSH URL。

You can use the git credentials storage for storing your username and passwords while accessing the repository over https. 您可以使用git凭据存储来存储用户名和密码,同时通过https访问存储库。
Run

git config credential.helper store

and then 接着

git pull

This will ask your username and passwords and then remember it for future use. 这将询问您的用户名和密码,然后记住它以备将来使用。 Please note running above commands will create a file at ~/.git-credentials and store the credentials in plain text which can be a security risk. 请注意,运行上述命令将在~/.git-credentials创建一个文件,并以明文形式存储凭据,这可能存在安全风险。 An alternative is to store the credentials in memory rather than the disk. 另一种方法是将凭证存储在内存而不是磁盘中。 To do this you can run the below command. 为此,您可以运行以下命令。

git config credential.helper 'cache --timeout=3600'

This way git will not any files on disk and use the memory for storing the credentials. 这样git就不会在磁盘上有任何文件,而是使用内存来存储凭证。 the timeout argument here is used to specify that the credentials should be cached for next 1 hour. 此处的timeout参数用于指定应在接下来的1小时内缓存凭据。

SOLUTION

This is how I managed to make it work. 这就是我设法让它发挥作用的方式。

Opened a new terminal and add 打开一个新终端并添加

ssh-keygen -t rsa -b 4096 -C "[github email address]"

The following showed in the terminal 以下显示在终端中

Generating public/private rsa key pair. [press Enter] Enter file in which to save the key (/home/${USER}/.ssh/id_rsa): Enter passphrase (empty for no passphrase): [press Enter] Enter same passphrase again: [press Enter]

Then 然后

cd /.ssh ls [you should see 3 files] cat [file].pub

Copy the content then go to your Github profile settings -> SSH and GPG keys -> New SSH key -> paste the content from [file].pub there. 复制内容然后转到您的Github配置文件设置 - > SSH和GPG密钥 - >新SSH密钥 - >粘贴[file] .pub中的内容。 After doing this I can clone the github repo with SSH without the need to add the token. 执行此操作后,我可以使用SSH克隆github仓库,而无需添加令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用个人访问令牌 Netbeans 克隆私有 Github 回购 - Clone a Private Github Repo with a Personal Access Token Netbeans 从私有 Git 存储库安装 Pip,在 Git URL 中使用个人访问令牌 - Pip install from private Git repo, with Personal access token in Git URL 如何使用默认的git clone语句代替个人访问令牌? - How to use default git clone statement instead of personal access token? 带有个人访问令牌的 Jenkins 中的 Git Clone 永远闲置 - Git Clone in Jenkins with Personal Access Token idles forever 使用 TFS 个人访问令牌克隆 Git Repo - Cloning Git Repo using TFS Personal Access Token 使用 dockerfile 克隆私有 git 存储库 - Clone private git repo with dockerfile 如何用我的个人访问令牌替换我的旧密码以克隆、拉取和推送存储库? - how to replace my old password with my Personal access token to clone, pull, and push a repo? 个人访问令牌 in.git 配置 - Personal Access Token in .git config Pip 使用 Gitlab-CI 上的个人访问令牌从 Gitlab 安装私有仓库 - Pip install a private repo from Gitlab with Personal Access Token on Gitlab-CI Pod Install 无权访问私有 repo,但 git clone 等在同一个 repo 上工作 - Pod Install doesn't have access to private repo but git clone, etc. work on the same repo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM