Is it possible to shutdown remote Computers without inputing the password?
I used the following bash to shutdown remote computers,but for each computer,I must input the password for it.Is it possible to input the password Automatically?
#!/bin/bash
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
ssh -t [email protected] "sudo poweroff"
You don't need to. Since you are logging on as root
there is absolutely no reason to use sudo
, just run poweroff
or (better) shutdown -h
directly.
If for some reason not explained in your question you really do need sudo
, use sudo
's -S
option. From man sudo
:
-S The -S (stdin) option causes sudo to read
the password from the standard input
instead of the terminal device. The
password must be followed by a newline
character.
For example:
#!/bin/bash
ssh -t [email protected] "echo PASSWORD1 | sudo -S poweroff"
ssh -t [email protected] "echo PASSWORD2 | sudo -S poweroff"
To avoid password entering use ssh-keygen for authentication key creation and upload public key to all your servers.
BTW, terdon right, if you root do not use sudo
.
ssh [email protected] poweroff
ssh [email protected] poweroff