Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How to make scripts w/ sudo that prompt for a password?


  • Please log in to reply
12 replies to this topic

#1 wishmakingfairy

wishmakingfairy

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 19 November 2014 - 03:16 PM

Im looking to try to find the simplest way to make any small script run with sudo, but prompt for a password like a few applications I've installed.

 

Anyone know of any easy way or any sites with tutorials for this?

 

I want to be able to run a few program scripts like.... avgscanner or something of the like that won't scan the full drive or run without root permissions. I don't want to have the automatically kick off in case someone gets curious while playing around with my computer and starts up five instances of something.

 

I also want to know how to allow the script to open the terminal to allow you to view what is being run.

 

Any help is appreciated


Edited by wishmakingfairy, 19 November 2014 - 03:17 PM.

Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^


BC AdBot (Login to Remove)

 


#2 bmike1

bmike1

  • Members
  • 596 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Gainesville, Florida, USA
  • Local time:02:53 PM

Posted 19 November 2014 - 04:42 PM

if you want this to be whenever you enter sudo  add your user to the /etc/sudoers file.

if you do this you will never be prompted for a password again when you type in 'sudo <whatever>'.

to do this find the section that looks like:

 
   # User privilege specification
   root ALL=(ALL:ALL) ALL
 
and make it look like:
 
   # User privilege specification
   root ALL=(ALL:ALL) ALL
   <your username> ALL=(ALL:ALL) ALL

Edited by bmike1, 19 November 2014 - 04:54 PM.

A/V Software? I don't need A/V software. I've run Linux since '98 w/o A/V software and have never had a virus. I never even had a firewall until '01 when I began to get routers with firewalls pre installed. With Linux if a vulnerability is detected a fix is quickly found and then upon your next update the vulnerability is patched.  If you must worry about viruses  on a Linux system only worry about them in the sense that you can infect a windows user. I recommend Linux Mint or, if you need a lighter weight operating system that fits on a cd, MX14 or AntiX.


#3 wishmakingfairy

wishmakingfairy
  • Topic Starter

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 19 November 2014 - 09:28 PM

Well im looking more for a "double click the script and when it launches in the gnome terminal or that xterm, it says it requires a password before it continues"

 

I already have the system configured to run scripts with a double click.

 

However.... what you did post, i'll put in my google drive for future reference :P


Edited by wishmakingfairy, 19 November 2014 - 09:30 PM.

Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^


#4 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 20 November 2014 - 12:21 AM

wishmakingfairy if you read this link to my Topic New to Linux &c, the link is to page 5 - pick up at #68 and read on.

 

I think that may be the sort of thing you are talking about, is that so?

 

If so, let me know and we can begin a dialogue.

 

Cheers

 

:wizardball: Wiz



#5 wishmakingfairy

wishmakingfairy
  • Topic Starter

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 20 November 2014 - 12:50 AM

Those do look exactly like what im looking for, I'll try to reply within a day or so, if what I'm doing doesn't work I'll gladly post what im typing in.


Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^


#6 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 20 November 2014 - 01:06 AM

Sweet, just bear in mind, if you read through, that it DOES require the use of sudo - with one option always, and with the other option, dependent on usage or non-usage of sudo in the Terminal session, and usage, determined by any sequence of elevated privilege commands used either side. Overall the integrity and security of sudo is maintained, and that is likely why Todd Miller approved.

 

Later

 

:wizardball: Wiz



#7 wishmakingfairy

wishmakingfairy
  • Topic Starter

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 20 November 2014 - 07:03 PM

Obviously Im missing a big chunk:

 

#!/bin/bash

gnome-terminal -e "bash -c ~/avgscan;bash"

 

Im just using the avg scan as a test, I know its in the usr/bin folder, and some of the script was taken from another example I saw somewhere.  So.... what would correct this to make the avg scan run with a request to enter a password to allow it to scan with sudo?

 

I know its 100% wrong :P , i've only ever just used pre-compiled scripts and built off of what I seen or... i've taken the pre-compiled scripts, dropped them into a terminal after i sudo -s, then ran them.


Edited by wishmakingfairy, 20 November 2014 - 07:23 PM.

Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^


