sudo but no sudo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sudo but no sudo
# 1  
Old 04-30-2010
sudo but no sudo

hi guys

a customer asked me to create a menu for linux he also asked me to do this:

open like a command like where a user can execute commands...so for this the users have sudo enabled

the code below works OK.

But it has an issue when a command is executed but the command does not need sudo


like for instance

Code:
cd /
sudo: cd: command not found


how can I allow a user to execute all commands when a command does not need sudo

Code:
echo -e "Press Control+C to finish"
#echo -e " "
while true;
  do
  read whichcmd?"Insert Command: "
  sudo $whichcmd
done

thanks a lot
# 2  
Old 04-30-2010
"cd" is almost useless as an external command, it should be done by the running shell itself.
# 3  
Old 04-30-2010
You have to check the kind of command, some are external files like /usr/bin/who, others, cd for example, are shell builtins.
try this in ksh or bash:
Code:
alias plpl='ls *'
type cd
type who
type plpl

You can use type to differentiate between things sudo can and cannot do.
BTW: if you grant sudo to that user for everything, you have given him/her complete control of the box. There is a file, /etc/sudoers, that lets you control commands like shutdown.
# 4  
Old 04-30-2010
Quote:
Originally Posted by karlochacon
so for this the users have sudo enabled
I think this is the wrong way to tackle the problem: sudo is for allowing users to execute commands they are normally not allowed to use. For instance: "shutdown" is only allowed for user "root", but you want to allow a specific user (other than root) to use this too (but not the other commands root is allowed to run). For this you create a sudo rule.

It doesn't make sense to control execution of each and every command in the system with sudo, because for this the normal filesystem flags (r-w-x) are sufficient. If you want all (normal) users not to use a specific command simply remove the x-flag from the executable and be done.

If you still need to use sudo at all after taking these considerations you could rewrite your code the following way:

Code:
echo -e "Press Control+C to finish"
#echo -e " "
while true ; do
     read whichcmd?"Enter Command: "
     if [ $(sudo -l | grep -c "$whichcmd") -gt 0 ] ; then
          sudo $whichcmd
     else
          $whichcmd
     fi
done

You will have to make sure in /etc/sudoers that "sudo -l" doesn't require a password, of course.

I hope this helps.

bakunin
# 5  
Old 04-30-2010
bakunin is correct. Turning off/on each possible command is a waste of effort. Conversely, granting a blanket sudo to a user is promoting that user to a sysadmin, which is really a bad idea. For a variety of reasons.

sudo should be set up for a given user to do specific tasks.

We have "role" user accounts, that can only be accessed via su. These users are application owners, and can do maintenance, etc., on an app. That may be what you really want.
# 6  
Old 04-30-2010
thanks guys

I know some commands are useless but I really don't want to complicate the end user and I need to have almost the same functionality as the normal shell

thanks a lot I' am going to try what you wrote here
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Sudo to user other than root but do not allow sudo to root

I have a set of RHEL 5 boxes running our ERP software on Oracle databases. I need to allow my DBA's to su to oracle and one other account (banner) without knowing the oracle or banner password. But I need to prevent them from su'ing to any other user especially root. I only want them to be able to... (1 Reply)
Discussion started by: westmoreland
1 Replies

2. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi, Have a need to run the below command as a "karuser" from a java class which will is running as "root" user. When we are trying to run the below command from java code getting the below error. Command: sudo -u karuser -s /bin/bash /bank/karunix/bin/build_cycles.sh Error: sudo: sorry,... (8 Replies)
Discussion started by: Satyak
8 Replies

3. Shell Programming and Scripting

sudo: sorry, you must have a tty to run sudo

Hi All, I running a unix command using sudo option inside shell script. Its working well. But in crontab the same command is not working and its throwing "sudo: sorry, you must have a tty to run sudo". I do not have root permission to add or change settings for my userid. I can not even ask... (9 Replies)
Discussion started by: Apple1221
9 Replies

4. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

5. AIX

sudo log and sudo auditing

Sudo In AIX, how to find out what commands have been run after a user sudo to another user? for example, user sam run 'sudo -u robert ksh' then run some commands, how can I (as root) find what commands have been run? sudo.log only contains sudo event, no activity logging. (3 Replies)
Discussion started by: jalite19
3 Replies

6. Cybersecurity

sudo /bin/sh or sudo su -

we are looking at changing the way we get root on our network. in our current system if an admin needs root access he just gets the root password and uses an su. some of our staff have decided that a sudo to "/bin/sh" will be easer. some of our staff think a sudo to "su -" will be better. I... (0 Replies)
Discussion started by: robsonde
0 Replies

7. Shell Programming and Scripting

sudo and sudo sh

Hello, I'm TOTALLY NEW to Unix. I just want to ask about what do those two commands in a SIMPLE NON-FORMAL mean: sudo sudo sh Thanks. (1 Reply)
Discussion started by: SWEngineer
1 Replies

8. UNIX for Dummies Questions & Answers

Unable to use the Sudo command. "0509-130 Symbol resolution failed for sudo because:"

Hi! I'm very new to unix, so please keep that in mind with the level of language used if you choose to help :D Thanks! When attempting to use sudo on and AIX machine with oslevel 5.1.0.0, I get the following error: exec(): 0509-036 Cannot load program sudo because of the following errors:... (1 Reply)
Discussion started by: Chloe123
1 Replies

9. UNIX for Advanced & Expert Users

Help with Sudo

Hi all: I am running sudo version 1.6.6. I would like to avoid any user the "sudo -s" command which opens a terminal giving the user full root access just like a root user essentially negating sudo. Is there any way to prevent users from giving this command ? Your help in this is appreciated. ... (1 Reply)
Discussion started by: geomonap
1 Replies
Login or Register to Ask a Question