How to autorun wpa_supplicant on Debian startup

19,092

If your goal is to get your wireless interface configured on startup (vs. putting the wpa_supplicant command in a script for other reasons), you can use /etc/network/interfaces and the ordinary config file wpa_passphrase generates to achieve this result.

In /etc/network/interfaces (assuming wlan0 is your wireless interface and the config from wpa_passphrase is in /root/your-wpa.conf):

allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /root/your-wpa.conf

On my system I have a tab (not spaces) at the start of the "wpa-conf" line. Had trouble entering a tab for the web when typing this response. Not sure if that matters.

I did not need to edit or do anything to the WPA conf file. It is what I get from the command

wpa_passphrase myssid mysecret >wpa.conf

See How to use a WiFi interface on Debian.org and /usr/share/doc/wpasupplicant/README.wpa_supplicant.conf.gz locally.

I tested this on Jessie and no longer have any Squeeze systems left - but I imagine you have upgraded in the 4 years since asking the question.

Share:
19,092

Related videos on Youtube

Dr Kitty
Author by

Dr Kitty

Updated on September 18, 2022

Comments

  • Dr Kitty
    Dr Kitty over 1 year

    I'd like to run wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant.conf on Debian startup (runlevels 2-5). I found some vague instructions from a related question that said to put a script in /etc/init.d/ and then symlink to it from the apropriate /etc/rcRUNLEVEL.d/ directories. However, I noticed that there are already some files named "wpasupplicant" that probably run at startup:

    /etc/network/if-down.d/wpasupplicant

    /etc/network/if-post-down.d/wpasupplicant

    /etc/network/if-pre-up.d/wpasupplicant

    /etc/network/if-up.d/wpasupplicant

    They all are symlinks to the same script, /etc/wpa_supplicant/ifupdown.sh. It has a comment at the beginning saying it "[...] allows ifup(8), and ifdown(8) to manage wpa_supplicant(8) and wpa_cli(8) processes running in daemon mode." However, the closest it gets to calling wpa_supplicant itself is (in functions.sh):

    WPA_SUP_BIN="/sbin/wpa_supplicant"
    [snip]
    start-stop-daemon --start --oknodo $DAEMON_VERBOSITY \
        --name $WPA_SUP_PNAME --startas $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE \
        -- $WPA_SUP_OPTIONS $WPA_SUP_CONF
    [snip]
    start-stop-daemon --stop --oknodo $DAEMON_VERBOSITY \
        --exec $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE
    

    Does that mean it's safe to make an init.d script for wpa_supplicant, and if so what would it look like?

    General info:

    • Debian Squeeze (5.0)
    • official wpasupplicant package (v0.6.10-2.1)

    The full contents of my system's functions.sh and ifupdown.sh are here (dependent, of course, on my system's uptime—it's a five-year-old laptop that greatly enjoys overheating):

    functions.sh

    ifupdown.sh