LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2011, 02:22 PM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
run a user-defined command without sudo


i wrote a shell script and was able to compile it using SHC. after that i copied it to the /bin folder and tried running it as a normal user, but i keep getting the error
" operation not permitted
killed "
i tried changing the permissions. but it doesn't work. it only works with sudo. there must be another way. otherwise it won't be linux right?
 
Old 01-24-2011, 02:28 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,261

Rep: Reputation: 315Reputation: 315Reputation: 315Reputation: 315
You can configure sudo by "visudo" command, first read manual of course, otherwise you lock self. By the way, can you tell which command from your script need root access and what your script do?

Last edited by eSelix; 01-24-2011 at 02:29 PM.
 
Old 01-24-2011, 02:38 PM   #3
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
well i tried using visudo. here is my /etc/sudoers file
Code:
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults	env_reset

# Host alias specification

# User alias specification
 User_Alias USERS = anurup

# Cmnd alias specification
  Cmnd_Alias CUSTOM_CMDS = /bin/resetproxy, /bin/nautcurrent, /bin/createbin, /bin/shc

# User privilege specification
root	ALL=(ALL) ALL

# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL
#
#includedir /etc/sudoers.d

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
do i have to add anything else to this file? well one example is i created an auto login script for my network connection
i want to run that as a command. but i need sudo all the time. is there any other way?
 
Old 01-24-2011, 02:40 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 178Reputation: 178
Quote:
Originally Posted by anurupr View Post
i wrote a shell script and was able to compile it using SHC. after that i copied it to the /bin folder and tried running it as a normal user, but i keep getting the error
" operation not permitted
killed "
i tried changing the permissions. but it doesn't work. it only works with sudo. there must be another way. otherwise it won't be linux right?
Um, it only works with sudo? Do you know exactly what operation is "not permitted" otherwise? If you wrote the script, and you don't know what it is in your script that's triggering this message, the worst thing you can do is just say, "oh, well", and run the script under sudo. That would mean using root privileges for doing something that you don't know about. Highly dangerous.

Figure out exactly what operation isn't permitted, first. Don't mess with sudoers, either, until you've answered this question.
 
Old 01-24-2011, 02:52 PM   #5
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
well ok i'm at fault there .but let me tell you something .its the same for any script that i write. there is one script which just opens the nautilus browser with the current working directory. is that dangerous?
 
Old 01-24-2011, 04:02 PM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,261

Rep: Reputation: 315Reputation: 315Reputation: 315Reputation: 315
You must use NOPASWWD if you want to not using passwords during sudo, but wje_lq has right saying that better is to find which command from your script need root access. Otherwise you will create security hole in your system.

In your example - opening nautilus with sudo means that you (or anybody who run this script) will get full access to every file in your system.
 
Old 01-24-2011, 04:45 PM   #7
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
yes exactly so i don't need root access for the nautilus script but i cannot run the command without sudo
 
Old 01-24-2011, 06:45 PM   #8
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Is it a permissions problem?
Try running:
Code:
ls -l scriptname
and/or
Code:
chmod +x scriptname
 
Old 01-26-2011, 05:49 AM   #9
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Original Poster
Rep: Reputation: 16
i don't think its the problem with my script . i think its the problem with the shc program the executable file it generates cannot be executed without sudo
 
Old 01-26-2011, 04:26 PM   #10
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,261

Rep: Reputation: 315Reputation: 315Reputation: 315Reputation: 315
To be sure. Run this script before compilation as normal user and check if you have no that error. So we will be known if the script generate error or shc.
 
Old 04-11-2011, 04:30 AM   #11
vasanthmurali
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 1
Quote:
Originally Posted by anurupr View Post
i wrote a shell script and was able to compile it using SHC. after that i copied it to the /bin folder and tried running it as a normal user, but i keep getting the error
" operation not permitted
killed "
i tried changing the permissions. but it doesn't work. it only works with sudo. there must be another way. otherwise it won't be linux right?
Please do the following.

su - root

./yourscriptname

That's all. It might be okay now.
 
Old 04-11-2011, 04:34 AM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Is it the compiled script that doesn't run?
What are the permissions of the program itself?

If a program can't open a file, one way of debugging is to launch the program using strace. It will list the system calls the program makes. Pay attention to the open calls.

What your compiled script does, could be performed simply modifying the properties of the icon. Change the command argument from %u to the url you want it to start with. Do this on a copy of the icon.

Last edited by jschiwal; 04-11-2011 at 04:39 AM.
 
Old 03-19-2013, 04:12 AM   #13
go260135
LQ Newbie
 
Registered: Mar 2013
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by anurupr View Post
i wrote a shell script and was able to compile it using SHC. after that i copied it to the /bin folder and tried running it as a normal user, but i keep getting the error
" operation not permitted
killed "
i tried changing the permissions. but it doesn't work. it only works with sudo. there must be another way. otherwise it won't be linux right?
I've also encountered this problem with shc-3.8.9 which is installed on Ubuntu 12.04. But the encrypted shell script only works with sudo, too. Then I saw the shc.html file, it shows the following words:


Compile a script which can be run on other systems with the trace option enabled:

example% shc -v -r -T -f myscript



I followed the example command, and my encrypted shell script works without sudo.
 
Old 03-19-2013, 12:28 PM   #14
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 123Reputation: 123
Quote:
Originally Posted by anurupr View Post
well i tried using visudo. here is my /etc/sudoers file
If you are going to grant sudo access, (especially without requiring a password) then it is best to to grant access only to those programs that are absolutely necessary.

For example:
Code:
##
## User privilege specification
##
root ALL=(ALL) ALL
anurupr ALL=(ALL) NOPASSWD: /path/to/program1, /path/to/program2, /path/to/program3
This can also be used for a group.

I use this method to allow me to run shutdown without logging in as root (I use fluxbox).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] "sudo: Can't mkdir /var/run/sudo/%user%: File exists" CNBarnes Linux - Server 7 01-10-2011 05:11 PM
(Sudo) command can't run by sudo rahilmaknojia Linux - Server 8 06-25-2010 10:30 AM
run a linux command in user defined terminal davender84 Linux - General 1 12-04-2009 07:43 AM
Gconf-editor settings not sticking for root, sudo user, or user when run sandaili Fedora 1 07-19-2008 09:31 AM
How to run user defined services and exe files on linux. Prabhat Sharda Linux - Software 6 01-05-2005 04:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:16 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration