Getting around "su : must be run from a terminal"

I killed the sshd daemon from one of our servers by accident today. I wanted to avoid going to the data center, so I was able to upload and run a PHP script to give me a shell..

Problem was, that it would run under the www-data user and trying to su to root gave me the following message:

su : must be run from a terminal

After some googling, I found the solution from Tero's glob. If you have python installed, just run the following from your shell:

echo "import pty; pty.spawn('/bin/bash')" > /tmp/asdf.py
python /tmp/asdf.py

You now have a proper terminal, and things like 'su' will work as usual.

Web mentions

Comments

  • Theo

    Theo

    Doesn't it scare you at least a bit that you were actually able to do this?
  • Evert

    Evert

    The scary part was being able to spawn a shell in the first place =P. We locked that down afterwards :)
  • Arjun

    Arjun

    I think it is not your justification; it is only the way to find another way. Yes, you are that I have got a proper terminal.
  • Quentin

    Quentin

    It is great that you have a proper terminal, and things like 'su' will work as usual. Tnanks for informative post.
  • dabb

    dabb

    Thank you thank you thank you, this saved me a whole lot of trouble. <3
  • mangoo

    mangoo

    Isn't the proper way to use sudo here?
  • Lukas

    Aaaaaa! You are amazing! Thank you, thank you, thank you, thank you!

    Do you know how many hours I spent trying to get access to my stuff which was 150km from me?
    Thank you and Tero's glob!

  • Skia

    Thanks a lot, it saved my night! :)

  • james

    thankssss

  • platzh1rsch

    thank you! very helpful!

  • Mathieu - L'Essence du mâle

    Thank you !!!!