0

I'm trying to iterate sudo poweroff through all ip addresses in my network using for loop. All computers in the network have the same password.

sshpass -p password ssh $ip sudo poweroff

The problem is sudo poweroff prompts for the password. I somehow need to send password using the script, but I'm not able to figure out how.

I want to accomplish this without editing sudoers file.

Update:

This did the job

sshpass -p password ssh $ip 'DISPLAY=:0 echo password | sudo -S poweroff'

Thanks to @dan08 for helping me with -S option.

Goku
  • 23
  • 4

0 Answers0