我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
我把我的工作推到一个远程git存储库。
每次推送都会提示我输入用户名和密码。我想避免它的每一个推送,但如何配置以避免它?
当前回答
只需使用——repo选项git push命令。是这样的:
$ git push --repo https://name:password@bitbucket.org/name/repo.git
其他回答
我用了帕维尔建议的答案,它对我很有效。我的区别是这样做,而我是这样添加远程:git远程添加(别名)https://(name:password)@github.com/(the远程地址).git
我使用的是https链接(https://github.com/org/repo.git) 而不是SSH链接;
git@github.com:org/repo.git
转换为我解决了这个问题!
据我所知,只有两种安全的方法:使用密钥库加密的ssh或passwd。
SSH
Log in your github; Visit: https://github.com/settings/keys; New SSH key; cat ~/.ssh/id_rsa.pub, paste it there, name and save it (if you have no such file, generate one for yourself by ssh-keygen -t rsa - just Enter for all prompts); Go to your local repository and update your remote by git remote set-url origin git+ssh://git@github.com/username/reponame.git - you can check it first by git remote -v); Here you go, just touch t; git add t; git commit -m "test"; git push and confirm yes to enjoy the password-free world.
passwd使用密钥库加密
如果你只使用git config -global credential。如其他人所述,您未加密的密码将以纯文本形式存储在~/下。git证书听起来并不安全。
尝试将其加密为
sudo apt-get install libgnome-keyring-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring
git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
git config --global credential.helper store
在本例中,您使用https://git@github.com/username/reponame.git。
第一步-
使用以下命令在linux系统上创建SSH密钥
ssh-keygen -t rsa -b 4096 -C "your_email"
它将询问密码短语和文件名(默认为~/)。ssh / id_rsa ~ / . ssh / id_rsa . pub)
步骤2 -
一旦文件创建,添加公钥id_rsa。Pub到github帐户SSH部分。
第三步-
在您的机器上,使用以下命令将私钥id_rsa添加到ssh-agent
ssh-add ~/.ssh/id_rsa
步骤4 -
现在使用以下命令将远程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
这是它。
在我的例子中,使用SSH,在将公钥添加到GitHub之后,然后将远程设置为git@github.com/username/reponame.git之类的东西,以及在本地永久添加私钥。本地命令如下:
ssh-add
ssh-add - k
我想有些人可能忽略了后一步。