Reboot over ssh

8,449

Solution 1


What is your shell when you log in as root?
If it is indeed bash, then you can probably try:
ssh root@routerip /bin/bash -c "/sbin/reboot"

Note that from a security perspective, enabling root login over SSH is a bad idea. You should check the vendor documentation to see if you can fix that.

Solution 2

Try entering the full path to the reboot or shutdown command. For example, if the full path to reboot is /sbin/reboot, run

ssh root@routerip /sbin/reboot

Share:
8,449
LecauseAndThePi
Author by

LecauseAndThePi

Updated on September 18, 2022

Comments

  • LecauseAndThePi
    LecauseAndThePi almost 2 years

    I'm trying to reboot a Teltonika RTU950 using ssh.

    I can log in as root via ssh and then reboot the router fine. However if i try to send the reboot command over ssh it does not work.

    ssh root@routerip 'reboot'
    

    This returns the error:

    ash: reboot: not found
    

    I've tried using shutdown -r instead. Also tried using absolute path. Always gives me the same error.

    To be noted that the error says: ash: and not bash:.

    The router runs on a linux os. uname gives:

    Linux Teltonika-RUT950.com 3.18.44 #1
    

    Any idea what could be causing this?

  • LecauseAndThePi
    LecauseAndThePi almost 6 years
    Thanks for the suggestion. I've tried that already. Same result unfortunately.
  • Kusalananda
    Kusalananda almost 6 years
    @LecauseAndThePi While logged into the host interactively, use command -v reboot to get the path for the reboot command, then use that in your ssh call.
  • LecauseAndThePi
    LecauseAndThePi almost 6 years
    i got the full path using which . Tried again with command -v to make sure and it's the same 'sbin/reboot/'
  • Kusalananda
    Kusalananda almost 6 years
    @LecauseAndThePi It is unlikely that the path is sbin/reboot and more likely that it's /sbin/reboot with a / at the start.
  • LecauseAndThePi
    LecauseAndThePi almost 6 years
    Yeah that's correct. Just bad typing on my part
  • LecauseAndThePi
    LecauseAndThePi almost 6 years
    Thanks for the tip. Still doesn't work. To be noted, the error says 'ash: reboot: command not found' . it is not 'bash'
  • LecauseAndThePi
    LecauseAndThePi almost 6 years
    THANK YOU. You inherently helped me to get this to work. The shell is actually ash, not bash, even when i ssh interactively. So the command i should use, and works is: ssh root@routerip "/bin/ash -c /sbin/reboot"