diff --git a/cloudtask/ssh.py b/cloudtask/ssh.py index cf50bbc..288b8f3 100644 --- a/cloudtask/ssh.py +++ b/cloudtask/ssh.py @@ -16,6 +16,7 @@ from temp import TempFile import executil import hashlib +from pipes import quote class PrivateKey: class Error(Exception): @@ -134,12 +135,11 @@ def copy_id(self, key): if not isinstance(key, PrivateKey): key = PrivateKey(key) - command = 'mkdir -p $HOME/.ssh; cat >> $HOME/.ssh/authorized_keys' + authorized_key = "%s %s" % (key.public, key.fingerprint) + command = ("mkdir -p $HOME/.ssh; printf '%%s\\n' %s " + ">> $HOME/.ssh/authorized_keys") % quote(authorized_key) command = self.command(command) - command.tochild.write("%s %s\n" % (key.public, key.fingerprint)) - command.tochild.close() - try: command.close() except command.Error, e: