Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On a Unix system, what is the best practice for editing system files such as /etc/hosts and php.ini as non-root without doing the tedious sudo+password?

Can I simply chown those files to my non-root-user, or is there a better way using groups or something?

share|improve this question
1  
I am not sure why you'd want to, those aren't files people typically edit frequently enough to need to bypass the protections that are in place for a reason. And no, don't change the ownership... –  nerdwaller Mar 29 '13 at 18:30
add comment

closed as not constructive by techie007, TFM, Scott, Nifle, Dave M Mar 31 '13 at 17:26

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

4 Answers

sudo is the best and proper way to do it. If you give your user account too many administrative privileges (for example, adding yourself to the root group), you open yourself up to accidentally doing all sorts of harmful things. Also, malware/trojans could use your privileges without your knowledge to do nasty things. Just think of typing sudo before a command as an extra check - "Do I really want to run this?"

You can set up sudo (it should already be this way) to wait a specified length of time before asking for your password again, so if you're doing a bunch of admin tasks all at once you don't need to keep entering it.

share|improve this answer
add comment

In addition to MattDMo's answer. If retyping your password is bothering you, you can add NOPASSWD to your privileges. This will still require you to sudo (so you can be aware that you are doing something that could be harmful), but won't bother you for typing your password.

In /etc/sudoers, you can use this line:

forthrin ALL=(ALL) NOPASSWD: ALL

share|improve this answer
add comment

Another option is to open a new terminal and switch to root. Depending on how your system is set up you will be able to do this using one or more of the following ways:

  • sudo su
  • sudo -i
  • su

Once you are the root user, simply keep thyat terminal open and edit any files you want from that terminal using emacs or vim or gedit or whatever you prefer:

emacs /etc/hosts
share|improve this answer
    
Or even sudo -s. –  oKtosiTe Mar 30 '13 at 11:10
add comment

sudo is what you want. As specified before, you can set custom timeouts before asking for a password again or specify NOPASSWD: This can also be set for only a specific usergroup and command like this:

%usergroup ALL=(ALL) NOPASSWD: /bin/vi

You could limit this command to a certain file by pointing to a script that runs vi /etc/hosts, but this would allow users to open other files as well from inside vi or drop into a shell from vi (:!sh or a similar command).

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.