Python ssh - 脚本终止后保持连接打开

标签 python linux ssh paramiko

我正在尝试编写一个脚本,为我将 ssh 连接到一个盒子中。我正在使用 Python 并利用 paramiko 库。我可以在盒子上成功 ssh,但是一旦脚本终止,ssh 连接也会终止。我想在脚本运行完成后保持连接打开。

python :

self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(host, username=self.username, password=self.password)
stdout = execute(self.ssh, 'pwd') # test command for now to verify i'm on box
print stdout
sys.exit()

控制台:

$ ssh.py

[u'/home/myuser\n']

myuser@xxxx ~

$

我无法在网上找到类似的示例,因此不胜感激。

最佳答案

试试这个:

import subprocess
subprocess.call(["ssh", "myuser@myserver"])

关于Python ssh - 脚本终止后保持连接打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32016159/

相关文章:

python 2.5.2 : trying to open files recursively

php - 从 PHP 调用 Python 并获取返回码

linux - 自己的 DNS 服务器不工作(尝试找出主机的 IP 时出现 SERVFAIL)

c - 我已经在centos上安装了kernel-devel,还是找不到内核头文件

用于 SSH 和 Telnet 的 C# 库

python - 分层数据建模 - GAE

python - CountVectorizer 错误 : No such file or directory

linux - 检测操作系统架构并根据结果选择 file-x32 或 file-x64 的脚本

C# SSH 隧道 Postgres 数据库连接

python - 通过脚本结果进行远程 NFS 配置