LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-16-2012, 01:20 PM   #1
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
SOLVED! Question: sudoers file syntax and function


I need to have a sudoers file entry that allows any userid, coming from anywhere, to execute a single command as root, without requiring a password, with or without a command line parameter.

Here is what I have, but I am still be prompted for a password:

ALL ALL=NOPASSWD: /usr/local/sbin/banssh

I need to be able to execute "banssh" either as simply "banssh" or as "banssh 198.162.0.1" (not for that specific IP address every time, the actual ip address varies, this is just an example)

Not that I think it matters, but "banssh" is a script I wrote, and have been using for many many years, that dynamically adds ip address to the hosts.allow file (using a syntax that bans the ip). If someone unsuccessfully tries to login three times, their ip address gets banned (via an entry like "ALL : 192.168.0.1 : DENY" in hosts.allow). This all works fine, except incoming ssh connections are asked for their password to run sudo. I don't remember this password request ever happening on other servers where I have installed banssh, but it is happening on this one older Ubuntu server I am working on now (I think this Ubuntu server is running Intrepid Ibex, but possibly it's Hardy Heron).

Here is how banssh is called in my application:

1st, from /etc/hosts.allow like this:
sshd : ALL : spawn (/usr/local/sbin/banssh %a)&

2nd, from /etc/ssh/sshrc like this:
sudo /usr/local/sbin/banssh

Why am I being prompted for a password to do the sudo?

Thanks!

Last edited by haertig; 12-17-2012 at 11:06 AM.
 
Old 12-17-2012, 08:53 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,681

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Quote:
Originally Posted by haertig View Post
I need to have a sudoers file entry that allows any userid, coming from anywhere, to execute a single command as root, without requiring a password, with or without a command line parameter. Here is what I have, but I am still be prompted for a password:

ALL ALL=NOPASSWD: /usr/local/sbin/banssh

I need to be able to execute "banssh" either as simply "banssh" or as "banssh 198.162.0.1" (not for that specific IP address every time, the actual ip address varies, this is just an example)

Not that I think it matters, but "banssh" is a script I wrote, and have been using for many many years, that dynamically adds ip address to the hosts.allow file (using a syntax that bans the ip). If someone unsuccessfully tries to login three times, their ip address gets banned (via an entry like "ALL : 192.168.0.1 : DENY" in hosts.allow). This all works fine, except incoming ssh connections are asked for their password to run sudo. I don't remember this password request ever happening on other servers where I have installed banssh, but it is happening on this one older Ubuntu server I am working on now (I think this Ubuntu server is running Intrepid Ibex, but possibly it's Hardy Heron).

Here is how banssh is called in my application:

1st, from /etc/hosts.allow like this:
sshd : ALL : spawn (/usr/local/sbin/banssh %a)&

2nd, from /etc/ssh/sshrc like this:
sudo /usr/local/sbin/banssh

Why am I being prompted for a password to do the sudo?

Thanks!
If that's the exact line you're using, I don't think the syntax is right. Try:
Code:
ALL=(ALL) NOPASSWD: /usr/local/sbin/banssh
 
Old 12-17-2012, 11:05 AM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Original Poster
Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
SOLVED!

Stupid me. It was an order-dependent thing in the sudoers file. The problem was that there were multiple matches in the sudoers file for the userid I was using, and sudo will always use the LAST match (not the MOST SPECIFIC match, but the LAST match - big difference there). And since I am in the "admin" group, the rule for %admin was overriding the specific rule for banssh.

What I had was this:

Code:
root	ALL=(ALL) ALL
ALL	ALL=NOPASSWD: /usr/local/sbin/banssh
%admin  ALL=(ALL) ALL
What I needed was this:

Code:
root	ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
ALL	ALL=NOPASSWD: /usr/local/sbin/banssh
I did not see that %admin line in the sudoers file initially because it was at the bottom of the file below a bunch of comment lines (I removed those comment lines for clarity in the cut-n-paste above).

Last edited by haertig; 12-17-2012 at 11:10 AM.
 
2 members found this post helpful.
Old 12-17-2012, 11:11 AM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Original Poster
Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Thanks for your help TB0ne, I appreciate your reply!
 
Old 12-17-2012, 03:50 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,681

Rep: Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971Reputation: 7971
Glad it's working, and thanks for following up!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sudoers file: syntax error skaushal_lk Linux - Newbie 5 07-12-2010 03:24 AM
sudoers file and no password question uncle-c Linux - Newbie 4 04-29-2009 04:35 AM
Syntax error in sudoers file Julix Linux - General 9 09-07-2007 09:44 PM
A question about the sudoers file... hkl8324 Linux - Newbie 1 01-29-2006 06:08 AM
I deleted /etc/sudoers and creates a new file call sudoers but now it doesnt for visu abefroman Linux - Software 1 11-10-2005 05:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:56 AM.

Main Menu
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