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)
3 Answers
I usually use nc (netcat) for this:
$ nc -zv 127.0.0.1 22
localhost [127.0.0.1] 22 (ssh) openThe -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] portexample
telnet myhost 22 2