When I create new Ubuntu 12.10 instances, I typically bootstrap them by manually SSHing onto the machine and editing the sudoers to put a NOPASSWD on the default user (e.g., ec2-user, azureuser, etc.). Then my install scripts can sudo various commands without having to provide a password.
I don't have anything against passwords. It's just that when I try to do a password-based sudo over SSH using a bash script, sudo complains that there's no tty ("sudo: no tty present and no askpass program specified").
Also, I need this to be completely automated--it shouldn't require somebody to type in a password manually.
Few questions:
1) Is the approach here on the right track? In particular, is using NOPASSWD here a bad idea? I'm assuming that safeguarding the default user's SSH private key is fine here--just treat this account as a root account essentially.
2) If this is wrong, then how do I overcome the "no tty present" objection without having to manually enter passwords?
3) If NOPASSWD is OK, then how should I automate the sudoers edit? It seems that I need to use a password if only to sudo the visudo command.
I guess I could do all the work manually and then create a new image, but I'd rather just keep the base image and then script this stuff on if that's possible.