阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用 Fabric 将你的公钥传到服务器

156次阅读
没有评论

共计 726 个字符,预计需要花费 2 分钟才能阅读完成。

fabric 是部署好帮手
下面的代码实现 ssh-copy-id 的功能
批量上传你的 id_rsa.pub 到一组服务器

@task
def copy_id(file=”~/.ssh/id_rsa.pub”):
    “””fab push 公钥 ssh-copy-id”””
    put(file, “/tmp/id.pub”)
    try:
        run(“if [ ! -d ~/.ssh]; then mkdir -p ~/.ssh; fi”)
        run(“if [ ! -f ~/.ssh/authorized_keys]; then cp /tmp/id.pub ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys; fi”)
        run(“cat ~/.ssh/authorized_keys /tmp/id.pub | sort -u > /tmp/uniq.authorized_keys”)
        run(“if [ `cat ~/.ssh/authorized_keys | wc -l` -lt `cat /tmp/uniq.authorized_keys | wc -l`]; then cat /tmp/id.pub >> ~/.ssh/authorized_keys; fi”)
    finally:
        run(“rm -f /tmp/id.pub /tmp/uniq.authorized_keys”)

使用 Vagrant 和 Fabric 用于集成测试 http://www.linuxidc.com/Linux/2014-07/104113.htm

Fabric:Python 远程部署工具 http://www.linuxidc.com/Linux/2014-05/101616.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计726字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中