简体   繁体   中英

How to run sudo su with paramiko?

I'd like to execute commands by root user. Firstly, I need to execute the command "sudo su" and after executing other commands such as docker pull, git clone, etc in particular session. I want to figure out the most efficient way to do it by using paramiko.

I realize that it's not ideal, but if you have a chain of commands to execute through sudo you may run them as sudo bash -c "command1; command2" :

In [11]: stdin, stdout, stderr = client.exec_command('sudo bash -c "id; id"')

In [12]: stdout.read().splitlines()
Out[12]:
[b'uid=0(root) gid=0(root) groups=0(root)',
 b'uid=0(root) gid=0(root) groups=0(root)']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM