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:

  1. 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:

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

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


6 Responses to Getting around "su : must be run from a terminal"

  1. 561 Theo 2008-06-06 8:07 am

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

  2. 562 Evert 2008-06-06 11:42 am

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

  3. 560 Arjun 2008-10-01 5:52 pm

    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.

  4. 563 Quentin 2008-10-04 12:09 pm

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

  5. 564 dabb 2009-05-09 2:37 pm

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

  6. 565 mangoo 2009-10-26 7:43 pm

    Isn't the proper way to use sudo here?



About

My name is Evert, and I've been writing semi-regularly on this blog since 2006.

I'm currently available for contract work.

more info.

Subscribe

Dropbox

Dropbox is a simple cross-platform online backup and sync application. The first 2GB of space is free, and both you and me get an extra 250MB extra space if you sign up through this link.