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

Change WPA/WPA2 Password from shell

Discussion in 'Tomato Firmware' started by jbaker6953, Sep 19, 2010.

  1. jbaker6953

    jbaker6953 LI Guru Member

    Change WPA/WPA2 Password from script

    I want to create a script that changes the WPA2 password every night. It's easy to change the NVRAM values, but I can't figure out the proper way to restart whatever needs to be restarted to pick up the new password.

    So now I have something like this in one of the custom schedulers:

    wpa_pass = nfjwe0a789n
    nvram set wl0_wpa_psk=$wpa_pass
    service nas restart
    It is not working. Any help?

  2. mstombs

    mstombs Network Guru Member

    remove the spaces round the first "=" ?
  3. jbaker6953

    jbaker6953 LI Guru Member

    Thanks for your reply. That's just a typo. Running ...

    nvram get wl0_wpa_psk
    shows the proper password. However, I can still connect to the wireless using the "old" password and not the new one in nvram. Something else needed to be restarted and I'm not sure what it is.

    EDIT - I also tried setting both wl0 and wl_wpa_psk and restart nas, udhcpd, and dnsmasq to no avail.
  4. TexasFlood

    TexasFlood Network Guru Member

    Need an nvram commit?
  5. jbaker6953

    jbaker6953 LI Guru Member

    So I tried stopping the nas service, and then making /etc/nas.conf read:

    nas -P /var/run/nas.pid -l br0 -H 34954
    -i eth1 -A -m 128 -k [password] -s [SSID] -w 4 -g 3600
    Still no good.
  6. jbaker6953

    jbaker6953 LI Guru Member

    Does it? It doesn't need to commit when I do it from the GUI. I have Tomato set to avoid commits, but I'll try it. What the heck.

    EDIT - Still no dice.
  7. jbaker6953

    jbaker6953 LI Guru Member

    I think I found my problem. nas isn't a service. After "service nas stop" it's still running. So I bet it isn't really restarting.

    Manually running nas from the command line with the appropriate parameters works. So now I need to know the command to make nas read the /etc/nas.conf file and run as a daemon.
  8. TexasFlood

    TexasFlood Network Guru Member

    Wasn't really sure, grasping at straws, :wink:. Probably do to make it stick through a reboot though.
  9. TexasFlood

    TexasFlood Network Guru Member

    Here is a little script from way back that I created to restart nas on tomato when apparently I was having problems with it dying on me. The basic syntax should still work, although may vary depending on which build you use.
    # checknas script TexasFlood May 2007, run from /tmp, run periodically from cron as needed
    if ! ps | grep [n]as; then
    nas /etc/nas.conf /var/run/nas.pid lan&
  10. jbaker6953

    jbaker6953 LI Guru Member

    I was just coming back to post what worked for me.

    kill `cat /var/run/nas.pid`
    nvram set wl0_wpa_psk="$wpakey"
    nvram set wl_wpa_psk="$wpakey"
    echo -e "nas -P /var/run/nas.pid -l br0 -H 34954\n-i eth1 -A -m 128 -k $wpakey -s [ssid] -w 4 -g 3600" > /etc/nas.conf
    nas /etc/nas.conf /var/run/nas.pid lan &

Share This Page