Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

To combat procrastination, I edit my /etc/hosts file by adding time-wasting websites and pointing them to localhost. However, the flesh is weak and I often find myself reverting my changes.

I was thinking of the following solution, but I don't know if it is technically possible.

I would ask a trusted friend to come over, create a new account with a strong password that I don't know, change the owner and permissions of the /etc/hosts file so that only that new user can change that file and that I nor root no longer have access to it.

The use case would be that I ask my friend to come over before the exam period, he changes the file and puts the procrastination blocking measures in place, and that during the time I need to study I have no way of editing the file myself. After the exam period is over, I ask him to 'unlock' the file and I can browse freely again.

share|improve this question
1  
We've gotten a few requests like this around Exam time. It usually ends up being 'improve self-control' –  Marco Ceppi Aug 11 '11 at 23:12
1  
Give us your friend's email and we'll tell him privately how to sabotage you. –  djeikyb Aug 12 '11 at 1:26
add comment

4 Answers

up vote 5 down vote accepted

You can lock a file so not even root user can edit it.

sudo chattr +i /etc/hosts

Stop reading this answer until after you exams :)

Then you unlock the file again using

sudo chattr -i /etc/hosts
share|improve this answer
    
You could delete /usr/bin/chattr after locking your hosts and restore it after your exams. Might break everything though. –  Oli Aug 11 '11 at 22:21
    
I didn't know about the chattr command, but the initial problem remains: I want to protect me from myself. If I know there is a way to unlock/restore the file before the exams, I probably will. Therefore I am still looking for a solution where only a third party can grant me access to that file. Thanks. –  BioGeek Aug 11 '11 at 22:29
1  
As long as you have root access you cannot do this. Even if there were a way, you still have physical access to the machine and can boot the machine from a rescue/live cd/usb and edit the files. I will post another answer. –  Richard Holloway Aug 12 '11 at 7:20
    
Just modify the source of your init process to force the chattr (polling or via inotify). Then you would have to boot with a live cd to change it, to counter that you can store it as a string in init and generate it on startup inside init. Personally I'd use an inotify watch on the file to replace it with the internal string on any inotify event. –  technosaurus Jan 21 at 3:25
add comment

Ultimately, if root access is available, there is no foolproof way to stop a smart user from doing what they want. I do not think that there is a way to do this, other than to relinquish root access.

share|improve this answer
1  
I would amend this to "Ultimately, if physical access is available...". Procrastination is easy as a livecd. –  djeikyb Aug 12 '11 at 1:28
    
True. I had not thought of that. –  zpletan Aug 13 '11 at 23:28
add comment

You could set up another user account that is a regular desktop user than cannot use sudo. Then get your mate to come round and log in as you on your existing account, edit the /etc/hosts file, then reset your password without telling you what it is and log out.

Then you have to use the new account, which does not have the rights to edit /etc/hosts.

You will still need to exercise will power though to stop you from booting from a live CD/USB.

share|improve this answer
add comment

As an alternative, the same time you make your /etc/hosts file, you could also edit the /etc/sudoers file or just remove your user from the admin group. Changing group is probably easier.

You should probably build a safe-guard so that you can add yourself back to the group. I suggest adding something in /etc/rc.local or something in a wake script (quicker than doing a full reboot).

If the worst happens and you are locked out, you can boot to recovery mode (in grub) and use the root console to manually add your user back to the admin group.

share|improve this answer
    
I don't think removing myself from the /etc/sudoers file is an ideal solution: I still want to be able to perform other system tasks like installing software, etc. I just don't want to be able to change /etc/hosts any more unless an outside party grants me access to that file. Any solution where I can add myself back to the admin group defeats the point, because I will probably end up doing that before the exams end. Thanks. –  BioGeek Aug 11 '11 at 22:35
1  
Installing software can be done with policykit. For example you can already request updates through update-manager which is otherwise a root-only endeavour. As for stopping yourself - you could create an admin user that only your friend can use to log in and re-add you as an admin. –  Oli Aug 11 '11 at 23:17
add comment

Your Answer

 
discard

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.