如何在zsh环境中运行ssh-agent auto?

wcc*_*526 29 linux debian zsh oh-my-zsh

我使用zsh和oh-my-zsh.当我使用github并想使用密钥上传时.

我总能找到

#git push
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

因为我还没有添加密钥

#ssh-add -l
Could not open a connection to your authentication agent.
Run Code Online (Sandbox Code Playgroud)

所以我必须启动ssh-agent并在我想要推或拉时添加密钥

#ssh-agent zsh
#ssh-add ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

如何在脚本中添加这些命令,所以我不需要输入命令?

Ila*_*mer 56

在文本编辑器中打开.zshrc:

vim ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

将ssh-agent添加到插件列表并保存:

plugins=(git ssh-agent)
Run Code Online (Sandbox Code Playgroud)

您可能需要立即重新加载.zshrc设置:

source ~/.zshrc
Run Code Online (Sandbox Code Playgroud)

  • 您可以使用:`zstyle:omz:plugins:ssh-agent identities id_rsa id_rsa2 id_github`(在此处找到:https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/ssh-agent/ SSH-agent.plugin.zsh) (4认同)
  • readme 比较清楚一点。https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/ssh-agent (3认同)
  • 不幸的是,这不适用于 powerlevel10k。 (3认同)
  • 它现在可以运行ssh-agent,但它怎么能自动"ssh-add -l"呢? (2认同)
  • 这里有一些 powerlevel10k 的细节:https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/ssh-agent#powerline-10k-specific-settings (2认同)