Easy automatic wifi connections on headless computers with no logged in users.
This is here just so it's easy for me to get. I only use it for psk but it shouldn't be hard to use it with other authentication schemes.
Scripts go right here.
AP custom configurations and custom shell scripts go in custom.d For now, shell scripts just have naming conventions. Later we may change that to have subdirectories under custom.d for overriding wifi-up behavior at different parts of the script.
- Install network-manager (nmcli, nm-applet, the network manager daemon, etc).
- Copy the wifi* scripts somewhere (e.g., /usr/local/bin/easy-wifi).
- Make the scripts executable.
- For each network you want to connect to, create files in config.d that contain the psk for that network:
- files should be named after the ssid you're connecting to (no extension unless ssid has a period in it)
- the file should contain one line like this 802-11-wireless-security.psk-:[thepassphrase with no brackets] ** ^^^ e.g., see config-example although you'd put that in the config.d directory.
- Set up a system to automatically call wifi-up. I prefer to do that in cron so that if the connection goes down it'll come back up automatically.
- wifi-status to see if you're connected
- wifi-up to bring it up
- wifi-down to bring the current connection down (it looks at wifi-status.sh to figure out what its connection is).
Normally, for wifi connections, you'd just use the nm-applet GUI to set up your wifi connections. I use these scripts for little computers (odroid, raspberry pi, etc) that normally run headless. The little computers normally don't have GUIs and I don't want to start vnc server and bring up the wifi via nm-applet that way. That doesn't work very well around reconnecting anyway.
Alternatives would be wicd or wpasupplicant. I use nmcli because the command lines and the configuration files are very simple.
I often use the headless device as a remote access computer on a client's network so I want it to reconnect to the wifi if the connection goes down. So wifi-up would be called from cron to run every minute (or every few minutes).
-
-
-
-
- root /usr/local/bin/easy-wifi/wifi-up.sh
-
-
-
If you don't have a VPN connection with a static IP it may also be helpful to have some cron job (e.g., a curl to some web server whose access log you can view, or that you can tcpdump for) that will send some traffic that you can inspect to determine what the IP address of the device is.
-
-
-
-
- root curl "http://[your-server]/ping_i_am_[this_hostname]/"
-
-
-
You won't need that if you have a monitor, keyboard and mouse connected to your device.
The wifi-up.sh script will scan the local network for SSIDs and for each one it sees, will look to see if there is a file (in the same directory as wifi-up.sh) that has the same filename as the SSID. If there is one, it'll use that as the file parameter (containing the psk) and will connect to the wifi accesspoint.
The scripts are very simple-minded. They assume there is only one wifi device and will connect to the first network that has a corresponding psk file on disk. If you need something more complicated this might not be for you (or you can add some smarts to it).