How do you start Python Paramiko SFTP with sudo?

眉间皱痕 提交于 2019-12-06 02:21:18

First, automating su or sudo is not the correct solution.

The correct solution is to setup a dedicated private key with only privileges needed for your task.


The invoke_subsystem and exec_command are generally mutually exclusive. You can use one or the other, but not both. A "subsystem" is kind of an alias to a "command". I.e. the "sftp" subsystem is typically an alias to the "/bin/sftp-server" command (thought that's a very simplified explanation).


There's no native support for executing SFTP subsystem as a different user.

So all you can do is to execute the sftp_server binary directly as a different user.

chan.exec_command('sudo su -c /bin/sftp-server')

(Assuming *nix OpenSSH server)

And you definitely cannot request PTY (get_pty) as that's incompatible with the SFTP protocol.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!