UNIX Hints & Hacks |
|||||||||||||||||||||||||||
Chapter 3: Security |
|
||||||||||||||||||||||||||
|
Safeguard against removing the root level files.
Flavors: All
Syntax:
touch file chmod mode file
This uses the -i argument in the rm command to remove files. The -i argument seeks confirmation before any removal of the file or directory takes place. It also known as an interactive removal process.
You place a -i at the top of the root directory; when the rm command progresses through the list of files, it picks up the -i as an argument, not as a file, and proceeds interactively requesting confirmation before it removes any files and your kernel.
Warning - Test this first in a nondestructive test area first. If you don't, you risk removing the files under the root directory. |
rocket 13% cd /usr/tmp rocket 14% mkdir foo rocket 15% touch /usr/tmp/foo/\-i rocket 16% chmod 000 /usr/tmp/foo/\-i
Note - Use the fully qualified path to create the file when creating. |
rocket 17% cd foo rocket 18% touch fee fii foo fum rocket 19% rm -rf *
To safely execute this process for testing, create a directory called foo in /usr/tmp. Then touch a file called -i. Change the permissions so that it has no permissions. If the -i doesn't force the interactive confirmation, the lack of permission on the file stops the removal process at the point where it hits that special file. Go into the foo directory and create test files with touch. Finally, test to verify that it works with the rm command.
Accidents happen and sometimes files at the root level get deleted. This adds one more layer of protection for securing the root files and saving the kernel from getting deleted.
Things happen; sometimes you fat-finger the key and other times you aren't paying attention to what directory you are in when you use the rm command. It's a nice little bonus feature. When it works, it saves much time in restoring from backups.
This -i can go in any directory where you are afraid to lose the files or the subdirectories; it does not have to go only at the root level.
Man pages:
chmod, rm, touch
UNIX Hints & Hacks |
|||||||||||||||||||||||||||
Chapter 3: Security |
|
||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.