26 lines
661 B
Python
26 lines
661 B
Python
|
from paramiko import SSHClient,AutoAddPolicy
|
||
|
from getpass import getpass
|
||
|
|
||
|
address = input("Machine address: ")
|
||
|
username = input("SSH user: ")
|
||
|
password = getpass()
|
||
|
|
||
|
print("Connecting to", address, "as", username, "...")
|
||
|
client = SSHClient()
|
||
|
client.set_missing_host_key_policy(AutoAddPolicy())
|
||
|
|
||
|
client.connect(address, username=username, password=password)
|
||
|
stdin, stdout, stderr = client.exec_command("su")
|
||
|
stdin.write(password + '\n')
|
||
|
stdin.write("touch /home/tanguy/testing\n")
|
||
|
stdin.write("exit\n")
|
||
|
stdin.flush()
|
||
|
print("Return", stdout.read().decode("utf8"))
|
||
|
|
||
|
ret = stdout.channel.recv_exit_status()
|
||
|
|
||
|
stdin.close()
|
||
|
stdout.close()
|
||
|
stderr.close()
|
||
|
client.close()
|