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.

Doesn't it scare you at least a bit that you were actually able to do this?
The scary part was being able to spawn a shell in the first place =P. We locked that down afterwards :)
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.
It is great that you have a proper terminal, and things like 'su' will work as usual. Tnanks for informative post.
Thank you thank you thank you, this saved me a whole lot of trouble. <3>
Isn't the proper way to use sudo here?