XK0-006 Security Practice Question
An administrator wants to generate a self-signed certificate and private key for testing. Which command creates both in one step?
⚠ Common exam trap
Many candidates confuse `openssl req -new` (which creates a CSR) with `openssl req -x509` (which creates a self-signed certificate), leading them to pick option C, which requires a pre-existing key and does not generate both in one step.
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
✓
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
The `openssl req -x509 -newkey rsa:2048` command generates a new private key (via `-newkey`) and immediately creates a self-signed X.509 certificate (via `-x509`) in a single step. The `-keyout` and `-out` flags specify the output files for the private key and certificate, respectively, and `-nodes` ensures the private key is not encrypted with a passphrase, which is typical for testing scenarios.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
Why this is correct
The -x509 flag makes openssl req emit a self-signed certificate rather than a CSR, while -newkey rsa:2048 generates the private key in the same invocation. This satisfies the stem's one-step requirement, producing both key.pem and cert.pem without a separate signing command.
- ✗
openssl genrsa -out key.pem 2048
Why it's wrong here
Only generates a key, not a certificate.
- ✗
openssl req -new -x509 -days 365 -key key.pem -out cert.pem
Why it's wrong here
This creates a CSR and self-signs it, but with -key key.pem it consumes an existing private key rather than generating one, so both artefacts are not produced in one step. Omitting -key would generate the key.
- ✗
openssl x509 -req -in req.pem -signkey key.pem -out cert.pem
Why it's wrong here
This signs an existing CSR using a key, so it needs req.pem and key.pem to already exist; it creates no private key. It is the correct step for converting a CSR into a certificate once those files are present.
Quick reference
Asymmetric Encryption Algorithm Comparison
| Algorithm | Key Exchange | Signatures | Equivalent Security Key | Notes |
|---|---|---|---|---|
| RSA-3072 | Yes | Yes | 128-bit | Widely deployed; slow for bulk data |
| ECDSA P-256 | No | Yes | 128-bit | Fast signatures; standard TLS certs |
| ECDH / ECDHE | Yes | No | 128-bit | Perfect forward secrecy in TLS 1.3 |
| DH / DHE | Yes | No | 128-bit (3072-bit key) | Replaced by ECDHE in modern TLS |
| Ed25519 | No | Yes | ~128-bit | SSH keys, modern PKI |
Go deeper
Related to this question
About these practice questions
One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
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.