从窗口运行bash脚本作为sudo从没有交互

我需要在远程Linux机器上执行一个bash脚本,作为sudo在Windows机器上运行的TeamCity。 我可以使用plink从cmd行执行脚本,但是系统提示input密码。 我需要能够做到这一点,而不需要提示input密码才能从teamcity执行。

我有什么select?

您需要编辑要运行该脚本的主机上的sudoconfiguration。 以root身份运行visudo ,并添加一行:

USERNAME ALL=(ALL) NOPASSWD: ALL

USERNAMEreplace为要运行该脚本的用户。 这应该使用户能够使用sudo而不必input密码。 你可能想限制sudo的使用到你实际需要的命令上。 通过使用visudo来看看这些sudoers如何实现这一点。

如果两个系统都是安全的,你可以使用这样的东西:

 echo 'sudo_password' | sudo -S command 

这个选项必须谨慎使用,因为它清楚地使用了密码,而其他login到该机器的用户可能会看到它。

一种select是只允许ssh直接访问机器的root帐户。 你应该用一个私钥来locking这个密钥,并且可能用密码保护这个密钥。 向你的sshd_config添加如下内容:

 PermitRootLogin yes Match User root PasswordAuthentication no 

如果你走这条路线,可以通过在〜root / authorized_hosts文件中joincommand=""来使这个键运行特定的命令脚本,

 command="/root/myscript" ssh-rsa AAAB3NzaC1yc2EAAAABIwAAADV4//KSz...