LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 03-07-2016, 10:48 AM   #1
slufoot80
Member
 
Registered: Nov 2011
Posts: 69

Rep: Reputation: Disabled
Smile sudo


ok I have a script that I want a user to run as root using sudo but I have a few problems

1) The following script runs fine, but I only want the user to run only the script and nothing more

2) when I run sudo and reboot it works and I don't want the user to run anything else except the script

3) when I run it the first time it asks for the root password when I type it in it doesn't ask anymore

Code:
#!/bin/bash
clear                                                   # clear screen

PROJECTNAME=mcksa                                   # variable name of project storage area
OLDDIRECTORYNAME=/dcfs0001mi/                           # variable name of old directory
NEWDIRECTORYNAME=/dcfs01_new/                           # variable name of new directory

export PROJECTNAME                                      # export variable
export OLDDIRECTORYNAME                                 # export variable
export NEWDIRECTORYNAME                                 # export variable

unlink /forms/$PROJECTNAME                              # unlinking of old project name from forms
sleep 1
ln -s $NEWDIRECTORYNAME$PROJECTNAME /forms/$PROJECTNAME # linking of new project name
sleep 1
cd /forms
ls -l |grep $PROJECTNAME                                # checking new link name

cd $OLDDIRECTORYNAME                                    # changing to old directory
sleep 1
mv $PROJECTNAME $PROJECTNAME.old                        # moving project name to .old
sleep 1
ls -l|grep $PROJECTNAME                                 # checking if project was moved to .old
line from sudoers file

Code:
username linux-nuau = (ALL) NOPASSWD: /usr/sbin/changelink

Last edited by slufoot80; 03-07-2016 at 10:51 AM. Reason: forgot line from sudoers
 
Old 03-07-2016, 10:53 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,837

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
sudo does not ask for root's password, but for user's one
you can specify in /etc/sudoers what is allowed, so you can allow to execute only a script. But be careful, do not allow the users to modify that script.
Would be nice to show what did you configure, otherwise hard to say anything
 
Old 03-11-2016, 01:27 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by slufoot80 View Post
Code:
username linux-nuau = (ALL) NOPASSWD: /usr/sbin/changelink
on my system a similar line would look like this:
Code:
username ALL=NOPASSWD: /usr/sbin/changelink
and works, i.e. i can call the script with
Code:
sudo changelink
and don't have to enter my password.

Sudo version 1.8.15

does that help?

btw, i wouldn't put custom scripts in /usr/sbin, rather in /usr/local/(s)bin or even /home/username/bin.
 
  


Reply

Tags
sudo script



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
sudo: effective uid is not 0, is sudo installed setuid root? awladnas Linux - Newbie 10 08-30-2014 06:03 PM
Question about the sudo command, specifically how to have sudo act as if user is root slacker_ Linux - Newbie 17 09-22-2013 03:48 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
Unable to redirect all sudo messages to /var/log/sudo driftwood Linux - Server 2 10-18-2012 04:34 AM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:36 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