5

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!

3
  • 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). Mar 26, 2014 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, 2014 at 5:28
  • 2
    Which hopefully illustrates why 'sudo su' is not a security measure. Mar 26, 2014 at 5:30

1 Answer 1

8

sudo -u foo /dir/foo_user_script.sh

1
  • 1
    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. Mar 26, 2014 at 5:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .