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

查看:39
本文介绍了使用 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.

推荐答案

我没试过,但是这个 pysftp 模块可能会有所帮助,而后者又使用了 paramiko.我相信一切都是客户端.

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天全站免登陆