I am trying to use a Mikrotik Router to reboot a Ubiquiti Radio. I know it has to be done using SSH, I have the public and private key installed where they need to be. Here is the command I am using
/system ssh 192.168.1.34 “reboot”
If I go thru the Terminal in the the router and it works. But when I try doing the same thing either in the scheduler or in a script it does not work.
Are user names on both devices the same? If they aren’t, then you have to tell ssh (or ssh-exec) which user to use on remote side.
Come to think: it’s entirely possible that scheduler on MT doesn’t run commands using same user credentials as were used to install the scheduled job. Unlike cron in normal linux machines which runs with individual users credentials. In which case the ssh private/public key being used will likely be different than when running commands interactively.
I figured it out. I am going to put down the procedure here, just incase someone else needs it.
Generate a Key-pair. I had to do this outside of Mikrotik, the ubiquiti radio does not like Mikrotik generated keypair.
ssh-keygen -t rsa -m pem
Then I just went to the users in winbox and then to ssh keys tab and imported the public key (Make sure you are logged into the correct account when you do this, or it will fail when you try to ssh into the ubiquiti radio). Next click on the SSH Private keys and import the private half of the key. (both halves have to be imported or else it will still fail).
Then login to your ubiquiti radio, go the services tab and then to the SSH section and click the edit button. Select your public key file and import it and apply it.
Now in the Mikrotik you can use the following line in a script or scheduler
/system ssh-exec 192.168.1.1 "reboot"
Just make sure to replace the IP Address with the correct one.
My personal failure was in that I did not import the private half of the keypair.
From what I know, and it is not a lot, the scripts that you are trying to use only work on the ppp connection itself, not external things. Where I was using it is in System -> Scripts.