Pages

Saturday, November 26, 2011

Protect your root account.

I will present a solution to protect the root account, quite funny but still elegant.
You can read about the command trap using: man trap.
What is this command?
when the specified event will occur will execute the command specified.
In this case, it will receive signal respectively will execute one command - exit
The source code.
 protect()
 {
 echo "What is the secret ?"
 trap protect 2 20
 read -s resp
 if [ "$resp" != "asd" ]; then
 echo "Error!"
exit
fi
 }
 protect
The result will be leaving the root account if you do not answer the question correctly.
Now protect the file against unauthorized changes:
# chmod 700 /root/.bashrc
You can create using the example above, different ways to execute various commands.