Author Topic: Sudo without passwd  (Read 9541 times)

0 Members and 8 Guests are viewing this topic.

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Sudo without passwd
« on: February 01, 2013, 07:57:56 pm »
Sup pals. I had a quick bash question about permissions. I wrote a wifi connect script because I scrapped networkmanager for a manual connection, but I didn't really want to have to enter all the commands at startup. It executes just fine but it asks for a password before it executes, which I don' t like. Now, I've added commands to the sudoers file before but for some reason it doesn't seem to want to work with custom scripts. Here's what I made:

Code: [Select]
#! /bin/bash

# Bring up the WiFi interface
sudo ip link set wlan0 up

# Tell wpa_supplicant to use WEXT and associate with SSID
sudo wpa_supplicant -B -Dwext -i wlan0 -c /etc/wpa_supplicant.conf
sleep 5

# Get an IP
sudo dhcpcd wlan0

# Verify
ip addr show wlan

What can I do so that it doesn't ask me for a password? I've googled but nothing seems to fit my particular needs. Thanks.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Sudo without passwd
« Reply #1 on: February 01, 2013, 08:17:27 pm »
Hey lucid,

Whatsup ?

Either add yourself to the wheel group ; https://wiki.archlinux.org/index.php/Users_and_Groups

Or do as I did;
UsErnAme ALL=(ALL) NOPASSWD: ALL

This way you need to use sudo however it will never ask for password.
Really convinient.
Not really secure though.


Or a totally different approach would be to make sure its executed at boot time on a differnt runlevel.
See: https://wiki.archlinux.org/index.php/Initscripts/runlevels


Let me know if it worked out.
Greetings Proxx.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline DaNePaLI

  • Peasant
  • *
  • Posts: 55
  • Cookies: 12
  • Forever n00b
    • View Profile
Re: Sudo without passwd
« Reply #2 on: February 01, 2013, 08:18:13 pm »
I do not have particular idea of this but what you could possibly do is append the line below:

Code: [Select]
%sudo ALL=NOPASSWD: ALL
which would then not ask password from all the users who can sudo. Or, you could do that per user:

Code: [Select]
user_name ALL=(ALL)NOPASSWD: ALL
Just be sure to use visudo to do so as I'm not entirely sure about the syntax.

Alternatively, you could save your script somewhere and try doing this, this is file-specific so might suit you better:

Code: [Select]
user_name  ALL=(ALL) NOPASSWD: /home/username/wifi_script
Make sure you use the sudo visudo command to edit the /etc/sudoers because I am not 100% sure about the syntax I've just written & I'm too lazy to test them :P
« Last Edit: February 01, 2013, 08:23:34 pm by DaNePaLI »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #3 on: February 01, 2013, 08:20:52 pm »
Unfortunately I've already done this in /etc/sudoers. The first thing it does is ask for a passwd when I execute the script still :/. I'll do some more tweaking but I'd rather not have sudo never ask for a passwd.

Also proxx that link you gave me only works with initscripts. I've switched to systemd. Thanks for the quick replies though.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Sudo without passwd
« Reply #4 on: February 01, 2013, 08:24:41 pm »
Are you editing with visudo ??

Also logout and login.
« Last Edit: February 01, 2013, 08:26:57 pm by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline fluxdaemon

  • Peasant
  • *
  • Posts: 104
  • Cookies: -7
  • Galatians 2:20
    • View Profile
Re: Sudo without passwd
« Reply #5 on: February 01, 2013, 08:37:21 pm »
Try putting

USER_NAME HOST_NAME= NOPWASSWD:

in your sudoers file and anything after the colon put whatever commands you don't want to ask for a password


« Last Edit: February 01, 2013, 08:38:10 pm by fluxdaemon »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #6 on: February 01, 2013, 08:39:48 pm »
Wait, how come even if I do EDITOR=nano sudo visudo it still seems to be editing with vi?
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline DaNePaLI

  • Peasant
  • *
  • Posts: 55
  • Cookies: 12
  • Forever n00b
    • View Profile
Re: Sudo without passwd
« Reply #7 on: February 01, 2013, 08:42:52 pm »
Most probably the culprit is VISUAL as EDITOR environment variable is only checked if VISUAL is not set. Check if VISAUL is set or not (echo $VISUAL).

Offline fluxdaemon

  • Peasant
  • *
  • Posts: 104
  • Cookies: -7
  • Galatians 2:20
    • View Profile
Re: Sudo without passwd
« Reply #8 on: February 01, 2013, 08:43:22 pm »
Wait, how come even if I do EDITOR=nano sudo visudo it still seems to be editing with vi?


You have to change your environment variables


# VISUAL="/usr/bin/nano -p -X" visudo


or you can do it system wide by doing


export VISUAL="/usr/bin/nano -p -X"
« Last Edit: February 01, 2013, 08:44:33 pm by fluxdaemon »

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #9 on: February 01, 2013, 08:45:22 pm »

You have to change your environment variables


# VISUAL="/usr/bin/nano -p -X" visudo


or you can do it system wide by doing


export VISUAL="/usr/bin/nano -p -X"

Didn't work. visudo is still editing /etc/sudoers with vi. Fucking hate vi. Maybe I did it wrong? This is annoying I just want to edit the fucking sudoers file.
« Last Edit: February 01, 2013, 08:53:34 pm by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline fluxdaemon

  • Peasant
  • *
  • Posts: 104
  • Cookies: -7
  • Galatians 2:20
    • View Profile
Re: Sudo without passwd
« Reply #10 on: February 01, 2013, 08:51:05 pm »
Didn't work. visudo is still editing /etc/sudoers with vi. Fucking hate vi. Maybe I did it wrong?

This is annoying I just want to edit the fucking sudoers file.


I did VISUAL="/usr/bin/nano -p -X" visudo -f /etc/sudoers as root and it worked fine for me

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #11 on: February 01, 2013, 08:53:19 pm »
I did that and it still edits with vi. I did echo $VISUAL and I get and empty value returned to me. Even after I set it to nano.

I never had a problem with this when I first installed Arch.
« Last Edit: February 01, 2013, 08:54:03 pm by lucid »
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline fluxdaemon

  • Peasant
  • *
  • Posts: 104
  • Cookies: -7
  • Galatians 2:20
    • View Profile
Re: Sudo without passwd
« Reply #12 on: February 01, 2013, 08:56:35 pm »
I did that and it still edits with vi. I did echo $VISUAL and I get and empty value returned to me. Even after I set it to nano.


I get an empty value too
Did you try appending


export VISUAL="usr/bin/nano -p -X" to your .bashrc file?

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: Sudo without passwd
« Reply #13 on: February 01, 2013, 08:58:57 pm »
Yes. Wow. Holy fucking shit. None of this stuff is working.
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python

Offline DaNePaLI

  • Peasant
  • *
  • Posts: 55
  • Cookies: 12
  • Forever n00b
    • View Profile
Re: Sudo without passwd
« Reply #14 on: February 01, 2013, 09:03:50 pm »
Once try: EDITOR=/usr/bin/nano visudo

Well one possibility is that your sudoers file has the entry like below:

Code: [Select]
Defaults      editor="/usr/bin/vim -p -X", !env_editor
Which will not allow you to use editor of your choice so either remove the line or change the vim to nano.