DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

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.



Published

Mar 31, 2014

Last Updated

Mar 31, 2014

Category

Tech

Tags

  • Fabric 8
  • SSH 23

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor