[英]how to sudo su during ssh remote command
I am writing a bash script to scan multiple linux machines for a line to see if it meets standards for the organization: 我正在编写一个bash脚本来扫描多台linux机器的一行,以查看它是否符合组织的标准:
grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin
I am doing this using the ssh command like this: 我正在使用ssh命令执行此操作,如下所示:
ssh -q <<HOSTNAME>> grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin
the problem is as follows: 问题如下:
sudo su -
manually on each box. UserA在sudoers列表中,在其中我可以在每个框中手动执行sudo su -
。 (I want to automate this. (我想使它自动化。 /sbin/sulogin
is a root only file. /sbin/sulogin
是仅根文件。 and cannot see the file under any other user. 并且看不到任何其他用户的文件。 how do I include sudo su -
into the ssh command to ssh into the server, then sudo su -
, then scan the file I need? 如何将sudo su -
放入ssh命令以ssh进入服务器,然后sudo su -
,然后扫描所需的文件?
Thanks. 谢谢。
Try this. 尝试这个。 user has to be part of sudoers. 用户必须是sudoers的一部分。
ssh -t user@hostname 'sudo grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.