我刚刚开始使用git,我不能让它记住我的密码,我使用cmd.exe提升,我的git主机是github,我已经创建了一个ssh密钥,就像github上的指南
但我还是得到了
*\subnus.mvc>git push origin master
Enter passphrase for key '/c/Users/Subnus/.ssh/id_rsa':
我刚刚开始使用git,我不能让它记住我的密码,我使用cmd.exe提升,我的git主机是github,我已经创建了一个ssh密钥,就像github上的指南
但我还是得到了
*\subnus.mvc>git push origin master
Enter passphrase for key '/c/Users/Subnus/.ssh/id_rsa':
当前回答
你可以在你的用户的主目录下创建一个。bashrc文件,比如C:/Users/youruser,然后放在那里:
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
该脚本在每次bash运行后执行。因此,当git-bash启动时,您只需要输入一次密码!
某些版本的bash需要.bash_profile文件而不是.bashrc,所以以防万一克隆。bashrc:
copy .bashrc .bash_profile
其他回答
可以尝试添加-k arg当你这样做;
ssh-add -k ~/.ssh/id_rsa
如果你在Windows下使用Git bash,你可以执行以下操作:
eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa
它会在第二个命令中要求传递短语,就是这样。你需要做的每一个额外的操作(曾经需要pass phrase)都不会要求你提供pass phrase(参见下面的屏幕截图中的例子):
如果您为密钥文件设置了密码,则在连接时始终需要输入该密码。如果你创建了一个无密码密钥,那么你就不必每次都输入它,但是,任何访问你的密钥文件的人现在都可以连接到你的github帐户。
Ssh-agent也可以工作。试着运行它,看看它是否会记住你的密码。
对于任何需要更详细说明的人,请参阅本页: https://docs.github.com/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases
你可以在你的用户的主目录下创建一个。bashrc文件,比如C:/Users/youruser,然后放在那里:
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
该脚本在每次bash运行后执行。因此,当git-bash启动时,您只需要输入一次密码!
某些版本的bash需要.bash_profile文件而不是.bashrc,所以以防万一克隆。bashrc:
copy .bashrc .bash_profile