I want to execute a shell script on a remote server, and the script should be run by root with no password required (or use
sudo in the script).
Can anyone give me some suggestions?
Beside solutions with
For this, you need to enable password-less login to the root user if not yet done (
You don't need to place your root password in script.
suid your script on the server , and make it read / executable only by root or your user group.
Don't forget to join your user into that group.
And you do
Create a SSH key , and copy public key to the remote server. This way you'll have to login as root , but also password-less. (Remeber to decrypt your private key with openssl)
It's very dangerous if you lost your private key.