Linux Survival Basics
Read-only, sensitive outputFind 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.
grep -n 'hostname' ~/.ssh/known_hostsgrep -n 'hostname' ~/.ssh/known_hosts
next steps
Related commands
Find a Host in known_hosts
Do not edit known_hosts blind.
ssh-keygen -F hostname
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
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
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
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
- SSH known_hosts changed hub Use to inspect stored SSH host keys.
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.
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.