LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > w322
User Name
Password

Notices


Rate this Entry

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>
&nbsp;&nbsp;&nbsp;auto eth2 <em>[or your wireless interface designation]</em>
&nbsp;&nbsp;&nbsp;iface eth2 inet dhcp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wireless-mode managed
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wireless-essid HOME-NET
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>
&nbsp;&nbsp;&nbsp;#!/bin/sh
&nbsp;&nbsp;&nbsp;case "${1}" in
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;("start")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Use start option when run from a script at login.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# With this parameter the gui does not run if we are
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# already connected.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Determine if we are connected already
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STATUS=`ifconfig | grep "inet addr" | grep --invert-match "127.0.0.1"`
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if test -z "$STATUS"; then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xhost +local:root
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo /usr/bin/wlassistant
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo Network already connected
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fi
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(*)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Use no options when the user starts this file manually,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# the gui will start even if network is already connected.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xhost +local:root
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sudo /usr/bin/wlassistant
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;;
&nbsp;&nbsp;&nbsp;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):
&nbsp;&nbsp;&nbsp;A. Open konqueror and create <strong>wireless.desktop</strong> by right clicking in <strong>~/.kde/Autostart/</strong>
&nbsp;&nbsp;&nbsp;and selecting "Create new link to application"
&nbsp;&nbsp;&nbsp;B. In properties dialog, under application tab, in "command" box type: <strong>wireless start</strong>
&nbsp;&nbsp;&nbsp;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.

Posted in Uncategorized
Views 3621 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    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 w322 is offline
  2. Old Comment
    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
    And you have to set the permission to executable:

    Code:
    sudo chmod +x [filename]
    Posted 12-31-1969 at 07:00 PM by w322 w322 is offline
 

  



All times are GMT -5. The time now is 07:38 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration