In your configuration you allowed:
userA
to run any command as any user
userB
to run fdisk
as vinoth
fdisk
by default requires root
privileges to access the devices, you cannot run it as userA
, ie. you can run, but fdisk -l
will print no output, which is what you got.
Finally sudo
command is not transitive. When you execute a command from userB
account using sudo -u userA <command>
, the <command>
will be run using userA
credentials and the fact that userA
has settings defined in sudoers
does not apply to this command.
Using sudo -u
To allow userB
to execute command as userA
you need to put the following into sudoers
:
userB ALL=(userA) /usr/bin/whoami
then login to shell as userB
and execute:
$ sudo -u userA whoami
userA
But userA
has permissions to run whoami
(which it does). It does not for fdisk
.
Enabling fdisk
for regular users
fdisk
itself is not restricted to root
account, however it requires access to disk devices (stored in /dev
which are not accessible to regular users). To give user permission to run fdisk
you can either:
Enable sudo
for the account. Running sudo fdisk -l
effectively means fdisk
is run on root
account.
Add the account to disk
group, which will allow running fdisk -l
without sudo
, using account credentials.
userB
runfdisk
asuserA
? – terdon Feb 08 '16 at 11:01