XK0-006 Security Practice Question
An administrator needs to generate a self-signed certificate and private key for an internal web server. Which OpenSSL command creates both in one step?
⚠ Common exam trap
A common mix-up: candidates think Option B is correct because it technically works, but the question explicitly asks for a command that creates both 'in one step', meaning a single OpenSSL command, not a shell pipeline of two separate commands.
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 -keyout key.pem -out cert.pem -days 365 -nodes` command generates a new RSA private key and a self-signed X.509 certificate in a single step. The `-x509` flag outputs a self-signed certificate instead of a CSR, `-newkey` creates the key pair, and `-nodes` prevents encryption of the private key, which is typical for an internal web server that must start without manual passphrase entry.
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 ca -in req.pem -out cert.pem
Why it's wrong here
openssl ca signs a certificate request using a configured CA database and serial file, so it needs an existing CA setup and a separate CSR, and it generates no private key. It is tempting because it is the standard way to issue CA-signed certificates, which is the correct choice when a real certificate authority must sign the request.
- ✗
openssl genrsa -out key.pem 2048 && openssl req -new -x509 -key key.pem -out cert.pem -days 365
Why it's wrong here
This chains two commands: genrsa only creates the private key, and req -new -x509 then builds the certificate from that existing key, so the key and cert are produced by separate invocations rather than one step. It is tempting because it is functionally valid, but the stem asks for a single command.
- ✓
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
Why this is correct
The `-x509` flag makes `req` emit a self-signed certificate rather than a certificate signing request, while `-newkey rsa:2048` generates the private key alongside it. `-keyout` and `-out` write both files in a single invocation, satisfying the requirement to create certificate and key together.
- ✗
openssl x509 -req -in req.pem -signkey key.pem -out cert.pem
Why it's wrong here
openssl x509 -req signs an existing CSR with a supplied key, so it requires a pre-generated key and request and produces only the certificate. It is tempting because it is the standard route for signing a CSR with a CA key, which is correct when the private key and request already exist.
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 |
About these practice questions
This XK0-006 question is part of Courseiva's 781-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.