简体   繁体   English

如何在ssh远程命令期间对sudo su

[英]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: 问题如下:

  1. The box I am on (the Jump Box) cannot sudo into root and then execute ssh. 我所在的框(跳转框)无法将sudo转换为root,然后执行ssh。 (I know, weird) (我知道,很奇怪)
  2. The box I am on has UserA, which is on all servers. 我所在的框中有UserA,它在所有服务器上。 UserA is on the list of sudoers in which I can execute sudo su - manually on each box. UserA在sudoers列表中,在其中我可以在每个框中手动执行sudo su - (I want to automate this. (我想使它自动化。
  3. /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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM