Search code examples
sshsudo

Is there a way to execute Shipit "remote" commands that use "sudo" with a user other than root?


When using the Shipit automation engine I found that trying to execute commands with "sudo" from an user other than root (let's call it "devuser") results in the connection closing without the command being executed.
This is a command that I'm trying to execute:

shipit.remote('sudo pwd');

Note that, on the target machine, "devuser" can execute everything with "sudo", without being asked his/her password (it's a choice of the target system).
Also note that everything invoked without "sudo" (and that obviously doesn't need elevated permission) gets executed prefectly fine by Shipit.
E.g.this one works just fine:

shipit.remote('pwd');

The question at this point is: am I doing something wrong or is it this way by design (e.g. to avoid privileges escalation)? If it's the latter: is there a way to work this limitation around?


Solution

  • simple hack for that is to set user inside each command that you are running with shipit. This is little overhead especially if there are a lot of commands but it will do the trick. Command for that is :

    su - <user> -c "<command>"
    

    In your case :

    shipit.remote('su - devuser -c "pwd"');
    

    You were on right track with your example.

    Best regards, Nikola