SSH keys and agent harvesting
Warning
Run these techniques only on systems you are explicitly authorized to test. Shell histories can contain credentials and internal hostnames. Minimize collection, don’t modify history files, and store/delete outputs according to the engagement’s rules.
You are looking for private keys, agent access, and SSH config that maps internal targets.
User SSH material
Pull high-value files when present:
Interpretation:
~/.ssh/configoften contains internal hostnames, jump hosts, usernames, and key paths.known_hostsis an internal hostname and IP list you can reuse later.
Find private keys without guessing names
Check whether a key is encrypted without modifying it:
Interpretation:
Exit code
0means the key could be used without a passphrase prompt.A passphrase prompt means the key is encrypted. Don’t brute force interactively on target. Capture it for offline handling if in scope.
Broad sweep across all readable files (noisy)
This is heavier. Keep it on one filesystem and prune pseudo filesystems.
Interpretation:
Hits under
/etc/ssh/may be host keys. Useful for certain scenarios, but treat them differently than user keys.Hits under
/home,/opt,/srv,/var/wwware more likely to be user or application keys that unlock access elsewhere.
SSH agent and forwarded agent reuse
Check if an agent is present for your current shell:
If you suspect other accessible agent sockets on disk:
If you can read or access a socket path that belongs to a more privileged context, you can try pointing your session at it:
Interpretation that changes decisions:
If
ssh-add -lshows keys, you can authenticate to targets where those keys are trusted without ever touching the private key file.If
SSH_AUTH_SOCKis empty and no keys exist on disk, deprioritize SSH-based access and focus on other credentials.
References
-
ssh manualman.openbsd.org/ssh (opens in new tab)
Client behavior and options
-
ssh-agent manualman.openbsd.org/ssh-agent (opens in new tab)
Agent socket and forwarding behavior
-
ssh-add manualman.openbsd.org/ssh-add (opens in new tab)
Listing and using loaded keys
Was this helpful?
Your feedback helps improve this page.