加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用Fabric的远程交互式shell被CTRL-C杀死

发布时间:2020-12-15 20:56:02 所属栏目:安全 来源:网络整理
导读:我用一个简单的任务构建了一个Fabric fabfile,为我提供了一个远程交互式 shell: def shell(): open_shell() 我这样做而不是原始的ssh来节省输入:fabfile已经有每个远程配置的密钥路径,主机名等. 调用 fab shell 工作,但如果我在shell中按CTRL C,它会终止整
我用一个简单的任务构建了一个Fabric fabfile,为我提供了一个远程交互式 shell:

def shell():
  open_shell()

我这样做而不是原始的ssh来节省输入:fabfile已经有每个远程配置的密钥路径,主机名等.

调用

fab shell

工作,但如果我在shell中按CTRL C,它会终止整个连接.

是否可以使CTRL C转到远程交互式shell?

解决方法

我见过的用于python的ssh库中唯一一个使用ssh rfc描述的信号传递机制的是来自chilkatsoft的库.
来自RFC 4254:

6.9.  Signals

A signal can be delivered to the remote process/service using the
following message.  Some systems may not implement signals,in which
case they SHOULD ignore this message.

  byte      SSH_MSG_CHANNEL_REQUEST
  uint32    recipient channel
  string    "signal"
  boolean   FALSE
  string    signal name (without the "SIG" prefix)

'signal name' values will be encoded as discussed in the passage
describing SSH_MSG_CHANNEL_REQUEST messages using "exit-signal" in
this section.

您可以修改fabric以使用它而不是’ssh’库,然后向fabric添加信号处理程序以捕获SIGINT并调用SendReqSignal()将其发送到远程进程.

或者您可以使用stty调用来包装fabric以将INTR字符更改为其他内容,然后再将其更改回来.

#!/bin/sh
stty intr ^U
<whatever to invoke fabric>
stty intr ^C

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读