Script to create SSH tunnel to externl server

I need to write script to create SSH tunnel from the router to an external server with dynamic port forwarding. I faced issues with the router accepting the private key, I have tried both PPK and OpenSSH format for the key without success.
I need also a script that will divert all router traffic to the dynamic port either by creating a SOCKS proxy or otherwise, thus diverting all the traffic to the external server.
BTW I am usind RB2011 MikroTik router.

Hello, I have same problem in mikrotik 951g-2hnd. Need to redirect some packets to ext. socksv4 server. You won this problem?

you cannot SSH to another server from scheduler.