AlfaZulu
AlfaZulu

Reputation: 931

Amazon EC2 - Prompted for Password when Switching to Passwordless User

Some background ...

I've just started using Amazon EC2 and I have a question regarding users and passwords.

As you surely well know, the default user (which in the case of Ubuntu Server 12.04 LTS is named ubuntu) doesn't have a password but instead uses public-private key authentication to login.

For reference, here's the contents of my /etc/sudoers.d/90-cloudimg-ubuntu file:

# ubuntu user is default user in cloud-images. # It needs passwordless sudo functionality. ubuntu ALL=(ALL) NOPASSWD:ALL

My question ...

I've since created a second user named jdoe who is a member of the admin group. The user jdoe has a password as well as a public-private key pair.

When logged in as jdoe I try to switch to the default ubuntu user using the following command, but I'm unexpectedly prompted for a password. How come? The user ubuntu (afaik) doesn't have a password!

jdoe@host:~$ su ubuntu Password:

Thanks in advance for your help and comments!

Upvotes: 0

Views: 1897

Answers (1)

slayedbylucifer
slayedbylucifer

Reputation: 23512

su and sudo are 2 different things and you're getting confused.

When you login as ubuntu and run any command using sudo, it will not ask for password because of ubuntu ALL=(ALL) NOPASSWD:ALL

Now jdoe is a part of admin group but admin groups needs to provide password as per %admin ALL=(ALL) ALL. This statement is found by running visudo. Please note that this statement does not have NOPASSWD:ALL

So when user jdoe runs any command as sudo, he has to enter the password

Now, su is entirely different aspect thansudo. And when you run su ubuntu, there is no sudo thing in picture. So it will ask you for the password of user ubuntu.

In otehrwords, the statement jdoe@host:~$ su ubuntu is asking you to enter the password of user ubuntu. As you do not have password for ubuntu set, this will never succeed.

However, if you login as ubuntu and try sudo su jdoe, it will not ask for any a pssword. But.... if you login as ubuntu and run su jdoe, it will ask you for the password of user jdoe. Try this so you get better understanding around how it works.

Upvotes: 1

Related Questions