LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2011, 01:11 PM   #1
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Rep: Reputation: 0
Edit the sudo file


I need to have regular user run this command sync; echo 3 > /proc/sys/vm/drop_caches

but it requires root privileges that I cannot give.

So I figured they could run the command as "sudo". I looked in /etc/sudoers and wasn't sure what I needed to edit for the users to run the following command

sync; echo 3 > /proc/sys/vm/drop_caches

Any wise words.....
 
Old 04-27-2011, 01:16 PM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 470Reputation: 470Reputation: 470Reputation: 470Reputation: 470
In a terminal type
Code:
man visudo
Once you are happy that you understand what needs to be done, use the command "visudo" to open the file ready for editing.
 
Old 04-27-2011, 01:35 PM   #3
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
I would add the following in your sudoers file using the visudo command.

username ALL=command/to/run
 
Old 04-27-2011, 01:36 PM   #4
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
OK -- i read and still a bit dumb. Why do I need to use visudo when I'm comfortable using vi?

I just want vi into /etc/sudoers and edit the line where the user can edit this specific area

"xx" <user> ALL=<ALL> sync; echo3 > /proc/sys/vm/drop_caches

I just need to know what line and if that is the right format?
 
Old 04-27-2011, 01:54 PM   #5
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
Quote:
Originally Posted by vintage2010 View Post
OK -- i read and still a bit dumb. Why do I need to use visudo when I'm comfortable using vi?

I just want vi into /etc/sudoers and edit the line where the user can edit this specific area

"xx" <user> ALL=<ALL> sync; echo3 > /proc/sys/vm/drop_caches

I just need to know what line and if that is the right format?

You should never edit the /etc/sudoers file directly. Using the visudo command uses vi, so you will still be very comfortable in that interface.

I would make the command you want to run into a shell script and place it in /root somewhere. make it executable and name it echo3.sh or something.

Then I would add the following line to your sudoers file (replace username with whatever user you want).

username ALL=/root/echo3.sh
 
Old 04-27-2011, 02:00 PM   #6
zjoske
LQ Newbie
 
Registered: Dec 2009
Posts: 18

Rep: Reputation: 2
Basically visudo lets you edit the /etc/sudoers file in a safe way, locking against simultanous edits, do a basic check, parse errors etc.

You can use vi too if you want. You can even echo your text into the sudoers file. Nothing against that. the visudo file is just a little safer.
 
Old 04-27-2011, 02:03 PM   #7
thinmintaddict
LQ Newbie
 
Registered: Apr 2011
Location: Austin, TX
Distribution: Arch Linux
Posts: 12

Rep: Reputation: 6
Lightbulb

certain packages, such as cron and sudo have special editing commands associated with them to prevent human errors. when you type "visudo" it acts as if you types "vi sudoers", except that when you save the file, it validates your changes, and makes sure there are no syntax errors before making the changes live. Indeed, if you don't like vi, you can change the editor with

Code:
EDITOR=nano visudo
or
Code:
EDITOR=joe visudo
man visudo as i recall is an explanation of what the various options do, not how to edit.

I don't think the issue is with root access to the command. Your issue is probably that the folder is only writable by root, as by default that file is owned by root:root -rw-r--r--. try changing the permissions on the file so that common users can write it. create a group for the writable users to be in, then give the single file group write permissions (chown :groupname, and chmod 664).

Hope this helps, let me know if it works for you.
TMA
 
Old 04-27-2011, 02:08 PM   #8
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
that's a good idea savona --

open text editor and type

#!/bin/bash
sync; echo 3 > /proc/sys/vm/drop_caches

save as echo3.sh

put the echo3.sh file in the /root

open the sudoers file by using "visudo' and this is where I'm not sure what to do---
need help driving in the sudoers file.

edit a pre-existing line or add a line
 
Old 04-27-2011, 02:10 PM   #9
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
Quote:
Originally Posted by thinmintaddict View Post
I don't think the issue is with root access to the command. Your issue is probably that the folder is only writable by root, as by default that file is owned by root:root -rw-r--r--. try changing the permissions on the file so that common users can write it. create a group for the writable users to be in, then give the single file group write permissions (chown :groupname, and chmod 664).

Hope this helps, let me know if it works for you.
TMA
I agree with this statement, I just had a look at the file and ...


$ ls -lrt drop_caches
-rw-r--r-- 1 root root 0 Apr 27 15:05 drop_caches

So adding your user to the sudoers file is not your answer, see thinmintaddict's suggestion above.
 
Old 04-27-2011, 02:11 PM   #10
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
thinmintaddict -- another great idea and simple...

checking on that/
 
Old 04-27-2011, 02:12 PM   #11
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
Quote:
Originally Posted by vintage2010 View Post
that's a good idea savona --

open text editor and type

#!/bin/bash
sync; echo 3 > /proc/sys/vm/drop_caches

save as echo3.sh

put the echo3.sh file in the /root

open the sudoers file by using "visudo' and this is where I'm not sure what to do---
need help driving in the sudoers file.

edit a pre-existing line or add a line

Well if you read the above posts this isnt going to solve your problems, but for the sake of learning you can add a new line since your working with the default sudoers file your user will not be in there. If you wanted to add another command in the future you would append the new command to the old line.

Short answer: Add a new line.
 
Old 04-27-2011, 02:17 PM   #12
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
I already have the group so I just need to do a chown "group" dump_caches
 
Old 04-27-2011, 02:20 PM   #13
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
Thanks savona -- for letting me learning something today

Thanks thinmintaddict as well

I will update the LQ profile as you two being AWESOME and helpful !!
 
Old 04-27-2011, 02:53 PM   #14
vintage2010
Member
 
Registered: Nov 2010
Location: Ohio
Distribution: RHEL 5
Posts: 52

Original Poster
Rep: Reputation: 0
OK I chown and chgrp to the file drop_caches and I got the following error

bash: echo: write error: Operation not permitted
 
Old 04-27-2011, 03:11 PM   #15
savona
Member
 
Registered: Mar 2011
Location: Bellmawr, NJ
Distribution: Red Hat / Fedora
Posts: 195

Rep: Reputation: 50
Quote:
Originally Posted by vintage2010 View Post
OK I chown and chgrp to the file drop_caches and I got the following error

bash: echo: write error: Operation not permitted
Hmmm... are you sure you set the permissions right? Also is the user in said group?

Do you have selinux enabled?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
[SOLVED] "sudo: Can't mkdir /var/run/sudo/%user%: File exists" CNBarnes Linux - Server 7 01-10-2011 04:11 PM
sudo permissions to edit apache's files xpucto Linux - Newbie 3 12-05-2007 03:17 PM
help to edit Edit my bootloader's config file from kernel prompt jagdishpandey Linux - Kernel 5 07-03-2007 06:59 AM
Changing file permission, How to edit a file? rainchild Linux - Newbie 8 01-14-2007 10:18 PM


All times are GMT -5. The time now is 03:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration