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.

5 Responses to “Recover your shell from python”

  1. Martijn said

    import os
    os.execl(‘/bin/bash’)

  2. mokkel said

    What about

    import os
    os.system(‘bash’)

  3. >>> import subprocess
    >>> subprocess.call (‘/bin/bash’)
    $ echo “yay!”

  4. LaGrange said

    import os
    os.execl(“/bin/bash”)

  5. Ered said

    import os
    os.system(‘chsh’)

Leave a Reply