0

Hello I'm new in Python,

My code :

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=ip, port=port, username=username, password=password,
               timeout=timeOut, key_filename=os.path.join(os.path.expanduser('~'), ".ssh", sshKeyName))

for i in range(len(myYml)):
    for module, value in myYml[i].items():
        if module == "module" and value == "copy":
            print('copy exist')
            client.exec_command('sudo cp -r ./Public /var/www/public')

Machine : local (MacOS) and VM (Debian)

What I'm trying to do: I want to execute a shell command in my VM when I launch my script in my local.

Problem ? In the last line (exec_command), when I try 'touch test', it create my file in my VM BUT when I try to execute a command with 'sudo', 'cp', 'sudo touch test' nothing happen in my VM.

SS.h777
  • 87
  • 5
  • doesn't sudo would block asking for a password? – Jean-François Fabre Oct 28 '22 at 13:50
  • It didn't ask about the password and except a simple touch or ls, nothing works when I change the command to 'bash -c touch test', nothing happen but when I try with 'touch test' it works and create the file in my VM. – SS.h777 Oct 28 '22 at 13:56
  • 2
    you should try `stdin, stdout, stderr = client.exec_command('your command')` and check the return values, otherwise if it doesn't work you're totally in the dark (https://docs.paramiko.org/en/stable/api/client.html) – Jean-François Fabre Oct 28 '22 at 14:03

0 Answers0