zsh: command not found: telnet

command-not-found

Published ยท Updated

zsh: command not found: telnet on a Mac is not a PATH problem. Apple stopped shipping telnet (and ftp) with macOS High Sierra 10.13 in 2017. No later macOS has it, so there is nothing to find until you install it.

Most people who type telnet want one of two things: to check whether a port is open, or to talk to a plain-text service such as SMTP by hand. Both work without installing anything.

Option 1: install telnet with Homebrew

brew install telnet
rehash
telnet example.com 80

The binary lands in /opt/homebrew/bin on Apple silicon and /usr/local/bin on Intel Macs. If brew is missing too, start with zsh: command not found: brew. If brew install worked but telnet is still not found, Homebrew's folder is not on your PATH; how PATH works in zsh on macOS shows the fix.

Homebrew's inetutils formula also has a telnet, along with the other GNU network tools. The two formulas conflict, so install only one.

Option 2: test a port with nc (already installed)

To answer "is port 5432 open on this host?", netcat is quicker than telnet and gives a clear yes or no:

nc -vz db.example.com 5432
# Connection to db.example.com port 5432 [tcp/postgresql] succeeded!

-z only checks the connection and -v prints the result. Add -w 3 to give up after three seconds instead of waiting for the system timeout. To type into the connection the way you would with telnet, drop -z:

nc smtp.example.com 25
EHLO test.local

Option 3: curl's telnet mode (also built in)

curl -v telnet://example.com:80

curl prints Connected to example.com when the port answers. Press Ctrl-C to close it.

Services that use TLS

Telnet and nc send plain text. For HTTPS, SMTP on port 465, or IMAP on port 993, they connect but you cannot read anything back. Use openssl (macOS includes it, built on LibreSSL):

openssl s_client -connect example.com:443
openssl s_client -connect smtp.example.com:587 -starttls smtp

Logging in to a remote machine

If you wanted telnet for a remote shell, use ssh. Telnet sends your password in clear text, which is why Apple dropped it. The exception is old network gear or lab equipment that only speaks telnet; for that, the Homebrew package is the right tool.

Sources

related.

Ruslan Osipov

Ruslan Osipov

About the author