Community discussions

MikroTik App
 
jonah1810
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 69
Joined: Tue Jul 30, 2019 10:19 pm

How to use output from ssh-exec?

Mon Jun 21, 2021 7:18 pm

EDIT: first problem was solved I changed the name of the title to match the problem i now have instead of making a entire new thread. I will keep the original issue in case somebody might have a similar issue
My issue now is i cant get ssh-exec's output set as a variable.


Hello I am trying to set up a SSH key on my mikrotik to login to my linux server to run commands and am completely stumped.

I created a key in my linux server with
"ssh-keygen -t rsa -m PEM"
saved to default location
no password
saved the public key as the "/root/.ssh/authorized_keys files
and imported the set of keys as a private key in my mikrotik.
But when I SSH into linux machine it still asks for a password.
when i turn off password authentication in the ssh server mikrotik just fails to connect it seems.

what am I doing wrong? all the wikis seem to only talk about connecting to a mikrotik through a remote machine. not the other way around.
Last edited by jonah1810 on Mon Jun 21, 2021 11:22 pm, edited 2 times in total.
 
jonah1810
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 69
Joined: Tue Jul 30, 2019 10:19 pm

Re: How to Login to Remote linux server via mikrotik SSH key?

Mon Jun 21, 2021 11:12 pm

Figured it out the issue was i was trying to login as root but that was set to no. I changed it so only with the key I can login as root.

But im having issues getting values from my server heres what i have:
:set $name value=[system ssh-exec address=10.100.97.213 user=root command= \ 
"mysql freeradius -e \"SELECT CONCAT(firstname, ' ', lastname) AS 'Full Name' FROM userinfo WHERE username = '$mac';\""]
it returns
exit-code 0
     output: Full Name
                      John Test
which returns just fine. But the variable is still blank. so it didnt use the output.

How do I use the output of ssh-exec?
 
jonah1810
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 69
Joined: Tue Jul 30, 2019 10:19 pm

Re: How to use output from ssh-exec?  [SOLVED]

Tue Jun 22, 2021 5:53 am

:set $Query value=[:put ([/system ssh-exec address=10.100.97.213 user=root command= \
("mysql freeradius -e \"SELECT username, '@split', CONCAT(firstname, ' ', lastname) AS 'Full Name' FROM userinfo;\"") as-value]->"output")]
to save output as variable!

Who is online

Users browsing this forum: cbialekskyvista, Google [Bot] and 11 guests