【问题标题】:ssh-agent isn't loaded when i run command locally当我在本地运行命令时未加载 ssh-agent
【发布时间】:2020-12-05 02:28:35
【问题描述】:

我想将一个应用从我的 Mac 部署到我的 ubutun 18.04 服务器。问题是当我去我的服务器并执行一个简单的命令时,比如 ssh -T git@bitbucket.org 一切正常。它不问我的密码等... 但是当我运行命令时

ssh deploy@ipofmyserver 'ssh -T git@bitbucket.org'

我遇到了这个错误:

git@bitbucket.org:权限被拒绝(公钥)。

我的 ssh 密钥已生成并在我的 bitbucket 帐户中得到很好的通知。

我注意到当我使用 ssh deploy@... 连接时,用户代理没有启动。当我运行命令时

ssh deploy@... 'eval `ssh-agent -s` && ssh-add && ssh -T git@bitbucket.org'

它询问我的密码,我得到了可以连接的响应。 我尝试使用此解决方案来使用已运行的用户代理:https://github.com/wwalker/ssh-find-agent,但它不起作用。

有什么办法吗?

【问题讨论】:

  • ssh -J deploy@ipfmyserver git@bitbucket.org 会更简单。

标签: ubuntu ssh ubuntu-18.04


【解决方案1】:

我尝试使用此解决方案来使用已运行的用户代理:https://github.com/wwalker/ssh-find-agent,但它不起作用。

如文档所述,如果您尝试在~/.bashrc~./.zshrc 中使用. ssh-find-agent.sh,那将不起作用。

您的问题的核心(ssh 内的 ssh)是 [ssh 会话将显示为:

  • ~/.bash_profile 在交互式会话中(不是 .bashrc
  • 非交互式会话中没有任何内容 (ssh user@server 'a command')

您至少应该获取您的 .bashrc_profile)以触发 . ssh-find-agent.sh 并查看它是否找到您的 ssh 代理(已在运行,已输入密码)

如果您必须输入密码,您可能需要expect,如end of this answer 所示。

OP jean-max 确认in the comments 采购.profile不是.bash_profile)足以使. ssh-find-agent.sh 工作。


chepner 提到 in the commentsssh -J "jump host" option,这里是动态的:

ssh -J deploy@ipfmyserver git@bitbucket.org 

【讨论】:

  • 感谢您的帮助。我在 .bashrc 中获取了源代码来触发 .ssh-find-agent.sh 并且它不起作用,但是当我在 .profile 中获取源代码时它起作用了。谢谢你的时间:)
  • @jean-max 我已将您的评论包含在答案中以提高知名度。
猜你喜欢
  • 2011-05-31
  • 2019-09-02
  • 1970-01-01
  • 2022-12-15
  • 2016-11-15
  • 2020-01-02
  • 2012-08-24
  • 1970-01-01
  • 2021-12-26
相关资源
最近更新 更多