4

I have a computer in my university office, with Ubuntu on it, ssh running, and Python. I'm connecting on it myself using ssh to run Python programs and see the output. Only command-line output, nothing fancy.

However, I have this colleague I would like to allow to do the same. Unfortunately, he is not great with IT, so I wouldn't want to go through the whole process of familiarizing him with ssh. I'm looking for a simple alternative way for him to run the program and see the (command-line) output.

Running the program in this context means being confined to a specific folder myFolder, and do python file1.py within that folder.

Does Ubuntu come with apache or another web server installed? Is there another means of communication I could set up for him? He is using Windows 7.

  • Consider installing webmin. It's a bit overkill just for running a command, but for general administration, its quite useful. – muru Dec 25 '15 at 16:38
  • 4
    "how to create a webinterface" is not related to Ubuntu but a general coding question. Try to find something useful on google and use that. – Rinzwind Dec 25 '15 at 16:49
  • 1
    Make something with Flask... – wb9688 Dec 25 '15 at 17:29
  • You are asking about a Web solution when what you are currently doing with SSH uses only Internet. I suggest you edit your question to remove the confusion. – andy256 Dec 25 '15 at 21:37
  • 1
    Is there any particular reason for you to provide that service? Because if you only need a way for your friend to run some Python in web browser, then there are few websites that can already do that. Look up Skulpt, Trinket or CodeAcademy Python course. – Mirek Długosz Dec 25 '15 at 23:41
4

Of course you can install apache and try your luck from there.

To me, the following seems simpler:

  • (optional) create a user account for him on the university machine. This is to "separate" him from your files. This is not strictly necessary but may be a good idea.
  • Install putty on your friend's Windows 7 machine.
  • Create a putty session (as described here) and put that as an icon on the desktop (or any other convenient place). Make sure you also configure user name and password. (A fancy alternative would be to use pageant for authentication)

This way, all your friend has to do is click on an icon and he will be presented with a console window where he can directly use the script: python file1.py

  • me likes this :-) Putty <3 – Rinzwind Dec 25 '15 at 20:21
  • 1
    The problem with putty is that it is just a ssh wrapper that is not telnet, it isn't that friendly to a non IT guy. He would still need to know the commands sent over ssh and how to use them so training would still be required – Sammaye Dec 25 '15 at 21:38
  • Though SSH key login would remove some of the IT knowledge required since he would magically login and be able to maybe run the script – Sammaye Dec 25 '15 at 21:39
  • @Sammaye: I disagree. Putty is a telnet client; read the title of the putty homepage. For the other part, I interpreted the question that his friend would like "to do the same". This would include the commandline. Putty can and does abstract the ssh hassle completely. So that the end-user is only faced with the commandline. To get to the same simplification level with apache requires IMHO a lot more. – user23573 Dec 25 '15 at 21:44
  • sorry yeah, don't know why I thought putty was not telnet, must have had one those moments – Sammaye Dec 25 '15 at 21:48
4

You could set up an Ipython notebook server.

Here are the instructions.

The notebooks should be relatively easy to use (for some applications even better than the terminal interface). Plus you don't have to install a SSH client on your friend's computer, or invent your own secure protocol.

  • you could use docker, to simplify the IPython setup and to limit the file system access (for an unsophisticated user) – jfs Dec 25 '15 at 22:54
2

If you're already coding in Python, you could write a web front-end for your program using the http.server module in Python 3, or BaseHTTPServer in Python 2. Your program would then emit its output directly over HTTP to the remote browser. The details of how to do so are outside the scope of this site, but depending on your program it could be less than 10 lines of code.

Bear in mind that by doing this, you would lose all the authentication and authorization capability of SSH. In other words, this method doesn't allow the server to ensure that you or your colleague is the one accessing the page. If anyone else discovers the right URL, they can run your program, potentially many times in quick succession; they could crash it; they could attempt to hack it; etc. But if these risks are acceptable to you, it's probably hard to beat pure Python for simplicity.

It is possible to do authentication and authorization over HTTPS, of course, but then it's no longer so simple.

  • It might be simpler to start with bottle or flask micro frameworks, to create a wsgi app that could be served securely – jfs Dec 25 '15 at 22:58
  • Or twisted. – gaborous Dec 26 '15 at 0:31
1

Ubuntu has a package customized and pre-configured for Ubuntu that includes apache and mysql that you can install with sudo apt-get install lamp-server^. If you install that you will need to code software to do what you want to do; like a webservice where he enters a link and then sees the python output inside his browser window. I consider it overkill; unless you expect to do more with it.

But would it not be easier to create a script on the Windows machine that does the ssh, the execution on your server and download the output so he can see it? Seem trivial to me (well I do this all the time but do not use Windows to do this ;) ).

  • It is simplel, to run commands using something like fabric. – jfs Dec 25 '15 at 22:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.