1

I do not have sudo installed on my machine, but I have a third party program which runs as different user other than root and tries to execute sudo command. Is there a way to enable this program to run sudo ?

I have logged in as root and created sudo bash script in /usr/bin with following contents, since I know root password is there a way I can modify the script to run the command with root privileges. Or is there any other way ? Yes this is foolish, but I need this only for testing.

#!/bin/sh
$@
Poorna
  • 161
  • 1
  • 2
  • 9
  • 1
    You can write a wrapper script that runs `ssh root@localhost` and run whatever you want. – dawud May 09 '13 at 06:28
  • @dawud how can I add password to the above command, since sudo script is run by other program which runs in background. – Poorna May 09 '13 at 06:35
  • I have tried copying the public key to roots authorized keys file and run the command ssh root@localhost command, it worked fine – Poorna May 09 '13 at 08:42
  • 1
    Nice to hear. Keep in mind this is not optimal, nor auditable in the way `sudo` is. – dawud May 09 '13 at 09:29

1 Answers1

3

You seem to be asking about the SUID bit; if you do chown root:root /usr/local/bin/foo; chmod 4755 /usr/local/bin/foo then, in theory, whoever runs /usr/local/bin/foo will run it as root. But the concept is so security-problematic that somes OSes don't honour the SUID bit at all, and others don't honour it on some executables (eg, shell scripts).

Since you have the root password, why not just install sudo? It has a good security track-record, and you can restrict the ability to run as root not just to a certain executable, but to a certain user also.

If you absolutely must use the suid bit, do not grant suid-root status to the script above, or you will have given anyone the power to do anything as root.

MadHatter
  • 79,770
  • 20
  • 184
  • 232