0

I need to make a script in python that connects me with my login/pw as a sudoer.

Here is my script.

import paramiko
import sys

host = '1.0.0.0'
port = 22
username = 'login'
password = 'pw'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, port=port, username=username, password=password)


chan = ssh.get_transport().open_session()
chan.get_pty()
chan.exec_command('sudo su -l axis_0;mkdir olivier')
print(chan.recv(1024))

But the folder olivier is never created..

1
  • You seem to expect sudo; mkdir to execute mkdir under sudo but that's not what it does. It runs sudo, then when that finishes, it runs mkdir running under your regular account.
    – tripleee
    Aug 21, 2018 at 10:18

1 Answer 1

0

I changed my command to this one, and it works.

chan.exec_command('sudo -iu axis_0 sh -c "cd FOLDER;"')

Not the answer you're looking for? Browse other questions tagged or ask your own question.