[Python] Executing an interactive command using ssh and Python

Discussão em 'Python' iniciado por Stack, Abril 14, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use a Python script to ssh to a remote server I own and source a script called "admin_environment". The interactive part is required because I need to enter a password once this script has been sourced. I already tried with

    import subprocess, os
    output = subprocess.run(["ssh", "me@servername", "source ~/admin_environment"])
    print(output)


    But this throws tonnes of errors. The main one being that it skips over my command and then immediately exits the ssh connection. Ideally I’d like to ssh, source the script then run a Command over python.

    Any ideas?

    Continue reading...

Compartilhe esta Página