Redis RCE via SSH Key Injection
Redis can write any data to any writable path on disk. By pointing the DB save path at /root/.ssh/ and writing your SSH public key as the DB content, you inject an authorized key and can then SSH in as root — or as whatever user Redis is running as. This gives persistent access rather than a reverse shell, and is often more stable than the cron technique on newer Linux distributions.
Prerequisites Check
1 – CONFIG access:
Must return a path, not an error.
2 – SSH port open:
SSH must be listening. If it is not, the technique still injects the key but you cannot use it until SSH is enabled.
3 – Redis can write to the target SSH directory:
OK confirms write access. This requires Redis to be running as root. For non-root Redis, try the home directory of the redis user instead:
If that directory does not exist, create it first from any existing shell on the target.
Step 1 – Generate or Use Your SSH Key
Generate a key pair if you do not have one:
Read the public key:
Step 2 – Record the Original Config
Step 3 – Write the Public Key into Redis
Pad the key with newlines to ensure cron-style garbage in the RDB file does not corrupt the authorized_keys format — SSH is strict about the file format:
Step 4 – Save the Key to authorized_keys
Confirm the save:
Step 5 – Connect via SSH
For a non-root Redis user:
If the connection is refused, the authorized_keys file may have bad permissions. From an existing foothold:
Step 6 – Restore Original Config
Finding the Redis User's Home Directory
If Redis is not running as root but you do not know the user's home directory:
Then from a shell, check who owns /tmp/test_write:
The owner is the Redis user. Check their home directory:
Use that home path for the .ssh/authorized_keys write.
References
-
Redis Pentestingbook.hacktricks.xyz/network-services-pentesting/6379-pentesting-redis (opens in new tab)
HackTricks SSH key injection technique and Redis CONFIG write methodology.
Was this helpful?
Your feedback helps improve this page.