【问题标题】:Automate Git clone from Private repo using SSH使用 SSH 从私有仓库自动克隆 Git
【发布时间】:2020-06-23 13:29:18
【问题描述】:

我一直在编写 bash 脚本来使用 SSH 克隆私有 Github 存储库。 需要遵循的步骤 -

  1. 使用 ssh-keygen -t rsa -b 4096 -C "your email" 生成 SSH 密钥。
  2. 复制 cat ~/.ssh/id_rsa.pub 的输出
  3. 将其存储在 - https://github.com/settings/keys

如何在 bash 脚本中自动执行第 3 步。 任何帮助将不胜感激。

【问题讨论】:

  • 您仍然需要对 github 进行身份验证 - 这仅适用于您自己还是所有人?
  • 这适用于所有有权访问该私有仓库的人。

标签: bash github ssh


【解决方案1】:

您需要使用 GitHub API POST /user/keys 将公共 SSH 密钥添加到经过身份验证的用户的 GitHub 帐户。

它要求您通过基本身份验证或至少具有 write:public_key 范围的 OAuth 进行身份验证。

所以你的脚本必须作为参数。

结果:example

# Add a SSH-Key (type "user:passwd ^D"), output: JSON object, or JSON error
curl -X POST -u <user[:passwd]> https://api.github.com/user/keys \
  --data "{\"title\": \"<title>\", \"key\": \"$(cat $HOME/.ssh/id_rsa.pub)\"}"

(other example here)

【讨论】:

猜你喜欢
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-11
  • 2012-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多