arcee123
arcee123

Reputation: 243

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:

grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin

I am doing this using the ssh command like this:

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. (I know, weird)
  2. The box I am on has UserA, which is on all servers. UserA is on the list of sudoers in which I can execute sudo su - manually on each box. (I want to automate this.
  3. /sbin/sulogin is a root only file. 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?

Thanks.

Upvotes: 0

Views: 2532

Answers (1)

nomad
nomad

Reputation: 983

Try this. user has to be part of sudoers.

ssh -t user@hostname 'sudo grep "sulogin" /etc/inittab ~:S:wait:/sbin/sulogin'

Upvotes: 1

Related Questions