PDA

View Full Version : Allow WiFi to start before you log in


DizzyTech
July 16th, 2009, 03:05 PM
I often find myself, despite having a lightning-fast boot with Ubuntu, waiting at my desktop for something to start. I started looking at what I do with my computer, investigating my bottlenecks. One of them was my wireless network. Even though I have a perfectly functional wireless card and I work within mere feet of my router, I often find myself waiting for the wireless to start before opening my web browser.

Background: I recently had a brief stint with Arch Linux due to, well, curiosity. I discovered a very helpful and useful tip when configuring NetworkManager in my Gnome installation. This tutorial is mostly duplication of that, and you may find the Wiki article here (http://wiki.archlinux.org/index.php/NetworkManager).

Most modern Linux distributions include NetworkManager, a very powerful network management daemon. The practical upshot of having NetworkManager in Ubuntu is that you can easily swap between multiple wireless networks, and even between WiFi and ethernet without editing configuration files or using the terminal.

NetworkManager can support automatically unlocking itself and signing in to networks immediately upon the daemon starting. The daemon itself usually starts up even before X and GDM/KDM, so it's running long before you log in. You can use this time to your advantage!

Steps: Still with me?

Make sure you are logged in to the account on your Ubuntu computer that manages wireless networks.
If you don't use encrypted networks or don't have a password on your Gnome keyring, skip ahead to step 5.
Hit Alt+F2. A dialog named "Run Application" will pop up. Enter the following in the dialog, press Enter, and enter your password when asked.
gksudo gedit /etc/pam.d/passwd
A text editor window should open. Skip to the end of the file, and copy and paste the following into a new line at the end of the document. Save and quit.
password optional pam_gnome_keyring.so
Hit Alt+F2. When the dialog "Run Application" pops up, copy and paste the following command into the input box and press enter. If it asks for your password, enter it and hit okay. Nothing else will appear.
gksudo polkit-auth --grant org.freedesktop.network-manager-settings.system.modify --user $USER
Right-click the network icon (if you're on wireless, it should be cellphone-like bars) and hit "Edit Connections...".
http://imgur.com/kr0WQ.png
A "Network Connections" window will pop up. Navigate to the wireless tab.
http://imgur.com/roTK1.png
Select a network that you wish to have connect automatically, and hit "Edit".
http://imgur.com/rqtVF.png
Towards the bottom of the property sheet that comes up, check "Available to all users." Hit Apply. If you are currently connected to this network, the network will disconnect and reconnect.
http://imgur.com/x1vnO.png
Repeat steps 8 and 9 for each network you wish to be able to connect to during boot.
You are done!


From now on, WiFi will immediately start when the NetworkManager daemon does. This is particularly useful if you use the login screen; however, you should also benefit if you automatically login.

Consequences: If your computer is ultra-mobile, or often doesn't stay in the same location, this obviously won't work unless you've been there before. This also opens up WiFi to all users on your computer, but that really shouldn't be an issue.

Undo!: If you wish to undo this hack, substitute the command in step 5 for the following command. As well, redo the steps while unchecking "Available to all users" in step 9.
sudo polkit-auth --block org.freedesktop.network-manager-settings.system.modify --user $USER

jpeddicord
July 19th, 2009, 11:56 PM
Approved; thanks for your Tutorials & Tips contribution.

MontanaMax
July 20th, 2009, 10:50 AM
This looks very cool - is there a similar set of steps anyone is aware of that will work with Kubuntu?

Thanks,
- Jon

DizzyTech
July 20th, 2009, 12:18 PM
I believe KDE (or at least Kubuntu) uses both PolicyKit and NetworkManager.

Steps 3 and 4 are not needed for Kubuntu systems, as this is just a hack to make sure Gnome authenticates your user for wireless keys immediately/ASAP. KDE uses a different method, which may or may not unlock automatically.

As an alternative to step 5, open KDE's terminal and run the following:
sudo polkit-auth --grant org.freedesktop.network-manager-settings.system.modify --user $USER

Enter your password when asked; press enter when done. Note that your password will not show up when typing it in within the terminal.

Attempt to follow steps 6-9 in the same fashion; KDE's NetworkManager should follow a similar set of steps. I don't use it often, so I couldn't answer. If the method mentioned here (Right-click > Edit Connections) doesn't work, attempt to use KDE's normal network management application.

adempewolff
July 21st, 2009, 03:14 PM
I do not log out very often but often suspend (to RAM) and resume and always find myself waiting ~20s for network manager to detect a network and connect. I was hoping this method might speed up that wait a little but it does not appear to. Have I done something wrong or does this method just not apply to resuming from suspend? Thanks!

dawnlove
July 21st, 2009, 04:06 PM
Is there a way to get this to work in xubuntu? many thanx

dawnlove
July 21st, 2009, 04:33 PM
Is there a way to get this to work in xubuntu? many thanx
I got it to work in xubuntu with sudo apt-get install gedit

DizzyTech
July 21st, 2009, 07:14 PM
Unfortunately, the waiting for ~20s and up on resume from suspend is from your wireless card. Some cards like to dump all connection information between suspend/resume. Not much can be done, but I'm hopeful for the future. In addition, if you leave your computer long on enough before unlocking your user account, you probably will be connected again. :D It's just the nature of Wi-Fi and, more accurately, Wi-Fi in Linux.

Yes, this works properly on Xubuntu with an installation of gedit. I intended to make this as user friendly as possible. However, I don't think XFCE uses the Gnome Keyring so the gedit commands are not generally needed. But your mileage may vary.

magh-87
July 21st, 2009, 07:38 PM
Awesome :) Thanks a lot. This is definitely going to speed up my day-to-day routine

adempewolff
July 21st, 2009, 11:32 PM
yeah I figured as much, thanks for the quick reply! The dump is probably for the better--I can just imagine all sorts of bugs and crashes from suspending then moving to another signal and resuming with it trying to talk with the old network. Ok, maybe that wouldn't be too hard to work around but I am determined to see the silver-lining in this cloud!

yuli_capone
July 22nd, 2009, 04:59 AM
Thank's,nery nice!
It's something like this to do with gmail notifier?
When i start my laptop, i am asked for the password...

davidfernando
July 22nd, 2009, 09:13 AM
Thanks for sharing such a nice useful tutorial. Its so easy to understand and it really worked

DizzyTech
July 22nd, 2009, 09:53 AM
Thank's,nery nice!
It's something like this to do with gmail notifier?
When i start my laptop, i am asked for the password...

Do you use autologin? Unfortunately, this is a larger issue with Gnome as a whole... it's keyring (what it stores your passwords in) unlocks automatically if you log in via the login screen, but not if you log in automatically.

There are two workarounds.

First is changing your keyring to have no password:

Open Applications > Accessories > Passwords and Encryption Keys
Click on the Passwords tab.
Right-click "default" and hit "Change password..."
Enter your current password and hit change (leaving new password blank) and confirming any warnings.


The second is disabling the auto-login (Gnome/XFCE only), giving your wireless network more time to autologin while you wait at the login screen thanks to my tutorial ( :P ):

Open System > Admistration > Login Window; enter your password if prompted.
Click to the "Security" tab.
Untick the "Automatic Login" checkbox, and hit "Close."

I leave Timed Login on, but I don't know if it'll still leave the keyring locked. Your mileage may vary.

bfckarlos
April 2nd, 2010, 07:27 AM
OP

Thanks for that, have been trying to sort this out for a while now.
Great!!;)

trusktr
July 29th, 2010, 01:58 AM
It's been about a year since the original post, but i believe the following still applies.

I believe steps 3, 4, and/or possibly 5 are NOT necessary.

I'm on Arch Linux and all I had to do was add my user to the "networkmanager" group (after creating it) and then step 9 (checking "available to all users") and that's it.

After adding you user to the "networkmanager" group, Gnome authenticates your user for wireless keys immediately/ASAP... This is much easier than modifying PAM files and using polkit commands. This feature is built into networkmanager. ;)