Send commands to a remote ssh server from my website form

♀尐吖头ヾ 提交于 2020-03-14 18:45:05

问题


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 webpage, the form contains input text, para1, para2, para3, etc..

After the user clicks submit, it should be able to send a command to remote ssh server terminal "python para1, para2, para3,....."

What kind of technique that I need to solve this problem??

Thank you.


回答1:


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



来源:https://stackoverflow.com/questions/59992524/send-commands-to-a-remote-ssh-server-from-my-website-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!