sodcalculator

10 Tech How-To

How to Check SSH Algorithms in Linux

Guide 10-59510 · Updated · Step by step

This guide shows you how to view the key exchange, host key, cipher, and MAC algorithms that your SSH client and server support or are currently using. You’ll learn the exact commands to list supported algorithms, check the active session’s algorithms, and verify configuration settings—useful for security audits, debugging connection issues, or ensuring compatibility with older systems.

What You’ll Need

  • A Linux system with OpenSSH installed (most distributions include it by default).
  • Terminal access (local or remote).
  • For checking the server’s algorithms: either root/sudo access to read the server configuration, or the ability to connect to the SSH server on port 22.

Step-by-Step

  1. Check the SSH client’s supported algorithms. Open a terminal and run:
    ssh -Q kex — lists key exchange algorithms.
    ssh -Q hostkey — lists host key algorithms.
    ssh -Q cipher — lists symmetric ciphers.
    ssh -Q mac — lists message authentication codes.
    These commands read the client’s built-in defaults, not the configuration file.
  2. Check the SSH server’s supported algorithms. On the server machine, run:
    sshd -T | grep -E 'kexalgorithms|ciphers|macs|hostkeyalgorithms'
    This shows the effective algorithms after applying the server’s config file (usually /etc/ssh/sshd_config and included files). You need root or sudo to read the private host keys, so run with sudo if necessary.
  3. Check the algorithms used in an active SSH session. While connected to a server, run:
    ssh -v user@host (add -v for verbose output). Look for lines starting with debug1: KEX:, debug1: Server host key:, debug1: Cipher:, and debug1: MAC:. These show the algorithms negotiated for that connection.
  4. Check the client’s configuration file. The client config at ~/.ssh/config or /etc/ssh/ssh_config may override defaults. To see what the client would actually use, run:
    ssh -G user@host | grep -E 'kexalgorithms|ciphers|macs|hostkeyalgorithms'
    This shows the effective settings after applying all config files and command-line options.
  5. Check the server’s configuration file directly. Open /etc/ssh/sshd_config (and any files in /etc/ssh/sshd_config.d/) and look for lines like KexAlgorithms, Ciphers, MACs, HostKeyAlgorithms. If a line is commented out or absent, the default for that OpenSSH version applies.
  6. Check the running SSH server’s actual listening algorithms. Use nmap (if installed) to scan the server’s SSH port:
    nmap --script ssh2-enum-algorithms -p 22 hostname
    This performs a real connection and lists the algorithms the server advertises. This is useful for remote servers where you don’t have shell access.

Common Mistakes

  • Confusing client and server. ssh -Q shows the client’s built-in support, not what the server accepts. The server may have a restricted list in its config.
  • Forgetting that config files override defaults. The effective algorithms are the intersection of what the client and server support, after applying their respective configuration files. Always check with ssh -G and sshd -T.
  • Using sshd -T without sudo. The command needs to read private host keys to list host key algorithms, so it will fail with a permission error if run as a normal user.
  • Assuming the verbose output shows all supported algorithms. ssh -v only shows the negotiated ones for that session, not the full list.

Tips

  • To see a quick summary of all supported algorithms in one command, use:
    for alg in kex hostkey cipher mac; do echo "$alg: $(ssh -Q $alg | tr '\n' ' ')"; done
  • If you’re auditing security, check for weak algorithms like diffie-hellman-group1-sha1, ssh-rsa (for host keys), aes128-cbc, or hmac-md5. These are often disabled in modern OpenSSH versions.
  • To test a specific algorithm, force it with the -o option:
    ssh -o KexAlgorithms=curve25519-sha256 user@host
  • To see the default algorithms for your OpenSSH version, check the man pages: man ssh_config and man sshd_config list the defaults in the description of each option.

Troubleshooting

  • Permission denied when running sshd -T. Run with sudo or as root. If you still get an error, check that the host keys exist in /etc/ssh/.
  • The ssh -Q command returns nothing. This can happen if OpenSSH is not installed or the version is very old. Check with ssh -V. If missing, install openssh-client with your package manager.
  • Verbose output doesn’t show the algorithm lines. Make sure you use a single -v (or more, like -vvv). The lines appear early in the connection handshake. If you’re already connected, you can’t see them; reconnect with -v.
  • nmap not found. Install nmap using your package manager (e.g., sudo apt install nmap on Debian/Ubuntu, sudo dnf install nmap on Fedora).
  • Connection fails after changing algorithms. If you edit the SSH config and then can’t connect, you may have disabled all mutually supported algorithms. Double-check that you didn’t exclude the algorithm the server uses. You can temporarily start sshd with sshd -t to test the config syntax.

Frequently Asked Questions

What is the difference between ssh -Q and sshd -T?

ssh -Q lists the algorithms compiled into the client binary, regardless of configuration. sshd -T shows the effective algorithms the server will use after applying its configuration file.

How do I see the algorithms for the current SSH session?

Connect with ssh -v user@host and look for lines starting with debug1: KEX:, debug1: Server host key:, debug1: Cipher:, and debug1: MAC:. These show the negotiated algorithms for that connection.

Can I change the algorithms the SSH client uses?

Yes, you can specify them in ~/.ssh/config (e.g., KexAlgorithms curve25519-sha256) or use the -o command-line option. The server must also support the chosen algorithm.

Why do I see ssh-rsa in the host key list but can’t connect with it?

In OpenSSH 8.8+, the ssh-rsa signature algorithm is disabled by default because it uses SHA-1. It may still appear in the list of supported host key types, but the server refuses to use it unless you explicitly enable it with HostKeyAlgorithms +ssh-rsa in the server config.

How can I check algorithms on a remote server without logging in?

Use nmap --script ssh2-enum-algorithms -p 22 hostname. This connects to the SSH port and lists the algorithms the server advertises.

What do the algorithm names mean? For example, curve25519-sha256.

The name typically indicates the algorithm family and parameters. curve25519-sha256 is a key exchange using the Curve25519 elliptic curve and SHA-256 hashing. aes128-ctr is a symmetric cipher using AES with a 128-bit key in CTR mode. hmac-sha2-256 is a MAC using HMAC with SHA-256.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →