1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Disable SSH using Cron

Discussion in 'Tomato Firmware' started by ImGeo, Mar 31, 2010.

  1. ImGeo

    ImGeo Addicted to LI Member

    Is there some command to disable(/enable) SSH (dropbear) over cron?
    I've looked at the section on SSH and have a general idea of cron (from looking at FAQ), but didn't find any commands or a way to start/stop SSH.

    I know it can be done via GUI, but I want to run a script to disable SSH every 4AM (for times when I forget to disable it after I'm done using it).
     
  2. ImGeo

    ImGeo Addicted to LI Member

    Well, the progress I made so far is to figure out how to start it (basically, just run "dropbear", or more specifically (derived from "ps") "dropbear -p 22 -a").

    but I still havn't figured out how to stop it. "ps | grep dropbear" does return something useful like:
    1084 root 940 S dropbear -p 22 -a
    1135 root 1456 S grep dropbear
    and I can run "kill 1084", except that I need to somehow pass 1084 (which can really be any number) to kill...

    any help?

    EDIT::

    from reading dropbear's info, I found out that it saves the PID to:
    /var/run/dropbear.pid , and inside that is the PID, just plain "1084"
    so .... how do I use that?
     
  3. mstombs

    mstombs Network Guru Member

    You can use pidof(), but "killall dropbear" should kill all.
     
  4. rhester72

    rhester72 Network Guru Member

    I haven't tested it, but something along the lines of "service ssh stop" or "service sshd stop" _may_ also work.

    Rodney
     
  5. ImGeo

    ImGeo Addicted to LI Member

    Thanks! This works. @rhester72, I tried both, but it ddin't work.

    Now... my cron doesn't work properly:
    # cru l
    00 4 * * * killall dropbear #KillDropBear#

    that should run every 4:00AM, right? well it's not 4am, so I wrote a cron that's 1 minute ahead of the current time (shown in the router overview page), and it never killed dropbear (ps | grep dropbear)
     
  6. mstombs

    mstombs Network Guru Member

    Do you have to use full path for dropbear and killall? I recall cron doesn't assume path?
     
  7. ImGeo

    ImGeo Addicted to LI Member

  8. ImGeo

    ImGeo Addicted to LI Member

    YAY!
    I think cron/cru does work.

    # cru a test "45 12 * * * dropbear -p 22 -a"
    # ps | grep dropbear
    # killall crond
    (restart crond, to reload config, incase it's necessary)
    (shows nothing)

    after 12:45
    # ps | grep dropbear
    (shows dropbear)

    Problem is, when I restart the router, my cron jobs are gone :(
     
  9. ringer004

    ringer004 LI Guru Member

    Use the web GUI

    You can create cron jobs that stick via the web interface:

    Look under Administration -> Scheduler -> Custom 1,2,3
     

Share This Page