Skip to content

Instantly share code, notes, and snippets.

@DanielArnett
Last active January 8, 2023 02:55
Show Gist options
  • Save DanielArnett/afbe5e508103ca91e78e4dee68af34ec to your computer and use it in GitHub Desktop.
Save DanielArnett/afbe5e508103ca91e78e4dee68af34ec to your computer and use it in GitHub Desktop.
Block Social Media in Ubuntu

This guide shows how to block distracting sites in Ubuntu, and stop yourself from removing the blocks personally. This is helpful in preventing a momentary temptation from turning into an extended distraction. Only do this if you don't need daily root access. Most sudo commands will still work, you just wont be able to switch to root user. You'll be generating a new root password and making it hard to access.

0. Before starting, make sure you've set up a password for the root user on your machine. If you haven't already you can run sudo passwd root to do so. If you want you can go ahead and use the random password in step 7.

1. Switch to root.

su

3. Create a file controlling what sudo users can do.

visudo -f /etc/sudoers.d/<account_I_use>

4. Paste the rules for that account allowing it to use all commands with sudo except chattr and bash (use the exclamation point to block more commands.

<account_I_use> ALL=ALL, !/usr/bin/chattr, !/bin/bash, !/usr/bin/passwd, !/etc/passwd, !/usr/sbin/visudo, !/bin/su, !/bin/sh

6. Make the hosts file immutable

chattr +i /etc/hosts

7. Generate a long, random password the password for the root user, save one half of the password somewhere you won't lose, and give the other half of the password to a friend. Now delete your copy of the full password, so nobody except yourself can reconstruct the full password.

passwd root

8. Once you're certain your friend has the password somewhere they can't lose, delete your copy of the password and exit the root user.

exit

Now you shouldn't be able to access the websites that commonly distract you without additional effort. No solution is going to be foolproof, but it certainly helps with hindering a shortlived impulse. If you need root access for some reason just ask your friend to send you their half of the password, and when you're done using root you can regenerate a new half for them. Don't worry if it doesn't seem to work right away; your browser likely saves a cached version of the websites temporarily, so it may take a little while before it shows up as being blocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment