Recall & Review
beginner
Why should you avoid running scripts as the root user unless absolutely necessary?
Running scripts as root can cause serious damage if the script has errors or is malicious. It can change or delete important system files. Always use the least privilege needed to reduce risk.
Click to reveal answer
beginner
What is the purpose of using 'set -e' at the start of a bash script?
'set -e' makes the script stop immediately if any command fails. This helps prevent the script from continuing in a broken state, which can cause security or data problems.
Click to reveal answer
intermediate
How can you protect sensitive data like passwords in your scripts?
Avoid hardcoding passwords in scripts. Use environment variables, encrypted files, or secure vaults. Also, restrict script file permissions so only trusted users can read them.
Click to reveal answer
intermediate
Why should you validate all user inputs in scripts?
Validating inputs prevents injection attacks and unexpected behavior. It ensures the script only processes safe and expected data, reducing security risks.
Click to reveal answer
advanced
What is the risk of using 'eval' in bash scripts, and how can you avoid it?
'eval' executes strings as commands, which can be dangerous if the string contains malicious code. Avoid using 'eval' or sanitize inputs carefully before using it.
Click to reveal answer
What does 'chmod 700 script.sh' do to the script file?
✗ Incorrect
'chmod 700' sets permissions so only the file owner can read, write, and execute the script. This protects the script from unauthorized access.
Which of these is a good practice to avoid exposing passwords in scripts?
✗ Incorrect
Storing passwords in environment variables keeps them out of the script code and reduces the risk of accidental exposure.
What is the main reason to validate user input in scripts?
✗ Incorrect
Validating input helps prevent malicious data from causing harm or unexpected behavior in the script.
What does the 'set -u' option do in a bash script?
✗ Incorrect
'set -u' helps catch errors by stopping the script if it tries to use a variable that has not been set.
Why is it risky to use 'eval' with user input in bash scripts?
✗ Incorrect
'eval' runs the input as code, so if the input is malicious, it can harm the system or leak data.
Explain three best practices to keep bash scripts secure.
Think about permissions, input safety, and secrets.
You got /3 concepts.
Describe why 'set -e' and 'set -u' are useful in secure bash scripting.
Consider how these options help prevent unexpected script behavior.
You got /3 concepts.