为 github 自动生成部署密钥
Automate generating deploy key for github
我每天执行几次以下命令:
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_projectname
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa_projectname
cat ~/.ssh/id_rsa_projectname.pub
ssh -T git@github.com
这个脚本中唯一的变量是 projectname
,我想制作一个 keygen.sh
脚本或类似的东西来自动化这个过程并传递 projectname
。这可能吗?
还有我应该从哪里开始寻找以及不要忘记什么,我对 bash 脚本编写有点陌生,我知道它在错误的人手中可能会非常危险。
只维护一组暂存或开发密钥而不是为所有内容生成它们不是更容易吗?恕我直言,您正在失去可配置性并且没有获得太多安全性。
除此之外,你走在正确的轨道上,但我会做一些不同的事情。
export PROJECT=foo;
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_${PROJECT}
这将生成命名键 id_rsa_foo 和 id_rsa_foo.pub
现在您需要让您的 ssh 配置将其用于 github。 ~/.ssh/config
应该是这样的:
Host remote github.com
IdentityFile ~/.ssh/id_rsa_foo
User git
StrictHostKeyChecking no
您需要将 public 密钥上传到 github。您必须使用他们的 API.
自己解决这个问题
如果你正确地完成所有这些,你应该能够git自动克隆。
#!/bin/bash
[[ -z "${PROJECT}" ]] && echo "project must be set" && exit 1
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_${PROJECT}
chmod 400 ~/.ssh/id_rsa_${PROJECT}
echo $' Host remote github.com\n IdentityFile ~/.ssh/id_rsa_'${PROJECT}'\n User git\n StrictHostKeyChecking no' >> ~/.ssh/config
chmod 644 ~/.ssh/config
# do the github api stuff to add the pub key
我每天执行几次以下命令:
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_projectname
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa_projectname
cat ~/.ssh/id_rsa_projectname.pub
ssh -T git@github.com
这个脚本中唯一的变量是 projectname
,我想制作一个 keygen.sh
脚本或类似的东西来自动化这个过程并传递 projectname
。这可能吗?
还有我应该从哪里开始寻找以及不要忘记什么,我对 bash 脚本编写有点陌生,我知道它在错误的人手中可能会非常危险。
只维护一组暂存或开发密钥而不是为所有内容生成它们不是更容易吗?恕我直言,您正在失去可配置性并且没有获得太多安全性。
除此之外,你走在正确的轨道上,但我会做一些不同的事情。
export PROJECT=foo;
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_${PROJECT}
这将生成命名键 id_rsa_foo 和 id_rsa_foo.pub
现在您需要让您的 ssh 配置将其用于 github。 ~/.ssh/config
应该是这样的:
Host remote github.com
IdentityFile ~/.ssh/id_rsa_foo
User git
StrictHostKeyChecking no
您需要将 public 密钥上传到 github。您必须使用他们的 API.
自己解决这个问题如果你正确地完成所有这些,你应该能够git自动克隆。
#!/bin/bash
[[ -z "${PROJECT}" ]] && echo "project must be set" && exit 1
ssh-keygen -t rsa -N "" -C "info@example.com" -f ~/.ssh/id_rsa_${PROJECT}
chmod 400 ~/.ssh/id_rsa_${PROJECT}
echo $' Host remote github.com\n IdentityFile ~/.ssh/id_rsa_'${PROJECT}'\n User git\n StrictHostKeyChecking no' >> ~/.ssh/config
chmod 644 ~/.ssh/config
# do the github api stuff to add the pub key