linux - 以编程方式发送 SSH 转义字符

标签 linux bash ssh

当我通过 ssh (OpenSSH) 连接到服务器时,我可以输入“~C”进入 ssh 的命令行,然后打开一些隧道。有没有办法编写脚本或编写 C 程序来执行此操作?我想通过 ssh 连接到我的服务器,然后运行一个命令来打开隧道。

最佳答案

  • 在手动建立的 SSH session 中,不——无论程序输出到它的标准输出是什么
  • 否则您可以编写程序来驱动 ssh session 。或者你可以使用 expect 来驱动一个,如 http://ubuntuforums.org/showthread.php?t=220139 (或搜索 expect + ssh 以获取更多示例)
  • 驱动 SSH 客户端的程序可以使用服务器打印的信息来打开适当的隧道(通过读取服务器输出,然后在有足够信息时模拟 ~C 按键)

关于linux - 以编程方式发送 SSH 转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18774185/

相关文章:

linux - Autoconf 检查程序,如果找不到则失败

linux - 创建 Axis 2 .aar 文件时遇到问题 : xml/services not found error

bash - 意外标记 'done' 附近的混淆语法错误

unix - 在通过 ssh 的 nohup 期间我 ctr+c 之后会发生什么?

git - Capistrano + Git - "unable to find"[提交 SHA]

arrays - Array Bash 在多个数组的循环中打印元素

python - 运行 Caffe 会在 ksoftirqd/0 上产生高负载

bash - 预期脚本 : "event not found" while passing in argument

linux - 使用 sed 和 IFS 替换 while 循环中的值

php - 使用带有 net_ssh 的 phpseclib 如何使用 $ssh->exec su 到 root