Imagine that you set up a computer at a public location, such as cafe, library, or computer lab in your school, so that any one can use your computer. Most of the time, users mainly use the web browsers for surfing the web, checking the email, or updating the status on social websites etc. At the mean time, they may download some files on your computer, generating a lot of browsing history in your web browsers, accidentally saving their user names/passwords in the browsers etc. How do you clean up these mess? How do you reset the user account to default automatically?
First, I am assuming that your computer is running Linux, such as Ubuntu, Fedora, Debian etc. It really doesn’t matter which Linux you use, because most Linux uses the same kernel. The idea describes in this article is applicable to any Linux.
Linux and Windows are very very different. Linux has a much better control on the user permissions. For example, if you simply create a standard user on Linux, e.g.,
sudo adduser guestuser
where this new user, guestuser, is a standard user only.
If you log in as guestuser, all of the files you create will be stored in your home folder only, i.e., /home/guestuser. Unlike Windows, there is no registry or something similar. In the other words, all of your activities are limited within your home folder. If you like to create a file outside your scope, you will need to have the root access. Of course, you won’t grand the root access to the guest user.
Now you understand that the guest user can only mess around the home directory only (/home/guestuser). In order to clean up or reset the user account to default, all you need is to reset this folder to default.
Setup a Home Directory On Ram Disk
We are going to implement this idea using ram disk. If you don’t know anything about ram disk, you can think about it as a usb thumb drive, except that it is a super fast device, and cannot hold any data after each reboot. In the other words, if we set up a the home directory of the guestuser on a ram disk, all of the mess will be gone after each reboot. So here are the steps:
First, we want to create a guestuser first:
sudo adduser guestuser
This will add a new user into the system and create its home directory. Next, we want to create a ram disk. Before we do it, let’s find out how much memory you have in your system:
On my machine, I have 2GB (2000 MB) memory in total.
total used free shared buffers cached Mem: 1999 1789 209 0 119 1176 -/+ buffers/cache: 492 1506 Swap: 3150 0 3150
Since I only have 2GB of memory, I want to keep some of them for my system. I think using 512MB for the ramdisk is enough.
To create a ramdisk during the boot, simply modify /etc/rc.local
sudo nano /etc/rc.local
And include the following commands:
#Create a 512MB ramdisk, and map it to the home directory of the guestuser. mount -t ramfs -o size=512M ramfs /home/guestuser #After the ramdisk is mapped, the directory will be owned by the root. #We need to modify the permission such that guestuser can access it. chown -R guest:guest /home/guestuser
Here are some special notes for different Linux:
Fedora 15 or earlier: None
Fedora 16: By default, /etc/rc.local is missing. Please refer my another post: Fedora 16 /etc/rc.local is missing) for details.
Ubuntu: Please include your code before exit 0 command, otherwise it won’t work, i.e.,
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. mount -t ramfs -o size=512M ramfs /home/guestuser chown -R guestuser:guestuser /home/guestuser exit 0
After the set up is completed, simply reboot the computer to make the ramdisk effective.
Now, try to log in as the guestuser. You can try to download some files to your home directory; visit some websites; or even change the wallpaper. All of these settings will be stored in your home directory. Next, try to log out the account, restart the computer and log in to your account again. You will notice that everything will be reset to default, i.e., all of your previously downloaded files are gone, wallpaper will be reset to default, the web history is cleared etc.
Enjoy running a clean, maintenance-free workstation.