SSH Private key cracking

For cracking SSH private key, We will use john tool.

Steps for Cracking SSH key

Step 1: Generate SSH Hash from Private Key

We have to make ssh hash first from SSH key.

ssh2john id_rsa > ssh.hash

Step 2: Clean SSH Hash File (Remove Filename Prefix)

This ssh.hash file will have name of file in the beginning. We have to remove that before cracking SSH key.

# Removing Username from hash and keeping only hash.
output=$(cat ssh.hash | cut -d ":" -f2)
echo $output > ssh.hash
cat ssh.hash

Step 3: Cracking SSH hash with john

# Using only wordlist
john --wordlist=/usr/share/wordlists/rockyou.txt ssh.hash

# Using wordlist and custom rule:
john --wordlist=/usr/share/wordlists/rockyou.txt --rules=sshrules ssh.hash

To learn to add custom rule in john the ripper visit below link

Step 4: Connect using SSH

Last updated