0

I have a script for MobileTerminal in iOS that requires su, is there any way I can add a command to the bash script to login as root without having to type su then the password?

Cheers,

Dec

Declan Land
  • 17
  • 1
  • 7

2 Answers2

1

SUDO and system functions are disallowed in iOS, they violate sandboxing and security.

zaph
  • 111,848
  • 21
  • 189
  • 228
0

That's the solution worked for me:

  1. Jaibreak
  2. Install sudo from Cydia
  3. Install OpenSSH from Cydia
  4. SSH to your iPhone

    $ssh root@<your iphone ip>
    Password: alpine //no echo
    

    and run

    iPhone:~ root# visudo
    

    add right after

    root    ALL=(ALL) ALL
    

    this line (varies of what you want)

    mobile  ALL=(ALL) ALL
    
  5. Save changes. Now you can sudo. For editing with visudo you should use controls like in vi
  6. After all add to your script hardcoded sudo call like this

    #!/bin/bash
    sudo -S -p "" echo -n "" <<!
    alpine
    !
    sudo echo "This line is printed as root"
    

    Now explanation:

    • -S allows reading password from <<!\n ... \n! block, it should be printed on a single line
    • -p "" suppresses password promt, so the line Password: is not printed
    • echo -n disallows a newline character in the end

So you can sudo in your script without any password promt. The only thing - in this method password is hardcoded. But you can try command line arguments like $1 (not tested, just an idea)