Ubuntu: User in sudo group cannot perform sudo operations



Question:

Using Ubuntu 14.04 on AWS and Ansible 1.9 and getting the following permission error:

$ whoami  >> ubuntu  $ mkdir -p $HOME/.ansible/tmp/testfolder  >> mkdir: cannot create directory ‘/home/ubuntu/.ansible/tmp/testfolder’: Permission denied  $  $ # this works!!  $ sudo mkdir -p $HOME/.ansible/tmp/testfolder  $ # this also works!! (maybe ubuntu doesn't have sudo privileges...)  $ sudo rm -rf $HOME/.ansible/tmp/testfolder  $  $ # ???  $ sudo adduser ubuntu sudo  >> The user `ubuntu' is already a member of `sudo'.  

If ubuntu belongs to the sudo group, how come I can't create that directory whereas sudo can? How can I really give ubuntu the privileges of sudo?

Edit: for reference,

$ ls -ld /home/ubuntu/.ansible/  >> drwxr-xr-x 4 root root 4096 Sep  8 00:20 /home/ubuntu/.ansible/  


Solution:1

I think you are not clear about what group sudo represents if a user is a member of it.

By default, if a user is a member of group sudo, that user can run commands as root by impersonating root as :

sudo some command  

There is a line in the /etc/sudoers file that makes this possible :

%sudo   ALL=(ALL:ALL) ALL  

Again becomming a member of group sudo does not make you root or does not give permission to run commands only runnable by root on the fly. You always need to use sudo before that command. So if a user is not a member of group sudo that user won't be able to run any command as root even with using sudo.

In your case, as you were running :

mkdir -p $HOME/.ansible/tmp/testfolder  

you will get permission denied message as the directory /home/ubuntu/.ansible is owned by root and there is no permission for others to write on it.

On the other hand while you were using :

sudo mkdir -p $HOME/.ansible/tmp/testfolder  

you were impersonating root who has the permission to write on that directory so the command was a success.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »