我会使用 git push
将我的工作推送到远程 Git 仓库。
每次 push
都会提示我输入用户名
和密码
。我想避免每次推送时都需要输入它们,但要如何配置才能避免呢?
我会使用 git push
将我的工作推送到远程 Git 仓库。
每次 push
都会提示我输入用户名
和密码
。我想避免每次推送时都需要输入它们,但要如何配置才能避免呢?
打开终端创建SSH密钥:
cd ~ #Your home directory
ssh-keygen -t rsa #Press enter for all values
(仅当提交程序能够使用证书/私钥和公钥时才有效)
这里是一个关于putty gen的步骤演示
此步骤因远程设置而异。
如果是GitHub仓库且您有管理权限,请转到设置并单击“添加SSH密钥”。将~/.ssh/id_rsa.pub
的内容复制到标记为“密钥”的字段中。
如果您的仓库由其他人管理,请将您的id_rsa.pub
提供给管理员。
如果您的远程仓库由您管理,您可以使用以下命令:
scp ~/.ssh/id_rsa.pub YOUR_USER@YOUR_IP:~/.ssh/authorized_keys/id_rsa.pub
如果您已完成上述步骤但仍然收到密码提示,请确保您的仓库URL的形式为
git+ssh://git@github.com/username/reponame.git
https://github.com/username/reponame.git
git remote show origin
您可以使用以下方法更改URL:
git remote set-url origin git+ssh://git@github.com/username/reponame.git
[1] 本节内容包含Eric P的答案。
git remote set-url origin git@github.com:/username/projectname.git
- Kurt运行以下命令以启用凭证缓存。
$ git config credential.helper store
$ git push https://github.com/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
使用者应该指定缓存过期时间。git config --global credential.helper 'cache --timeout 7200'
启用凭据缓存后,将缓存7200秒(2小时)。
注意:凭据助手会在本地磁盘上存储未加密的密码。
git
的手册中可以看到:“使用此助手将会在磁盘上以未加密的形式存储您的密码,仅受文件系统权限保护。” - cmaster - reinstate monicastore
凭据助手时会将密码明文存储在磁盘上。 - cmaster - reinstate monicagit config --unset credential.helper
。 - serv-incman git-credential-store
列出文件 ~/.git-credentials
和 XDG_CONFIG_HOME/git/credentials
,顺序如上。附注:“使用此助手将会在磁盘上以未加密的形式存储您的密码,仅受文件系统权限保护。” - cmaster - reinstate monicagit+ssh://git@github.com/username/reponame.git
与...相对https://github.com/username/reponame.git
要查看您的仓库URL,请运行:
git remote show origin
你可以使用 git remote set-url
来更改URL,方法如下:
git remote set-url origin git+ssh://git@github.com/username/reponame.git
git@github.com/username/reponame.git
。 - Ivan Shulev只需在git push命令中使用--repo
选项。像这样:
$ git push --repo https://name:password@bitbucket.org/name/repo.git
git remote set-url origin https://name:password@github.com/repo.git
命令将其默认设置为此。 - ACyclicname@github.com/....git
也可以,如果你不介意每次都要输入密码的话。 - timdaygit push --repo https://github.com/Username/repo
可以在不加 .git
扩展名的情况下正常工作。 - Pe Dro您可以通过git-credential-store进行操作。
git config credential.helper store
该程序在文件系统中未加密存储您的密码:
使用此助手将以未加密形式将您的密码存储在磁盘上,仅由文件系统权限进行保护。如果这不是可接受的安全折衷,请尝试使用git-credential-cache,或查找与操作系统提供的安全存储集成的助手。
请使用git-credential-cache,默认情况下会将密码存储15分钟。
git config credential.helper cache
要设置不同的超时时间,请使用--timeout
(这里是5分钟)
git config credential.helper 'cache --timeout=300'
- 如果您使用的是 Mac,Git 自带一个“osxkeychain”模式,可以将凭据缓存在附加到您系统账户的安全钥匙串中。这种方法将凭据存储在磁盘上,它们永远不会过期,但是使用与存储 HTTPS 证书和 Safari 自动填充相同的系统进行加密。在命令行上运行以下内容即可启用此功能:
git config --global credential.helper osxkeychain
。您还需要使用 Keychain 应用程序将凭据存储在 Keychain 中。- 如果您使用的是 Windows,则可以安装一个名为“Git Credential Manager for Windows”的助手。这类似于上述描述的“osxkeychain”助手,但使用 Windows 凭据存储来控制敏感信息。它可以在https://github.com/Microsoft/Git-Credential-Manager-for-Windows 上找到。[强调我的]
credential.helper cache
是无效的。正确的命令应该是 git config --global credential.helper wincred
。 - Paulo Mersonhttps://github.com/org/repo.git
)而不是ssh链接。git@github.com:org/repo.git
步骤1 -
使用以下命令在您的Linux系统上创建SSH密钥
ssh-keygen -t rsa -b 4096 -C "your_email"
步骤1 -
它会要求输入密码短语和文件名(默认为~ / .ssh / id_rsa,~ / .ssh / id_rsa.pub)。
步骤2 -
一旦创建了公钥和私钥文件,请将公钥id_rsa.pub添加到Github帐户的ssh部分。
步骤3 -
在您的计算机上,使用以下命令向ssh代理添加私钥id_rsa。
ssh-add ~/.ssh/id_rsa
第四步 -
现在使用以下命令将远程URL git@github.com:user_name/repo_name.git 添加到本地git repo中。
git remote remove origin
git remote add origin git@github.com:user_name/repo_name.git
这就是它。
在Windows操作系统上使用此命令,这对我有用:
https://{Username}:{Password}@github.com/{Username}/{repo}.git
e.g.
git clone https://{Username}:{Password}@github.com/{Username}/{repo}.git
git pull https://{Username}:{Password}@github.com/{Username}/{repo}.git
git remote add origin https://{Username}:{Password}@github.com/{Username}/{repo}.git
git push origin master
我想指出上面多次提到的解决方案中的一些问题:
git config credential.helper store
将您的git客户端连接到操作系统凭据库。例如,在Windows中,您可以将凭据助手绑定到wincred:
git config --global credential.helper wincred
在 GitHub 使用 https:// 时,是否有跳过输入密码的方法?