自动化生成部署github上
问题描述:
关键我执行以下命令的一天几次:自动化生成部署github上
ssh-keygen -t rsa -N "" -C "[email protected]" -f ~/.ssh/id_rsa_projectname
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa_projectname
cat ~/.ssh/id_rsa_projectname.pub
ssh -T [email protected]
在该脚本的唯一的变量是projectname
,我想作一个keygen.sh
脚本或者类似的东西自动执行此过程并传递projectname
。这可能吗?
而且我应该在哪里开始寻找,什么不能忘了,我是一个有点新的bash脚本,我知道它可以在不法分子手中相当危险的。
答
难道不容易,只需维护一个集转移或发展的关键,而不是生成它们的一切?恕我直言,你失去了可配置性,并没有获得太多的安全性。
一边,你就是那个在正确的轨道上,但我会做的事情有点不同。
export PROJECT=foo;
ssh-keygen -t rsa -N "" -C "[email protected]" -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
您需要将公钥上传到github。你必须弄清楚自己使用他们的API。
如果你做这一切正常,你应该能够,自动将克隆的git。
#!/bin/bash
[[ -z "${PROJECT}" ]] && echo "project must be set" && exit 1
ssh-keygen -t rsa -N "" -C "[email protected]" -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
您每天都会多次生成部署密钥?为什么? – Chris
@Chris每天两到三次,我从Github克隆一个新的回购到一个新的分期或开发环境。 – RTB