使用Python进行SSH的最简单方法是什么? [英] What is the simplest way to SSH using Python?

查看:175
本文介绍了使用Python进行SSH的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何简单地从本地Python(3.0)脚本SSH到远程服务器,提供登录名/密码,执行命令并将输出打印到Python控制台?

How can I simply SSH to a remote server from a local Python (3.0) script, supply a login/password, execute a command and print the output to the Python console?

我宁愿不使用任何大型外部库或在远程服务器上安装任何东西.

I would rather not use any large external library or install anything on the remote server.

推荐答案

我没有尝试过,但是

I haven't tried it, but this pysftp module might help, which in turn uses paramiko. I believe everything is client-side.

有趣的命令可能是.execute(),它在远程计算机上执行任意命令. (该模块还具有.get().put方法,这更多地暗示了它的FTP字符).

The interesting command is probably .execute() which executes an arbitrary command on the remote machine. (The module also features .get() and .put methods which allude more to its FTP character).

更新:

在我最初链接到的博客文章不再可用之后,我已经重新编写了答案.现在,某些引用此答案的旧版本的评论看起来很奇怪.

I've re-written the answer after the blog post I originally linked to is not available anymore. Some of the comments that refer to the old version of this answer will now look weird.

这篇关于使用Python进行SSH的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