How to check/adjust SSH server on embedded board

Posted on

Problem :

I’m currently having difficulties connecting to an embedded board from my Linux machine through ssh. The embedded board is a FOX G20 V with a Linux OS. I’ve tried to connect to the board through several ports, I have followed all the solutions online regarding firewall, public/private keys and iptables configuration. Nevertheless, I always get the error message

connect to host port 22: Connection refused

This got me thinking, perhaps I need to check the ssh status on the embedded board and to check what port it’s listening on. But since I can’t even connect to the board to check this information out, I’m stuck. For what it’s worth, I am able to ping to the board.

Does anyone therefore have a solution as to how I can check the ssh status?

Solution :

Judging from your question, it appears the board is not under your control, otherwise you would know (I presume) which port ssh is listening on, if at all.

If this is indeed the case, then nmap is your only friend (or some other scanner, of course). My suggestion is to do a heavy scan:

  sudo nmap -T5 -A -p1-65535 ip.address.of.board

The flag -T5 reduces the time interval between probes, which should not be a worry for you (you are not trying to go undetected, are you?). The -A flag introduces a number of tests performed through scripts, which may also prove useful. The -p1-65535 makes sure you test all ports, not just the lowest-numbered ones.

This will tell you, except in the presence of elaborate evasive action (port knocking, anyone?), whether an ssh service is listening at all, and on which port.

Of course this implies you are checking on TCP ports, which is the correct choice if you are investigating a possible ssh service. However, most people forget that an nmap scan does not, by default, scan UDP ports; once again, this is irrelevant for ssh, but just for the sake of completeness, if you were trying to do the same for OpenVPN, you would have to issue the command:

 sudo nmap -sU -T5 -A -p1-65535 ip.address.of.board  

nmap of course(i.e. do a port scan). nmap -P0 -p1-65535 5.6.7.8 (where 5.6.7.8 is the ip) maybe somebody has a better idea or better parameters. That -P0 makes it work even if you didn’t get a ping response. and scanning all those ports (1-65535) at once may be a bit slow(or perhaps ok on a LAN)

added
-v is an excellent switch, it makes nmap show the results as it progresses. that is very fast. nmap -v -P0 -p1-65535 5.6.7.8 (and perhaps you may find -T5 as marius suggests makes it faster)

added
as to the other aspect of your question, how to adjust the ssh server port, I haven’t checked to see if it’s possible to edit sshd_config while logged in but that’d be a path to try. You open sshd_config (it’s within /etc e.g. /etc/ssh/sshd_config and it will say e.g. Port 22 so you make a new line and type Port 12345, then restart the system or the sshd server. and (you can use nmap and test your two ports eg 22 and 12345) so see you still have port 22 and that you get the additional port. That(adding an additional port) seems safer than adjusting the one port it is on because if that goes wrong you’ve locked yourself out. You can always edit again and remove a port. Hopefully sshd_config doesn’t lock while logged in, give it a try and report back. Hopefully some know some other ways as it’s always good to have multiple methods.

Leave a Reply

Your email address will not be published.