Back to commands

Linux Survival Basics

Read-only, sensitive output

Find known_hosts Lines by Name

You need matching lines in known_hosts for one host string.

Command

grep -n 'hostname' ~/.ssh/known_hosts

Before you run this

System impact: Read-only. Output may expose users, paths, tokens, keys, IPs, process arguments, or log details.

When not to use it: Do not delete every known_hosts line for convenience.

Expected output

Line numbers and matching known_hosts entries, if not hashed.

System impact

Read-only, sensitive output. Nothing changes. The command reads current state and prints diagnostic evidence.

Recovery / rollback: no state is changed.

When to use it

Use after `ssh-keygen -F` or when entries are unhashed.

When not to use it

Do not delete every known_hosts line for convenience.

Example run

Commands shown

These are the commands shown for inspection. Treat them as an example, not proof that your system will behave identically.

  1. grep -n 'hostname' ~/.ssh/known_hosts
  2. grep -n 'hostname' ~/.ssh/known_hosts

next steps

Related commands

Linux Survival Basics Can be slow

Find Apache DocumentRoot and Directory Rules

Apache 403 often comes from the directory block, not the file.

grep -RInE 'DocumentRoot|<Directory|Require all|Options|AllowOverride' /etc/apache2/sites-enabled /etc/apache2/conf-enabled /etc/httpd/conf.d 2>/dev/null
Linux Survival Basics Can be slow

Find Nginx root alias and access rules

One deny or alias can explain the whole 403.

grep -RInE 'root|alias|deny|allow' /etc/nginx/sites-enabled /etc/nginx/conf.d 2>/dev/null
Linux Survival Basics Can be slow

Find Nginx SSL Certificate Directives

The wrong certificate is often in the server block.

grep -RInE 'ssl_certificate|ssl_certificate_key|server_name' /etc/nginx/sites-enabled /etc/nginx/conf.d 2>/dev/null
Linux Survival Basics Can be slow

Find the Exact Log Line Before You Scroll

The error was there. The useful part was knowing exactly where it was.

grep -inE 'error|failed|denied|timeout' /var/log/nginx/error.log

next diagnostic step

Where to go from this command

Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • LPIC-1 style command-line practice
  • LFCS style performance-task practice
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.