Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have access to a linux server where I can sudo to 'foo' like this without a password:

sudo su - foo

Once I am the 'foo' user I am able to run a script like this:

/dir/foo_user_script.sh

The 'foo_user_script' is only executable by the foo user and not by my user. Thus I can run the script by first changing to the 'foo' user and then running the script.

However, I am trying to automate some processes using the Java SSH client ganymed. Ganymed's faq suggests that to run multiple commands I should use a contruct like:

Session.execCommand("echo Hello && echo again")

I tried something like this, but the second command (the foo_user_script) did not execute:

Session.execCommand("sudo su - foo && /dir/foo_user_script.sh")

I think this doesn't work because su launches a new shell.

Is there any way for me to run the /dir/foo_user_script.sh script in a single command?

Note:
"sudo -l" shows me this:

(root) NOPASSWD: /bin/su - foo

Thanks for the help!

share|improve this question
    
You should ask the server provider to provide a less broken configuration of sudo. IMHO, the sudo su combination is broken and defeats the purpose of using sudo in the first place (limiting access, providing audit trails and accountability). –  Slartibartfast Mar 26 at 5:05
    
After fiddling with this for a while, I realized that because I can sudo to the user I can generate and use my own SSH keys. I generated a new key and now I can SSH to the server directly as 'foo'. –  George Mar 26 at 5:28
1  
Which hopefully illustrates why 'sudo su' is not a security measure. –  Slartibartfast Mar 26 at 5:30

1 Answer 1

sudo -u foo /dir/foo_user_script.sh

share|improve this answer
    
Sadly, though this is the better answer in many senses, the user's system is broken (see the output of sudo -l) to reduce security. –  Slartibartfast Mar 26 at 5:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.