OpenVZ Forum


Home » Mailing lists » Users » "permission denied" error on CT rc.local script to add custom commands by regular
"permission denied" error on CT rc.local script to add custom commands by regular [message #42989] Sat, 25 June 2011 16:56 Go to next message
knawnd is currently offline  knawnd
Messages: 27
Registered: April 2011
Junior Member
Hi!

I need to add in script some custom commands into /etc/rc.local file
located in CT filesystem in order to execute them on CT start up. It
needs to be done under regular user with full root rights granted via
sudo. But "permission denied" error appears.

$ sudo echo "# oneadmin test" >> /vz/private/164/etc/rc.d/rc.local
-bash: /vz/private/164/etc/rc.d/rc.local: Permission denied

$ grep -v ^# /etc/sudoers|grep -v ^$
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE
LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME
LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE
LINGUAS \
_XKB_CHARSET XAUTHORITY"
root ALL=(ALL) ALL
%cloud ALL=(ALL) NOPASSWD: ALL

$ id
uid=9000(oneadmin) gid=9001(cloud) groups=9001(cloud)

$ sudo id
uid=0(root) gid=0(root)
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(whe el)

$ sudo ls -al /vz/private/164/etc/rc.d/rc.local
-rwxr-xr-x 1 root root 227 Jun 25 20:17 /vz/private/164/etc/rc.d/rc.local

Whereas the same command (i.e. echo "# oneadmin test" >>
/vz/private/164/etc/rc.d/rc.local) is performed normally under superuser.

CT is based on Scientific Linux 5 template. Hardware node is running
under CentOS 5.6.

Does someone have any ideas what can be the reason of insufficient
privileges for regular user with full root rights granted via sudo?

Thanks in advance,
Nikolay.
Re: "permission denied" error on CT rc.local script to add custom commands by reg [message #42990 is a reply to message #42989] Sat, 25 June 2011 17:14 Go to previous messageGo to next message
Sharp is currently offline  Sharp
Messages: 14
Registered: March 2011
Junior Member
On Sat, Jun 25, 2011 at 8:56 PM, <knawnd@gmail.com> wrote:
> $ sudo echo "# oneadmin test" >> /vz/private/164/etc/rc.d/rc.local
> -bash: /vz/private/164/etc/rc.d/rc.local: Permission denied
>
> Does someone have any ideas what can be the reason of insufficient
> privileges for regular user with full root rights granted via sudo?

That's simple. Your echo command is running as root because of sudo.
But the shell that's redirecting echo's output is still running as
you.

You can become a root and do that command without any problems.
Re: &quot;permission denied&quot; error on CT rc.local script to add custom commands by reg [message #42991 is a reply to message #42990] Sat, 25 June 2011 17:56 Go to previous message
knawnd is currently offline  knawnd
Messages: 27
Registered: April 2011
Junior Member
Sharp wrote on 25/06/11 21:14:
> On Sat, Jun 25, 2011 at 8:56 PM,<knawnd@gmail.com> wrote:
>> $ sudo echo "# oneadmin test">> /vz/private/164/etc/rc.d/rc.local
>> -bash: /vz/private/164/etc/rc.d/rc.local: Permission denied
>>
>> Does someone have any ideas what can be the reason of insufficient
>> privileges for regular user with full root rights granted via sudo?
>
> That's simple. Your echo command is running as root because of sudo.
> But the shell that's redirecting echo's output is still running as
> you.
>
> You can become a root and do that command without any problems.
Thanks for quick reply!

I need to do that in a script. I found the solution:
$ sudo bash -c 'echo "# oneadmin test 2" >> /vz/private/164/etc/rc.local'

Regards,
Nikolay.
Previous Topic: vzdev-3.3.13-1.4.swsoft
Next Topic: Strange mount problem
Goto Forum:
  


Current Time: Tue Apr 30 15:21:38 GMT 2024

Total time taken to generate the page: 0.01711 seconds