donv29560 2014-03-20 09:46
浏览 44
已采纳

去郎执行/产生一个SSH会话

I'm trying to work out the mechanism to fork/start a ssh terminal session i.e I want to be logged into remote server (my keys are on server) if I execute this program.

Right now it just executes but nothing happens.

package main

import (
 "os/exec"   
 "os"
)

func main() {
  cmd := exec.Command("ssh","root@SERVER-IP")
  cmd.Stdout = os.Stdout
  //cmd.Stderr = os.Stderr
  cmd.Run()

}
  • 写回答

2条回答 默认 最新

  • duaiwu8385 2014-03-20 10:01
    关注

    cmd.Run waits for the command to complete. Your ssh session should (normally) not exit without user interaction. Therefore your program blocks, since it waits for the ssh process to finish.

    You may want to either

    • also redirect Stdin, so you can interact with the ssh session
    • execute ssh me@server somecommand. In the last form a specific command gets executed and the output of this command gets redirected.
    • take a look at the ssh package
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度