Page cover
For the complete documentation index, see llms.txt. This page is also available as Markdown.

SSH | 22

00. Basic

SSH (Secure Shell) is a cryptographic protocol for secure remote access and data transfer over TCP port 22, using SSHv2 for security (SSHv1 is insecure); prefer key-based authentication over passwords, disable root login, configure on Linux via /etc/ssh/sshd_config with sudo systemctl restart sshd, use OpenSSH or PuTTY on Windows, allow TCP port 22 in firewalls while restricting to trusted IPs, and check /var/log/auth.log on Linux for troubleshooting.

  • SSH Login Options

## ------------------| Debugging and Troubleshooting
ssh -v h4rithd@$IP                                   ## Enable verbose output for debugging
ssh -vvv h4rithd@$IP                                 ## Enable maximum verbose output

## ------------------| Host Key Management
ssh -o UserKnownHostsFile=/dev/null h4rithd@$IP      ## Prevents ssh from attempting to save the host key
ssh -o StrictHostKeyChecking=no h4rithd@$IP          ## Instruct ssh to not prompt to accept the host key
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null h4rithd@$IP      ## Combine to bypass host key checking (insecure, for testing)

## ------------------| Escaping Restricted Shells
ssh -t bash h4rithd@$IP                              ## Escape rbash by forcing bash
ssh -t /bin/sh h4rithd@$IP                           ## Escape rbash using sh
ssh -t python -c 'import pty; pty.spawn("/bin/bash")' h4rithd@$IP      ## Escape rbash with Python PTY

## ------------------| Using sshpass for Automation
sshpass -f /path/to/keyfile ssh h4rithd@$IP          ## Use sshpass with key file
sshpass -p 'password' ssh h4rithd@$IP                ## Use sshpass with password (insecure)
sshpass -p 'password' ssh -o StrictHostKeyChecking=no h4rithd@$IP      ## Combine sshpass with no host key checking

## ------------------| Authentication Methods
ssh -o PubkeyAuthentication=no h4rithd@$IP           ## Disable public key authentication
ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no h4rithd@$IP      ## Force password authentication
ssh -o GSSAPIAuthentication=no h4rithd@$IP           ## Disable GSSAPI authentication
ssh -i /path/to/id_rsa_custom h4rithd@$IP            ## Use specific private key file

## ------------------| Encryption and Compatibility
ssh -o MACs=hmac-sha2-256 h4rithd@$IP               ## Specify modern MAC algorithm
ssh -o MACs=hmac-sha2-512 h4rithd@$IP               ## Specify modern MAC algorithm
ssh -o MACs=hmac-md5 h4rithd@$IP                    ## Try legacy MAC for compatibility (deprecated, insecure)
ssh -o Ciphers=aes256-ctr h4rithd@$IP               ## Specify encryption cipher
ssh -o KexAlgorithms=diffie-hellman-group14-sha1 h4rithd@$IP      ## Specify legacy key exchange algorithm
ssh -o HostKeyAlgorithms=+ssh-dss h4rithd@$IP       ## Specify legacy host key algorithm
ssh -o KexAlgorithms=diffie-hellman-group14-sha1 -o HostKeyAlgorithms=+ssh-dss h4rithd@$IP      ## Combine legacy key exchange and host key algorithms

## ------------------| Connection Optimization
ssh -2 h4rithd@$IP                                  ## Force SSHv2 protocol (SSHv1 is insecure)
ssh -C h4rithd@$IP                                  ## Enable compression for faster data transfer
ssh -p 2222 h4rithd@$IP                             ## Use custom port (e.g., 2222)
ssh -F /path/to/custom_ssh_config h4rithd@$IP       ## Use custom SSH config file
  • Default Configurations

01. Enumeration & Exploitation

01.1 Enumeration

01.2 Exploitation

  • Brute Force

  • Crack Private Keys

  • User Enumeration (OpenSSH 7.7 | CVE-2018-15473)

  • SSH Certificate-Based Authentication for Root Access

  • CVE-2008-0166 (Debian-based systems | September 2006 <--> 2008 May 13th)

  • Predictable PRNG Brute Force SSH

Last updated