The 'root' in the /etc/sudoers should be the ID of the user executing the commands.... In your example, this would be 'ubuntu' I believe.
You example does this:
- logs into $machine as root (I assuming that you've set that machine to be able to logon as root. If not, you need to adjust your pam.d settings to allow root logins via ssh. This has nothing to do with sudo).
- As root@#machine, your command ssh's to ubuntu@address and executes the command 'sudo service cassandra start'.
It looks by your example that you need to enable sudo for ubuntu and not root to be able to execute service commands.
Example:
# User privilege specification
ubuntu ALL=(root) NOPASSWD: /usr/bin/service cassandra *
EDIT: I am really confused as to what you are trying to accomplish. If you are simply trying to ssh to another server and run that service command, all that is required is this in your shell script:
Your command would look like this:
sshpass -p 'ubuntu' ssh -t ubuntu@$address -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/nul -x 'sudo service cassandra start'
Also, you still need to add my edits to /etc/sudoers per above to allow 'ubuntu' to execute that command.
i think the topic isnt so clear, can you edit it?. – Francisco Tapia – 2015-04-29T17:41:20.637
some hint: avoid editing
– Slizzered – 2015-04-30T18:42:55.723/etc/sudoers
directly using vim. If you make a mistake, yoursudo
might be broken. It is better to use thevisudo
command. It will also edit your/etc/sudoers
file, but it will do some additional syntax-checking before you can exit the program (see)