Courseiva
easyMultiple SelectObjective-mapped

XK0-006 Practice Question: A Linux administrator writes a Python script to…

A Linux administrator writes a Python script to parse configuration files. Which TWO practices improve security and portability? (Select TWO.)

⚠ Common exam trap

Another common mistake is selecting Option B because absolute paths seem more reliable, but they actually harm portability when the script is moved to a different system with a different directory structure.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Validate all external input before processing

Validating all external input before processing prevents injection attacks and data corruption. In Python, this means checking file paths, user inputs, and configuration values against expected patterns (e.g., using regex or allowlists) before using them in file operations or system calls. This is a core security principle for any script that handles untrusted data.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Validate all external input before processing

    Why this is correct

    Input validation prevents injection attacks and improves security.

  • Use absolute paths for all file operations

    Why it's wrong here

    Absolute paths reduce portability; relative paths or configuration are better.

  • Use sudo within the script to run privileged commands

    Why it's wrong here

    Embedding sudo in a script is a security risk; use proper permissions instead.

  • Use raw_input() instead of input() in Python 2

    Why it's wrong here

    raw_input() is Python 2 only; Python 3 uses input() which is safe. This does not apply to modern environments.

  • Use shebang #!/usr/bin/env python3

    Why this is correct

    This makes the script portable across systems where python3 may be in different locations.

About these practice questions

Courseiva writes every XK0-006 question from scratch — 979 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.