Amazon EC2 prompt password when sudo

When I log into an ec2 instance via ssh using keypair (logged in as ec2-user user), I am able to execute sudo commands without typing a password.

How can I configure ec2 instance to prompt for a password when the logged in user issues a sudo command?

1 Answer

Warning: Make sure to set the password for ec2-user before doing this

You need to modify the sudo settings to enable password authentication when using sudo. Run the visudo command as root (or sudo visudo) and look for a line like this:

ec2-user ALL=(ALL) NOPASSWD: ALL

Remove the NOPASSWD: bit, so the line looks like this:

ec2-user ALL=(ALL) ALL

sudo will ask for a password next time you log on. Again, make sure to set your password before doing this!

6

You Might Also Like