【问题标题】:How to setup the git bash that I do not have to type the passpharse for ssh after reboot?如何设置 git bash 重启后我不必为 ssh 输入密码?
【发布时间】:2023-03-09 05:05:02
【问题描述】:

我已经按照 GitHub 文档为我的笔记本电脑设置了 ssh 密钥。然后我在推或拉时遇到了麻烦,因为我每次都必须写密码。所以,我关注了这个GitHub doc。将以下代码添加到我的 .bash_profile

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

现在我每次打开电脑都要写 GitHub 通行证。有什么方法可以让我不必在每次重启时都输入密码?

【问题讨论】:

  • 重新生成一个没有密码的 SSH 密钥...(也就是说,在生成过程中要求它时留空。)
  • @GenoChen 成功了!谢谢
  • @JoyKarmoker 当然,这将完全绕过您的问题。我已经相应地编辑了答案。

标签: git github git-bash windows-11


【解决方案1】:

阅读man ssh-add,可以尝试将SSH_ASKPASS设置为described here
将您的脚本中的ssh-add 替换为:

cat ~/.ssh/id_rsa | SSH_ASKPASS=~/.print_ssh_password ssh-add -

假设您已将私钥密码存储在 %USERPROFILE%\.print_ssh_password 中,这并不理想,但至少在您自己的 Windows 配置文件文件夹中受到保护。

当然,另一种方法是remove the passphrase of your current existing private key(同样不理想)。
那就不用ssh-add了。


另一个明显的选择是在生成您的私钥时首先没有密码。

您也可以删除passphrase to an existing private key

【讨论】:

    猜你喜欢
    • 2020-01-21
    • 2012-05-05
    • 2021-11-29
    • 2019-04-27
    • 2021-03-29
    • 2014-02-28
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多