How do I make my python script login to a server thrugh ssh using a private key and then create a user using the given password? I tried this code but I am not able to go further like sending a "sudo adduser username"
and "sudo adduser username groupname"...
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "sudo adduser myuser" ]
for command in commands:
print "Executing {}".format( command )
stdin , stdout, stderr = c.exec_command(command)
print stdout.read()
print( "Errors")
print stderr.read()
c.close()
Please advise me or I would really appreciate if someone could be kind enough to help me with a working example.
Thanks