Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要编写一个 python 脚本,它必须能够连接到远程服务器(到 user1),执行一些命令(这很容易),然后它必须通过 sudo su - user2 切换到 user2,并执行一些命令(问题在这儿)。如何在不询问我密码的情况下切换到 user2(我可以将密码放在脚本中的某个位置),并以 user2 身份执行命令。
谢谢,
尝试-S(大写“S”)。引用 sudo 手册页:
-S
-S The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.