0

我刚刚下载了适用于 Windows 的 Git(便携式 2.19.0.windows.1)并尝试设置 SSH 密钥。我使用 GitKraken,它已经帮助我生成了 2 个密钥。我根据Github Help在我的创建.bashrc(也尝试过.bash_profile)添加它们。如果我执行然后我可以拉。但如果直接来自 Windows cmd,则不能。它显示以下错误:%USERPROFILE%shgit pullgit pull

D:\Data\Blog (master -> origin)
λ git pull
git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我跑去ssh -vT git@gitlab.com发现我的 ssh 密钥没有被添加。似乎git.exe不会运行我的.bashrc所以即使 ssh-agent 也不会启动。这导致我的 VS Code 无法使用 git。

如何解决这个问题,以便它可以自动启动 ssh-agent 并添加 SSH 密钥?

我的.bashrc

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

# Shinoka part
add_my_ssh () {
    ssh-add /C/Users/shinoka/AppData/Roaming/.gitkraken/profiles/d6e5a8ca26e14325a4275fc33b17e16f/ssh/gitkraken_Shinoka-Yoga_github_rsa >| /dev/null
    ssh-add /C/Users/shinoka/AppData/Roaming/.gitkraken/profiles/d6e5a8ca26e14325a4275fc33b17e16f/ssh/gitkraken_Shinoka-Yoga_gitlab_rsa >| /dev/null
}
# end Shinoka part

# 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
    add_my_ssh
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    add_my_ssh
fi

unset env
4

0 回答 0