Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to lock the /etc/hosts file somehow in a way that only someone else can unlock it, possibly using a lock code.

I would then give the passcode to someone else.

I'm running Ubuntu 10.10.

share|improve this question
just one word: why? – akira Dec 18 '10 at 12:14
I change it otherwise. Works fantastic on a jailbroken iPhone with lockdown. – tobeannounced Dec 18 '10 at 22:58
Tell us more about this desire to constantly change /etc/hosts. – Allen Dec 19 '10 at 12:54
up vote 3 down vote accepted

Create an account for the other person and add it to the admin group (gives sudo access). Take yourself out of the admin group, so you can't use sudo.

share|improve this answer
+1. Not sure how else to do it. – oKtosiTe Dec 18 '10 at 16:10

As far as I know, Pass codes on files nearly always (well every time I have seen) uses third party software in order to encrypt the file.

I do not know of any software that will accomplish what you want as the file needs to be read normally by the OS. If you were to some how encrypt it, then someone else could always just delete it and recreate it.

What you want to do is to look in to standard file level protection and only give certain groups access to the file - such as Root/Administrators. You can read up about Linux permissions using chmod here.

share|improve this answer
The problem of course being that–at least that's my assumption–the asker is the root user of the system. My knowledge is by no means definitive, but I'd be surprised if there is any way to protect any file from being deleted/replaced by root. – oKtosiTe Dec 18 '10 at 13:07
@oKtosiTe - My thoughts exactly, Chmod is the only solution I can think of - but that only works for machines with multiple users.... Anything that encrypts/passcodes the file will make it inaccessible to the system itself so kind of pointless... It is a hard one, but chmod is the best solution. – William Hilsum Dec 18 '10 at 14:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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