Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've launched an Amazon EC2 instance of Ubuntu Server 12.04 and it's all fine except, unlike with my local Ubuntu, the EC2 instance never asks for any passwords when I'm sudoing with the command line or become root. I tried

passwd
# asks for a new password, I supply one
sudo -i
# always makes me root right away
passwd
# asks for a new password, I supply one
passwd ubuntu
# asks for a new password, I supply one

(ubuntu is the default user the instance gets installed with.) So far, event after reboots, I haven't noticed any difference, it still never asks for any passwords.

It's not a biggie but I guess I've just used to how my local Ubuntu works.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

EC2 does not have an easy way to provide you with a secure password for the ubuntu user, so the default is to allow passwordless sudo after you connect securely with the ssh private key.

If you add a password to the ubuntu user, you can require it for sudo by editing /etc/sudoers.d/90-cloud-init-users and changing:

ubuntu ALL=(ALL) NOPASSWD:ALL

to:

ubuntu ALL=(ALL) ALL

This command does that edit for you (assuming an untouched, default sudoers file):

sudo perl -pi -e 's%NOPASSWD:%%' /etc/sudoers.d/90-cloud-init-users

For safety, keep a separate shell logged in as root so that you can fix the file and recover if you edit it incorrectly and break sudo.

Adding a password for sudo increases the overall security of your system.

It is still recommended that you not allow the use of a password for ssh logins. Keep that limited to ssh private keys.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.