LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 01: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, 01:28 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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 01:29 PM.
 
Old 01-24-2011, 01: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, 01:40 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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, 01: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, 03:02 PM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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, 03: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, 05:45 PM   #8
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
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, 04: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, 03:26 PM   #10
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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, 03: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, 03:34 AM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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 03:39 AM.
 
Old 03-19-2013, 03: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, 11:28 AM   #14
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
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



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

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

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