LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-04-2008, 01:17 PM   #1
bgrantham
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Rep: Reputation: 0
Question about using sudo su


Hi,

I have a need to run a script as another user, but the current process takes three commands to do.

sudo su - user
cd directory/
./script.sh

The account is set up such that doing the 'sudo su - user' requires no password.

I am trying to get this into a single command or shell script which I can run to accomplish the same thing. I tried using the -c flag of su, however I am required to enter a password with this flag. I can't enter a password, since I haven't been given a password.

Any help would be appreciated.

Thanks,
Beau
 
Old 07-04-2008, 02:55 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Disregard this.

Last edited by stress_junkie; 07-04-2008 at 02:56 PM.
 
Old 07-04-2008, 03:30 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Can you not put
Code:
su - user -c "cd /path/to/directory && ./script"
into e.g. runme.sh, modify sudoers to allow you to run
runme.sh w/o a password and then do sudo runme.sh?



Cheers,
Tink
 
Old 07-04-2008, 03:32 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
sudo su is superfluous. Use either sudo or su, you don't need both together.

If you want your script run as a different user, use any of these:

sudo -u user directory/myscript.sh
sudo -u user sh -c 'cd directory; ./myscript.sh'
 
Old 07-04-2008, 09:28 PM   #5
bgrantham
LQ Newbie
 
Registered: Jul 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
Can you not put
Code:
su - user -c "cd /path/to/directory && ./script"
into e.g. runme.sh, modify sudoers to allow you to run
runme.sh w/o a password and then do sudo runme.sh?



Cheers,
Tink
Thanks for the suggestion Tink, I tried this too. I think I am going to have to get the server admin to change the sudoers file, as you suggested in order to accomplish this.

Thanks again,
Beau
 
Old 07-04-2008, 09:41 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
The su program does not use sudoers; only sudo users sudoers.
 
  


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
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 05:40 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
sudo question binary_0011 Linux - Newbie 5 05-03-2006 07:55 AM
Sudo question satimis Fedora 6 11-24-2004 08:58 PM


All times are GMT -5. The time now is 08:24 PM.

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