Connect to headless Linux Server through SSH

Connect to headless Linux Server through SSH

by Andre D -
Number of replies: 7

Hello everyone,

I am trying to develop a plugin to connect to a headless linux server through SSH which opens then in a new window. I can already connect to the server through SSH2, but is there any possibility to also open an interactive terminal? For example like you do in PuTTY.

Thanks in advance!

Average of ratings: -
In reply to Andre D

Re: Connect to headless Linux Server through SSH

by Ken Task -
Picture of Particularly helpful Moodlers

You've posted in what appears to be the right forum ... developers ... but ... wonder if you are kinda re-inventing the wheel.   While there is no publically available moodle plugin that does an ssh shell, many hosting providers do offer such via cPanel/Terminal.   If hosted on Google, Google's panel does allow configuration of something it calls OSLogin which is terminal/ssh into the hosted guest OS (Linux) environment.

If you do continue, a suggestion ... don't program it for the default ssh port 22, but rather, an unassigned port in the range 49152 to 65535 ... that for security purposes and getting away from script kiddie's that will hammer away at server.   Since many hosting providers are moving to metered each one of those hits (valid or not/errored or not) are counted as traffic thus pushing your bill for hosting higher than it should be.

That assumes you install script not running as root/superuser can set up a port in the OS to be allowed ... inbound/outbound ... which, I doubt it could. :|

My 2 cents as a non-programmer, however!

'SoS', Ken




In reply to Ken Task

Re: Connect to headless Linux Server through SSH

by Andre D -
Thanks for your answer, but unfortunately this is for a university project so I don't have any influence on the hosting provider. Maybe a bit more information on the side, the goal is that for example students can click on a link in a course and then a new window pops up where you can see the shell. I will keep the port security issue in mind, although the admin of the plugin should be able to set the port individually at the end.
In reply to Andre D

Re: Connect to headless Linux Server through SSH

by Ken Task -
Picture of Particularly helpful Moodlers

Not trying to burst bubbles or discourage since you say this is a project at a Uni, but ...

".... the goal is that for example students can click on a link in a course and then a new window pops up where you can see the shell."

As a former K12 server admin person, have to ask: what are students supposed to learn with shell access?  Surely these  student accounts will not be members of sudoers, will they?

Also have to ask ... have you ever had experience at administering a system for multiple users with shell access (just ssh - no web shell)?

There is a Virtual Programming Lab moodle plugin
https://moodle.org/plugins/mod_vpl

'SoS', Ken


In reply to Ken Task

Re: Connect to headless Linux Server through SSH

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
"what are students supposed to learn with shell access?"
Speaking from extensive teaching experience I suspect some will attempt to learn how to destroy your system.
In reply to Marcus Green

Re: Connect to headless Linux Server through SSH

by Ken Task -
Picture of Particularly helpful Moodlers

+1 Marcus ... true story follows ...

A liberally minded tech director of a small school whose students were generally well behaved (offline and on), setup a Linux server to allow students to learn how to do web pages.  Students had their own home directory and a public_html directory for publishing their DreamWeaver/other web creations.

Within a month of helping set that up, server out of space ... why?   One student was really interested in cars ... all makes, models, years, etc.    Spent a lot of time but managed to find the 'mother loads' of car pics ... ford, chevy, etc, and downloaded them to that server.   Nothing really malicious ... just resulted in an un-intended consequence of no quota's (duh!).

Now as to a script for ssh and moodle ... best, me thinks, if it could be restricted to the admin/server folks.   Advantage in admin of a moodle then ... git acquired code, git maintained moodle + ability to make site backups + take advantage of the cli scripts that do exist in moodle code.

Anyhoo, my 2 cents!

'SoS', Ken

 


In reply to Andre D

Re: Connect to headless Linux Server through SSH

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
>> the goal is that for example students can click on a link in a course and then a new window pops up where you can see the shell

That doesn't mean the shell runs "inside Moodle", unless you want to rewrite a Unix/Linux shell in JavaScript. There are all sorts of web magic that gives you the feeling, you're in Moodle but are somewhere else.
wink

See also the discussion Command line moodle plugin.
In reply to Andre D

Re: Connect to headless Linux Server through SSH

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Andre,

Google for "PHP Ajax terminal emulator" and integrate what makes sense into your plugin. Some limitations include:

1. These are probably only be compatible with Linux shell but it might be possible to make one that would be compatible with Windows Powershell or Command Prompt.

2. The user will have all of the powers of the user under which your web server is running.

3. Some of these may not support full screen applications such as "htop". However, there are some that do. It depends on your needs.

You may also think about looking for one that limits the list of commands that a user can use or even limits them to a particular directory and below. Again, it really depends on your expectations and how much you trust your students not to mess up your server.

I have actually been thinking of creating a plugin like this myself since quite a while. I would be very interested in seeing your plugin if you are open to sharing it.

I think it would complement well with my TinyFileManager plugin.

Best regards,

Michael Milette