Ping Equivalent for Ssh

Ping Equivalent for Ssh

Is there an equivalent to running ping $HOST but for the ssh daemon? Just to check if it's running, no attempt to log in as a specific user or validate with credentials

Something like

DAEMON_UP=$(sshping $HOST | process_output)

1

3 Answers

I usually use nc (netcat) for this:

$ nc -zv 127.0.0.1 22
localhost [127.0.0.1] 22 (ssh) open

The -z option is "zero-I/O mode" specifically for scanning.

The -v option means "verbose" and actually causes the output to be generated; without this option only the exit status will indicate whether the port is open or not (0 = yes, 1 = no). This makes it easy to use this in scripting:

if nc -z 127.0.0.1 22; then
    echo "ssh daemon is listening on port 22"
else
    echo "ssh daemon is not listening on port 22"
fi

one way is to use nmap (in the example below I checked if port 22 was open on localhost)

nmap -p 22 127.0.0.1

how about telnet ?

telnet [IP or hostname] port

example

telnet myhost 22
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.