SSH Out Of Router

Hi.
I am trying (via a script) to get the router to connect to an external server via SSH, without success.
Is there anything obvious I need to do to get this to work?

Here is the ssh command.
ssh -T ${PORT:+ -p $PORT}${KEY:+ -i $KEY} “${USER}@${SERVER}”

Yes, I did specify values for the port and server etc.

Thanks,
Glitch

There is a parenthesis issue with the variables eg: ${PORT} and ${KEY}

I’m not sure what the + 's are for. So I cannot help there. If you could give more detail as to what your trying to do it would help.

try:

ssh -T -p ${PORT} -i ${KEY} “${USER}@${SERVER}”

Does the router has a public IP address? Did you open the SSH port?

  1. No (it’s connected to my main router under WISP).
  2. No, (that was partly what I was asking / how do I do that?)

@nopro404 Another way of writing the command is

ssh -T -p $port -i $KEY

Yes, but case matters . $port and $PORT are different.

Per the Google best practices for shell scripts constants and environment variables should be uppercase to show their significance.

https://google.github.io/styleguide/shell.xml#Constants_and_Environment_Variable_Names

Variables used for iteration should be lowercase.

All variables should be wrapped in curlies and quoted so expansion works in all cases. This was a bug in the startvpn script causing VPN files with spaces to not work correctly.

If you are SSH’ing OUT of the router to a publicly accessible server you dont need to open a port - only for SSH’ing INTO the router.

How does:

port=1111 differ from PORT=1111 and
$port from $PORT ?
It doesn’t as far as I know, so that isn’t the problem!

Regarding the port number, I assumed that was the port I was logging into (since the username and password are for that purpose)?

variables are case sensitive:

root@GL-AR300M:~# port=1
root@GL-AR300M:~# PORT=2
root@GL-AR300M:~# echo $port $PORT
1 2

the -i option is for a file name of the public key to use not your password or ‘key’ if that helps.

Regarding the port number, I assumed that was the port I was logging into (since the username and password are for that purpose)?

I’m not sure what this means. 22 is the default ssh port - unless you’r doing something different.

I am logging into a remote server so assumed the port I specify is for that (just as when you use a VPN server, it has a port number? eg. 443, 1194 etc.).

Yes - SSH servers by default listen on port 22. If it is 22, you don’t need to specify it, it will default to it.

Keep in mind that Dropbear (SSH Client/Server) is installed by default… and it, like BusyBox, can behave different…

OpenSSH-Client is in the repo if I recall correctly - which might be helpful if porting scripts from other non-embedded platforms.