New Plugin: SSH Interface - v0.0.1 ALPHA

I've been working on this plugin off and on for a bit now and after a few rewrites I'm finally at a point where I'm comfortable enough with the framework that I want to release an alpha build to those that might want to try it out and help improve it. This is flagged for py3 compat but don't expect it to work yet.. Expect issues.

I mainly wrote this for the terminal so everything else is just extra.

OctoPrint 1.4.0+ required.

This won't be going into the plugin repo for a while for obvious reasons.

2 Likes

Nice. I had done this with one my pis in the past, and just redirect a url path via haproxy to another port on the back end. You should include a very clear warning that you do not want to put this type of connection insecurely on the internet in any way.

Edit: and yeah, I wasn't paying attention and loaded in Python3 dev environment and sure enough, there were byte/str errors....lol.

Didn't think to ask, is this linux only by chance or you have to have a local ssh server running for it to connect to, because getting a weird error on startup in my Python 2 dev environment.

2020-04-28 20:58:35,270 - octoprint.plugin.core - INFO - Initialized 24 plugin implementation(s)
Exception in thread Thread-16:
Traceback (most recent call last):
  File "c:\python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\python27\Lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "c:\octoprint\venv\lib\site-packages\octoprint_sshinterface\__init__.py", line 106, in _run_ssh
    pubKey, privKey = self._load_ssh_keypair()
  File "c:\octoprint\venv\lib\site-packages\octoprint_sshinterface\__init__.py", line 66, in _load_ssh_keypair
    privateKey = keys.Key.fromString(data=privateBlob)
  File "c:\octoprint\venv\lib\site-packages\twisted\conch\ssh\keys.py", line 172, in fromString
    raise BadKeyError('cannot guess the type of %r' % (data,))
BadKeyError: cannot guess the type of ''

@jneilliii It's written in python and as such embedded into the plugin. No "real" SSH server required. Should be able to work on all operating systems.

90% sure the error is due to my lazy handling of the data directory. Take a look at what self.private_key_file = self._plugin_data_dir + '/id_rsa' resolves to.

Might have been related to my failed Python3 startup, my two dev virtualenv's share the same config path. After deleting/clearing the data and restarting OctoPrint it seems to load up fine without issues. I was able to SSH to the custom port 2222 and run commands.

How does this work with User Access (or does it)?

@OutsourcedGuru it requires Access Control to be enabled with valid users. Auth is run against the OctoPrint user DB. Permissions for actions are checked within the shell (Though I'm sure I missed something).

1 Like

Bumping my own thread. I've made some good progress on this. Here are some screenshots.




Testers appreciated. Requires OctoPrint 1.5.0+ w/ Python 3.

Trying to give this plugin a spin....

Octoprint Settings > Plugin Manager > Get More > Install from URL and pasted https://github.com/kantlivelong/OctoPrint-SSHInterface/archive/devel.zip.

Plug-in manger installs and prompts for restart, but the plug-in isn't listed anywhere upon restart :man_shrugging:t2:

SSH gets a "connection refused" when attempting to connect to port 2222, so I'm pretty sure I'm definitely doing something wrong (which is usually the case).....

Thoughts?

Make sure you're on python 3. Otherwise will need some logs.

On python 3.7.3

browser.user_agent : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15
connectivity.connection_check : 8.8.8.8:53
connectivity.connection_ok : true
connectivity.enabled : true
connectivity.online : true
connectivity.resolution_check : octoprint.org
connectivity.resolution_ok : true
env.hardware.cores : 4
env.hardware.freq : 1500
env.hardware.ram : 3959308288
env.os.bits : 32
env.os.id : linux
env.os.platform : linux
env.plugins.pi_support.model : Raspberry Pi 4 Model B Rev 1.2
env.plugins.pi_support.octopi_version : 0.18.0
env.plugins.pi_support.throttle_state : 0x0
env.python.pip : 20.2.4
env.python.version : 3.7.3
env.python.virtualenv : true
octoprint.safe_mode : false
octoprint.version : 1.5.3

Grabbling logs now... Anything inparticular?

Here's plugin_pluginmanager_console.log (38.6 KB)

that and octoprint.log should be good.

Yep... here's Octoprint.log |grep ssh output...

2021-03-10 22:54:06,100 - py.warnings - WARNING - /home/pi/oprint/lib/python3.7/site-packages/twisted/conch/ssh/common.py:14: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
2021-03-10 22:54:06,418 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 22:54:26,617 - py.warnings - WARNING - /home/pi/oprint/lib/python3.7/site-packages/twisted/conch/ssh/common.py:14: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
2021-03-10 22:54:26,848 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:09:47,171 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:09:52,564 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:10:21,484 - py.warnings - WARNING - /home/pi/oprint/lib/python3.7/site-packages/twisted/conch/ssh/common.py:14: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
2021-03-10 23:10:21,717 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:18:45,075 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:18:50,522 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)
2021-03-10 23:19:09,931 - py.warnings - WARNING - /home/pi/oprint/lib/python3.7/site-packages/twisted/conch/ssh/common.py:14: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead
2021-03-10 23:19:10,162 - octoprint.plugin.core - ERROR - Error loading plugin sshinterface
File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py", line 22, in
from . import commands as opsshcommands
ImportError: cannot import name 'commands' from 'octoprint_sshinterface' (/home/pi/oprint/lib/python3.7/site-packages/octoprint_sshinterface/init.py)

octoprint.log (652.8 KB)

Thanks. Looks like something was deprecated in python that Twisted relied on. They did fix it it but you likely don't have that version yet.

https://twistedmatrix.com/trac/ticket/9263

Assuming you are on OctoPi can you SSH in an run:

source ~/oprint/bin/activate
pip3 freeze | grep -i twisted

Edit: Actually just noticed thats from 2017. Lets check the version anyway.

Thanks it returns: Twisted==21.2.0

Hum strange. Going to look further.

Thanks buckets :slight_smile:

Hah doh I see the prob. Fix will be pushed in a few mins.