Send commands to a remote ssh server from my website form

前端 未结 1 920
长发绾君心
长发绾君心 2021-01-14 16:45

I want to create a website that users can fill a form,

and then I send those parameters to a remote ssh server to issue a python script.

Example, in my webpa

1条回答
  •  余生分开走
    2021-01-14 17:08

    You can create a Web application using Flask Framework and then use the Paramiko module to connect Python script with SSH Server and execute commands from the local machine. Your python script will act as an SSH client.

    Check out this link which shows steps to create a web application using Python and Flask Framework: https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

    Web application Example:
    For you simple form, you can update home page and sign up page to get form parameters and use those parameters to pass commands to the SSH server.

    Please find below the link for Paramiko and one link showing examples. It is really easy to set up the Paramiko.

    try:
        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.WarningPolicy)
    
        client.connect(hostname, port=port, username=username, password=password)
    
        stdin, stdout, stderr = client.exec_command(command)
        print stdout.read(),
    
    finally:
        client.close()
    

    Here, the hostname will be the SSH server and the username and password will be the one which you usually use to connect to the SSH server.

    Paramiko - http://docs.paramiko.org/en/stable/
    Example - https://gist.github.com/mlafeldt/841944

    0 讨论(0)
提交回复
热议问题