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

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Issue accessing my RT-AC68U using PHP and SSH2

Discussion in 'Routers' started by jpr105, Oct 16, 2018.

Tags:
  1. jpr105

    jpr105 New Around Here

    Joined:
    May 5, 2018
    Messages:
    9
    Hello,

    I need to access my RT-AC68U in SSH. So I configured the router as follows:
    • Enable SSH = LAN Only
    • Allow SSH Port Forwarding = Yes (not sure this is necessary)
    • SSH port = 2222
    • Allow Password Login = Yes
    • Enable SSH Brute Force Protection = Yes
    When I connect from my iMac or Raspberry, everything is normal.
    Code:
    ssh [email protected] -p 2222
    And I can see my connection on the router's log:
    This is fine but I especially want to do it in PHP with LibSSH2.

    So I wrote this code and it does not work.

    PHP:
    $ASUS_IP "IP routeur";
    $ASUS_Port "Port routeur";
    $ASUS_User "User";
    $ASUS_Psw "Password";

    $AsusSSH ssh2_connect ($ASUS_IPintval($ASUS_Port));
    $AsusLogin ssh2_auth_password ($AsusSSH $ASUS_User$ASUS_Psw);

    /* V√©rification de la connexion */
        
    if ($AsusLogin) {
        echo 
    'Connexion SSH effectu&eacute;<br />';
        } else {
        echo 
    'Connexion SSH &eacute;chou&eacute;e<br />';
    }
    RT-AC68U Log
    PHP Log
    Can someone help me please?

    Thank you in advance

    Regards - Jean-Paul
     
  2. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    28,299
    Location:
    Canada
    The log complains about a non-existing user, so that's probably your problem - double check the user.
     
  3. jpr105

    jpr105 New Around Here

    Joined:
    May 5, 2018
    Messages:
    9
    You were right, the problem was on my side and it works now ... I can now connect to my router without problems :)

    The purpose of my PHP script is to turn ON or OFF, "on demand", my 2.4Ghz wifi signal.

    I tested these commands successfully:
    Code:
    wl -i eth1 radio on
    wl -i eth1 radio off
    But before using them, I wonder if there is an easy command to know the state of the radio signal (on or off) before changing it.

    Thanks
     
  4. jpr105

    jpr105 New Around Here

    Joined:
    May 5, 2018
    Messages:
    9
    Hello,

    To complete my last post, I noticed there was no synchronization between the action (wl -i eth1 radio on or wl -i eth1 radio off) and the Web GUI and I do not find this very "clean" :(.

    I found another method on this forum ... is it better?

    Code:
    #get 2,4ghz radio status
    nvram get wl_radio
    
    #turn off 2.4ghz
    nvram set wl_radio = 0
    nvram commit
    restart_wireless service
    
    #turn on 2,4ghz
    nvram set wl_radio = 1
    nvram commit
    restart_wireless service
    
    #get 5ghz radio status
    nvram get wl1_radio
    
    #turn off 5ghz
    nvram set wl1_radio = 0
    nvram commit
    restart_wireless service
    
    #turn on 5ghz
    nvram set wl1_radio = 1
    nvram commit
    restart_wireless service
    Thanks
     
  5. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    28,299
    Location:
    Canada
    Yes, as that would be done at the firmware level, rather than poking directly at the radio level (where it might leave you with out of sync settings as you've noticed).

    Note however that for 2.4 GHz, the correct variable is wl0_radio, not wl_radio.
     
  6. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    6,775
    Location:
    UK
    Your nvram set command produces a syntax error because it has spaces in it and you are restarting the wireless incorrectly. Use something like this:
    Code:
    #turn off 2.4ghz
    nvram set wl0_radio=0
    nvram commit
    service restart_wireless
    I presume you mis-copied those commands from here: https://www.snbforums.com/threads/turning-off-wireless-in-merlin.32264/#post-437984
     
  7. jpr105

    jpr105 New Around Here

    Joined:
    May 5, 2018
    Messages:
    9
    Thanks a lot @RMerlin and @ColinTaylor,

    I think I have everything I need to succeed in my project.

    I test and come back to post my solution if it can help someone else.

    Thanks again.

    Regards - Jean-Paul