I have an embedded system that is running Debian. I want to be able to provide wifi network SSID and password information via a USB thumb drive. That way I can easily deploy it to any wifi network.

Would it be possible at boot up to have a script read the wifi SSID and password from the USB drive and automatically connect to the wifi network? Anybody have a script to do this?

Is there a better way to accomplish this?

1 Answer 1


Here's an idea using Perl to execute the script for you. You could translate this to your language of choice, or probably even bash. It's really the commands to connect to the wireless that count. Perl is just a means for me to do this quickly, your idea of quick may be different. A note if you're not used to reading Perl everything backticks is a shell command.

Gnome, for example, has built in handling of remembering your networks, and will do this for a logged in user, but... I'm assuming a headless setup. Which is kind of fun, a roving headless setup that will automatically connect to wifi. Cool.

This assumes a wpa network, and iwconfig installed (which I'll bet comes with your wireless packages), and wpa_supplicant.

This accounts for only one network defined in a csv. And assumes that it will work on the first try. You'll need to flesh it out with the actual parameters for the desired networks, or add other handling. But, this general structure will do it for you quickly.

File @ /mnt/usb/network.csv in the format "target SSID,passphrase":


File @ /home/me/connect.pl (with chmod 755 for example):

# Set to your device name.
$iface = "wlan0";

# Set to your USB mount point & network definition CSV file.
$networkdefinition = "/mnt/usb/network.csv";

# Get the contents of your file on USB stick.
$line = `cat $networkdefinition`;

# Read the CSV into parts.
@parts = split(/,/,$line);

# Get a list of wireless networks in range.
# And grep that for the network we're looking for.
$foundnetworks = `iwlist $iface scan | grep 'ESSID:"$parts[0]"'`;

# See if this turns up the network we're looking for
if (length($foundnetworks)) {
        # It did. Let's bring up that interface.                    
        `wpa_supplicant -B -i $iface -c <(wpa_passphrase $parts[0] $parts[1])`;
} else { 
        # Network not in range, perform error handling etc.

In your crontab:

@reboot /home/me/connect.pl


  • Needs better error handling / a way of running more regularly
  • Needs handling of other networks other than WPA
  • Cron solution assumes mount will be available by then.

That's the fun stuff to extend as you go along, but, could be a quick way to boot up using the USB stick CSV file to specify your wifi network.

The real meat of this are these two commands:

  • iwconfig
  • wpa_supplicant

The rest is just really an idea on how to implement your proposed solution to automatic connection to a wifi ap.

  • Thanks a lot! I will use this as a start to develop the script.
    – sizzle
    Commented May 14, 2013 at 19:58
  • No problem!! Out of curiosity, is it a Raspberry Pi? Debian + Embedded linux is sounding very Pi-ish. Cool idea on the autoconnect, fun one to help with.
    – dougBTV
    Commented May 14, 2013 at 20:13
  • Good guess. Yes it is.
    – sizzle
    Commented May 15, 2013 at 16:24
  • 1
    +1 You might want to couple this with an entry in /etc/fstab to ensure your thumb drive is always mounted at the same mount point. I wouldn't rely on automounting for this because you may have some other USB stick plugged in that grabs the mount point you're relying upon.
    – Joseph R.
    Commented May 23, 2013 at 18:50
  • 1
    @szielenski Third suggestion, if you're conversant with udev,save the Perl script on your thumb drive and write a udev rule that would mount your drive at a specified point and run the script off it as soon as it's connected.
    – Joseph R.
    Commented May 23, 2013 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .