Auto connect to wireless network without sudo privileges
Posted 09-09-2006 at 08:33 PM by w322
How I got my notebook to connect to my wireless network for users without sudo privileges. I'm using Kubuntu 6.06.
<!--break-->
1. You should have <strong>/etc/network/interfaces</strong> configured for automatic network connection. It should contain something like this:
<code>
auto eth2 <em>[or your wireless interface designation]</em>
iface eth2 inet dhcp
wireless-mode managed
wireless-essid HOME-NET
wireless-key1 XXXXXXXXXX
</code>
2. If you visit a new location, such as a coffee shop, you can set things up so that a normal user can connect without having sudo privileges.
Create a script named /usr/local/bin/wireless:
<code>
#!/bin/sh
case "${1}" in
("start")
# Use start option when run from a script at login.
# With this parameter the gui does not run if we are
# already connected.
# Determine if we are connected already
STATUS=`ifconfig | grep "inet addr" | grep --invert-match "127.0.0.1"`
if test -z "$STATUS"; then
xhost +local:root
sudo /usr/bin/wlassistant
else
echo Network already connected
fi
;;
(*)
# Use no options when the user starts this file manually,
# the gui will start even if network is already connected.
xhost +local:root
sudo /usr/bin/wlassistant
;;
esac
</code>
After creating, set executable permission: sudo chmod +x wireless
Note: This script is to be run by user, no need to run sudo.
3. sudo edit <strong>/etc/sudoers</strong> and add the following line at the end:
<code>
%users ALL = NOPASSWD: /usr/bin/wlassistant
</code>
Be Careful! If you make mistakes in /etc/sudoers all users could lose sudo privileges!
This allows members of the <strong>users</strong> group to sudo run wlassistant without a password. I add all the users of my notebook to the <strong>users</strong> group.
4. To bring up a dialog at login when no networks are found (In KDE):
A. Open konqueror and create <strong>wireless.desktop</strong> by right clicking in <strong>~/.kde/Autostart/</strong>
and selecting "Create new link to application"
B. In properties dialog, under application tab, in "command" box type: <strong>wireless start</strong>
in "name" box type: <strong>wireless</strong>
5. Create a menu entry for Wireless Lan Startup with the command: <strong>wireless</strong>
this may also be added to the system tray.
<!--break-->
1. You should have <strong>/etc/network/interfaces</strong> configured for automatic network connection. It should contain something like this:
<code>
auto eth2 <em>[or your wireless interface designation]</em>
iface eth2 inet dhcp
wireless-mode managed
wireless-essid HOME-NET
wireless-key1 XXXXXXXXXX
</code>
2. If you visit a new location, such as a coffee shop, you can set things up so that a normal user can connect without having sudo privileges.
Create a script named /usr/local/bin/wireless:
<code>
#!/bin/sh
case "${1}" in
("start")
# Use start option when run from a script at login.
# With this parameter the gui does not run if we are
# already connected.
# Determine if we are connected already
STATUS=`ifconfig | grep "inet addr" | grep --invert-match "127.0.0.1"`
if test -z "$STATUS"; then
xhost +local:root
sudo /usr/bin/wlassistant
else
echo Network already connected
fi
;;
(*)
# Use no options when the user starts this file manually,
# the gui will start even if network is already connected.
xhost +local:root
sudo /usr/bin/wlassistant
;;
esac
</code>
After creating, set executable permission: sudo chmod +x wireless
Note: This script is to be run by user, no need to run sudo.
3. sudo edit <strong>/etc/sudoers</strong> and add the following line at the end:
<code>
%users ALL = NOPASSWD: /usr/bin/wlassistant
</code>
Be Careful! If you make mistakes in /etc/sudoers all users could lose sudo privileges!
This allows members of the <strong>users</strong> group to sudo run wlassistant without a password. I add all the users of my notebook to the <strong>users</strong> group.
4. To bring up a dialog at login when no networks are found (In KDE):
A. Open konqueror and create <strong>wireless.desktop</strong> by right clicking in <strong>~/.kde/Autostart/</strong>
and selecting "Create new link to application"
B. In properties dialog, under application tab, in "command" box type: <strong>wireless start</strong>
in "name" box type: <strong>wireless</strong>
5. Create a menu entry for Wireless Lan Startup with the command: <strong>wireless</strong>
this may also be added to the system tray.
Total Comments 2
Comments
-
Hello, I am new to the forums, am a linux newbie (SuSe 10) - I did a search here in the forums but I'm not sure this applies or not to my situation. I am not having trouble getting connected to my wireless at home, I have a Linksys wireless card and I installed ndiswrapper - however, to get internet to work each time, I open up Konsole and su root, then iwconfig ESSID, iwconfig key, then dhcpcd wlan0 --- I'd like to write some sort of script that will run at start-up, as a regular user, or somehow runs as my root account, so that when I boot up my system I will already have my wireless configured and I can avoid all the manual steps I do in Konsole every time I turn on my computer. I'd tried a few different things but I lack a basic understanding of the file system ( a friend installed this for me ) - one was to write a bash file but when it "runs" nothing happens.
I'd like some help with this, from a very newbie-linux standpoint, because like I said, I don't have any idea about the file system or writing batch files and need to start at the ABCs, so to speak.
Thanks in advance to anyone willing to tackle this and mentor me through this process.Posted 12-31-1969 at 07:00 PM by w322 -
There are many Linux shell tutorials. One I found is http://steve-parker.org/sh/sh.shtml
Be sure to put this as the first line of your script, it tells Linux to execute the file as a script:
Code:#!/bin/sh
Code:sudo chmod +x [filename]
Posted 12-31-1969 at 07:00 PM by w322