Skip to content

Instantly share code, notes, and snippets.

@TabTwo
Created October 25, 2010 09:45
Show Gist options
  • Save TabTwo/644691 to your computer and use it in GitHub Desktop.
Save TabTwo/644691 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
from getpass import getpass
import paramiko
def deploy_key(key, server, username, password):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server, username=username, password=password)
client.exec_command('mkdir -p ~/.ssh/')
client.exec_command('echo "%s" > ~/.ssh/authorized_keys' % key)
client.exec_command('chmod 644 ~/.ssh/authorized_keys')
client.exec_command('chmod 700 ~/.ssh/')
key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
username = os.getlogin()
password = getpass()
hosts = ["hostname1", "hostname2", "hostname3"]
for host in hosts:
deploy_key(key, host, username, password)
@nougad
Copy link

nougad commented Oct 25, 2010

emerge -vat net-misc/openssh
for I in "hosts"; do ssh-copy-id ${USER}@$I; done

@TabTwo
Copy link
Author

TabTwo commented Nov 1, 2010

nicht ganz :)

da sind noch mehr "geheime" client.exec_command im endgültigen script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment