Recover your shell from python
March 7, 2008
While messing around with networks and ssh and user permissions, I stumbled upon this question:
Given a user (pybuntu) for example is logging into a machine via ssh and the admin is having a fun time, so the login becomes not a Bourne shell (bash) to instead the account is being launched into a python primary promt (>>>). How would the user recover into a shell?
My first though was to import some sort of bash module into python, or file, but that didn’t work too well for me. Any takes?
ps. exit() kills the ssh session.
EDIT:
>>>import os
>>>os.execl(‘/bin/bash’)
Sweet! Thanks to Martijn for this one.
-Eddie M.
import os
os.execl(‘/bin/bash’)
What about
import os
os.system(‘bash’)
>>> import subprocess
>>> subprocess.call (‘/bin/bash’)
$ echo “yay!”
import os
os.execl(“/bin/bash”)
import os
os.system(‘chsh’)