Distribute SSH Pubkey to Multiple Hosts with Fabric

  1. Generate ssh keys on source host with ssh-keygen;

  2. Disable known_hosts prompt(optional): add "StrictHostKeyChecking no" into ~/.ssh/config;

  3. Run fabric script to distribute pubkey, you have to input password manually: fab distkey;

$ cat fabfile.py

from fabric.api import local, task

env.hosts = ['10.0.2.48', '10.0.2.49', '10.0.7.141', '10.0.7.142', '10.0.7.143']

@task

def distkey():

env.user = 'gcp'

local('ssh-copy-id %(user)s@%(host)s' % env)

You have to input password for every host. So try to use uniform password for all hosts. It will save you lots of times.

posted on 2014-04-02 15:53  leechau  阅读(323)  评论(0编辑  收藏  举报

导航