sudo not allow User to run sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sudo not allow User to run sed
# 1  
Old 04-18-2008
sudo not allow User to run sed

Hello,

As recommended by the moderators I will start my questions here...

I am a little confused by my Linux (CentOS/RHEL) distribution's sudo
mechanism. Or perhaps I just do not know how to use sudo. I can run
a sed command as the root user but it fails to write a root-owned
directory when I run via sudo command.

Is there a config file that sudo uses to determine which commands it
will be managing? Right now I have a sudoers file set this like the
following:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL

## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL

My user is in wheel group.

$ id
uid=500(duderonomy) gid=10(wheel) groups=10(wheel)


Any ideas?

Thanks in advance.
-D
# 2  
Old 04-18-2008
you should probably post the exact commands you're using and any error messages etc... it's really unclear what issue you're having.
are you doing a:
sudo su -
then running some command?

are you running a sudo command line instead? if so what is that command line??
# 3  
Old 04-18-2008
Hi!

I appreciate the feedback that I was vague.
Thank you (very much) for your time. Smilie

Here's my input and output for the two cases described in my
original post:

Case A)
---------
$ su -
<entered password>
# cd /etc
# sed -e 's/A/B/' < motd.ORIG > motd
#

It works! (writes file "/etc/motd" which is inside root owned
directory and file also has root ownership)

Case B)
---------
$ cd /etc
$ sudo sed -e 's/A/B/' < motd.ORIG > motd
-bash: ./motd: Permission denied

It Fails.

##

I really need this to work via sudo as this one step
is part of a larger script. I do not see my problem.

Thank you for any hints.

-D
# 4  
Old 04-19-2008
sudo runs the current command as root, but the redirection is handled by your shell before invoking sudo, so that happens as yourself.

A common workaround is to create the file as regular user, then use sudo to copy it to the privileged location. This also reduces the need to run potentially complex commands with elevated privileges.
# 5  
Old 04-22-2008
Quote:
Originally Posted by era
sudo runs the current command as root, but the redirection is handled by your shell before invoking sudo, so that happens as yourself.
You are eff'n brilliant! Thank you.

Quote:
Originally Posted by era
A common workaround is to create the file as regular user, then use sudo to copy it to the privileged location. This also reduces the need to run potentially complex commands with elevated privileges.
So, if I were to extend what I believe you are saying...

If, for example, I was developing a new root file system for deployment as a new distribution, I work with the files with/in normal user privilege/location. Then, later run sudo on simple commands (such as cp, chown, chmod) to achieve the final desired result.

Thanks,
D
# 6  
Old 04-22-2008
Pretty much, yes. Or create a chroot jail / vmware image / whatever where you will only wreck the thing you're working on if you goof up while playing root.
# 7  
Old 04-22-2008
after you've completely tested, and know exactly what will happen,
you can create a script "with your sed commands, etc in the script"
instead of putting on command line as you were originally.
then you can:
Code:
 sudo "/<path>/script"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to automatically run commands after SSH and SUDO not working?

I'm working on a script to SSH and SUDO as (sap user sidadm) then automatically run commands that the sidadm user can run such as R3trans -v, tp, etc.. I can SSH without password and SUDO.. but the commands don't run after I SSH and SUDO to the sidadm user...here is the commands that I've... (2 Replies)
Discussion started by: icemanj
2 Replies

2. Shell Programming and Scripting

Preserving variable in script run with sudo

In a nutshell, I want $USER to reflect my user ID in a script run with sudo. I'm working with OSX in case that makes a difference. If I 'sudo echo $USER', I get my user ID. But if I 'sudo myscript.sh' and myscript.sh has a line to echo $USER, I get 'root' I'm hoping there's a switch I can add... (1 Reply)
Discussion started by: jnojr
1 Replies

3. Shell Programming and Scripting

Chmod working in sudo run script but chown isn't

My git user has permission in sudoers to run a wrapper script to move files into my webroot. Everything is working fine except for the chown line. After the script has run, the files ar still root:root instead of apache:apache. Scratching my head...:confused: #!/bin/sh echo echo "****... (4 Replies)
Discussion started by: dheian
4 Replies

4. Shell Programming and Scripting

How to run sudo commands under a script?

Hi, I am new to scripting. I am trying to write a script to ssh one remote machine and run a sudo command. ssh <hostname> sudo -S <command> < ~/pass.txt I am stored my password in pass.txt. I am getting error sudo: no tty present and no askpass program specified Please suggest me how can... (1 Reply)
Discussion started by: venkia9
1 Replies

5. 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

6. AIX

track commands run as root after sudo

I'm looking for a way to track commands that are run as root after a user runs sudo su - root. I have a profile set up for root that will track the commands by userid but if we change the shell it only stores it in that shells history file. (2 Replies)
Discussion started by: toor13
2 Replies

7. 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

8. Cybersecurity

Unable to run 'su' and 'sudo' after changing permissions on /etc

Hello, I'm running rhel6 64bit. Accidentally I ran % chmod -R 777 /etc and after that I have a problem to do 'su' or 'sudo'. When I did sudo it complained that /etc/sudoers has 777 while it should be 0440. I changed that and also restored right permission for: -rw-r--r-- 1 root root 1966 May 19... (2 Replies)
Discussion started by: susja
2 Replies

9. UNIX for Dummies Questions & Answers

sudo user

I am trying to run a command from different user on my server. However when i execute the command it asks for password can you please help. when i use this command to switch user no password is required 1) sudo su - bilbtf42 when i use 2) sudo su - bilbtf42 cp file1 direcotry1/file1 ... (3 Replies)
Discussion started by: blackeyed
3 Replies

10. AIX

Run sudo to another user

Run sudo to another user . I have two users in my AIX system appadmin (Application admin ) and appuser (Application user) Application Admin user has special permission to run every thing about this application. I have one script called /usr/app.sh Only appadmin has permission to run this... (11 Replies)
Discussion started by: Mr.AIX
11 Replies
Login or Register to Ask a Question