从 Python 脚本启动交互式 SSH 会话 [英] Start interactive SSH session from Python script

查看:51
本文介绍了从 Python 脚本启动交互式 SSH 会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Python 脚本启动交互式 SSH 终端使用像 pexpect 或 paramiko 这样的模块 - 我想坚持使用 CentOS 预装 Python 提供的内容(以简化兼容性和部署问题).

I'd like to start an interactive SSH terminal from a Python script without using modules like pexpect or paramiko - I want to stick with what CentOS pre-installed Python provides me (to ease compatibility and deployment issues).

我可以使用 subprocess 模块很好地运行命令,但无法获得交互式终端.在 Perl 中,我只会使用反引号来实现这一点,但我正在寻找这样做的 Pythonic 方式.

I can run commands fine using the subprocess module, but cannot get an interactive terminal. In Perl, I would just use backticks to achieve this, but am looking for the pythonic way of doing this.

有人能指出我正确的方向吗?

Can someone point me in the right direction?

UPDATE - 基于@leoluk 的回答,我使用了 docs.python.org 提出:subprocess.call("ssh ...", shell=True)

UPDATE - based on @leoluk's answer, I used the instructions from docs.python.org to come up with: subprocess.call("ssh ...", shell=True)

推荐答案

如果我使用 os.system('ssh [...]')

这篇关于从 Python 脚本启动交互式 SSH 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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