inflater wrote:(Imagine: New USB stick (empty), old USB stick (valuable data). Insert new stick, mkfs, mount, some file operations, umount, switch to new stick, using command history to get to the mount command, hit "up" one time too often while in a hurry...)
...and nothing would prevent you from formatting if you used SUDO before mkfs, which you had to.
Just being pedantic here, but you do not need to be root to create a filesystem. By default, mkfs is not on a standard user path, but you can always call it yourself. The only thing preventing a standard user from running mkfs on any block device is the permissions set on that device. You either have to be root, or in some special group (usually 'disk') to be able to write directly to a device file, which is how mkfs works.
Anyway, the password prompting feature of sudo would generally prevent you from accidentally running mkfs. Yes, sudo caches credentials for a period (5 minutes by default), so you're not always prompted for a password. I hate to say it, but you're right, if sudo (in it's default config) was used in Solar's example then nothing would prevent you from inadvertently running mkfs on the old usb stick. It's for that reason entirely that I disable the password caching on systems I admin, so anyone needing to run multiple commands in a row as root need to use 'sudo -s' or /bin/su to get a root shell instead. I don't run Ubuntu, so I have no idea how sudo is set up there. The purpose of sudo though is that it can be set up to be more restrictive than /bin/su. You can specify what commands a user (or group) is allowed to run via sudo. That's something you cannot do with /bin/su.
Note though, Solar didn't mention sudo at all. I look at it from this point of view... If you ran through Solar's example on a single user machine, what would prevent it? Nothing. On a standard unix machine? The fact that normal users cannot write to a block device file. You'd have to become root somehow to mount the device, as well as to format the device. Sure, the example is flawed if sudo with password caching is used, or if you hit up arrow too many times inside a root account. But just using different user accounts (privilege separation) makes it safer. You always need to be careful when running as any administrative user. It's designed so that average joe can't harm the system by doing stupid things, but once you become root (almost) all those restrictions go away. An example of a restriction that will not go away: you can't run mkfs on a device file that contains an active (i.e., mounted) filesystem.
I'd also like to point out that while nobody else in your household may run linux on that machine, it does not mean you're the only user on it. Run 'ps aux'. Look at the output. See things like 'root', 'nobody', 'daemon', etc? Those are all USERS. Sure, most of them are system accounts, and you may be the only user account on there, but once again, privilege separation. If a process running as nobody goes awry, the most it can affect is anything else the nobody system account has access to. For another example, look at your windows xp or vista box's task manager. You'll notice the same thing; processes running under system accounts or user accounts. Those are there for the same reason.
inflater wrote:there's bound to be an accident sooner or later.
Yep, but I've grew on DOS/Win95 and still am using the command line sometimes, and guess what? I never accidentaly typed format c:
Perhaps the only reason you never accidentally typed 'format c:' is because of the huge "This will destroy all your data!" warning you received the first time you did it. That makes not doing it again a learned behavior. Or perhaps you once typed 'format c:' instead of 'format d:' and only caught it because that same warning is followed by a "continue?" prompt. To put this in the context of Solar's example above, you also can't run that command accidentally because there's no command history or command recall in DOS.
Yes, accidents happen, and judging by your experiments with high voltage electricity and the injuries you've received from that, it's only a matter of time until you've learned that the hard way. Hopefully you won't get yourself nominated for a Darwin award in the process.
//EDIT: Fixed botched quoting attempt.