#8 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 20 November 2014 - 08:31 PM

  1. Where I called my file "update", what did you call yours?
  2. Did you build/place your file in usr/local/bin or just usr/bin?

:wizardball: Wiz

 

And what version of AVG?

 

Edited - inserted last line


Edited by wizardfromoz, 21 November 2014 - 02:11 AM.


#9 wishmakingfairy

wishmakingfairy
  • Topic Starter

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 21 November 2014 - 08:56 AM

:P I actually have the script on the desktop, however I did try adding the full path to the avgscan after the " ~/ " but it would say that the destination was incorrect. I just named the script scan.sh

 

So #!/bin/bash seeks the bin folder for its destination? I only did it on the desktop because I knew the avgscan was a ready to use command. And I can probably just find it in the usr/bin folder and make a shortcut, but this is for the sake of trying to make something happen in case I want to make something for others.

 

So, if im trying to use a script on the desktop... #!/home/user/Desktop/bash ?

 

The avg is the 2013 they have located in.... http://free.avg.com/us-en/download-free-all-product


Edited by wishmakingfairy, 21 November 2014 - 10:38 AM.

Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^


#10 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 21 November 2014 - 04:14 PM

Hi

 

 

So #!/bin/bash seeks the bin folder for its destination?

 

Nope

 

It's a convention so the *nix shell knows what kind of interpreter to run.

For example, older flavors of ATT defaulted to "sh" (the Bourne shell), while older versions of BSD defaulted to "csh" (the C shell).

Even today (where most systems run "bash", the "Bourne Again Shell"), scripts can be in bash, python, perl, ruby, PHP, etc, etc. For example, you might see "!/bin/perl" or "/bin/perl5".

PS: The exclamation mark ("!") is affectionately called "bang". The shell comment symbol ("#") is sometimes called "hash".

PPS: Remember - under *nix, associating a suffix with a file type is merely a convention, not a "rule". An "executable" can be a binary program, any one of a million script types and other things as well. Hence the need for "#!/bin/bash".

 

With that latter line, it means you have no need to call it "scan.sh" but could just call it "scan", or something unique and easily remembered, eg "scanme" (Scan Me).

 

Best to follow the directions as I wrote them (I am new to this too) - I can revisit my posts to see if I made errors.

 

There are also numerical codes that can be written in to affect/set read/write/execute privileges dependent on whether you wish to maintain a script for exclusive personal use or distribute it. Later on these

 

34 deg C here today coming up (93.2 F) gotta get shopping done before the heat hits my wife (Lupus), lol. Back here asap

 

:wizardball: Wiz



#11 Al1000

Al1000

  • Global Moderator
  • 7,489 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:08:53 PM

Posted 21 November 2014 - 07:24 PM

What is the purpose of the script? I would try changing the permissions of the existing executable file, so that it requires your password to execute. You can find the path to this (or any other) file using the locate command. If the executable file is avgscan, then:
locate avgscan
Then when you've found it, use ls -l to find out what the permissions are just now.
ls -l /path/to/avgscan


#12 wizardfromoz

wizardfromoz

  • Banned
  • 2,799 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:53 AM

Posted 22 November 2014 - 06:55 AM

wishmakingfairy can speak for herself but I think she was looking to get practice with scripting and picked an arbitrary app she was familiar with.

 

Just as easily,the same result (as the scripting) could be achieved through Aliassing.

 

But as you say Al, if it is simply to invoke sudo/password input, then no need to reinvent the wheel

 

Nitey-nite

 

:wizardball: Wiz ...zzzz.zzzz..yawn...zzzzzzzzzzzzzz

 

BTW learned something "locate" is one I have been looking for , Ta, Al!



#13 wishmakingfairy

wishmakingfairy
  • Topic Starter

  • Members
  • 212 posts
  • OFFLINE
  •  
  • Gender:Female
  • Local time:02:53 PM

Posted 23 November 2014 - 03:00 PM

A bit late on the reply, I did get some things working and some not, but the locate was definitely a helper as well the permissions thing. So thank you very much for it all. I'll get it eventually.


Using ubuntu and sharing how to as well as collecting how to scripts for common programs. Feel free to ask or share ^-^





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users