Running an SFTP operation as a different user via Python Paramiko

别来无恙 提交于 2019-12-01 13:30:34

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

The correct solution is to login directly with the account you need to use.


Anyway, open_sftp_client and exec_command run on two different SSH channels. So your code cannot work, as the sftp operates on non-elevated session, that's not affected by the exec_command at all.

There's no explicit support for running SFTP with su in Paramiko (as that approach is wrong and hardly standardized).

You would have to implement an alternative to SFTPClient.from_transport that will call your exec_command instead of invoke_subsystem.

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