[英]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.