连接到SSH服务器

huangapple go评论75阅读模式
英文:

Connect to an SSH server

问题

我想制作一个程序,让我可以这样做:

./my_app connect prod

在运行这个命令之后,我希望能够像手动输入ssh user@ip一样登录到服务器,其中的user和ip会在程序中被猜测出来。

我不知道是否可以运行一个命令并附加到创建的进程上。

英文:

I'd like to make a program that will allow me to do that:

./my_app connect prod

After this command, I'd like to be logged in that server as I would have typed manually ssh user@ip where user and ip would be guessed inside the program.

I don't know if it is possible to run a command and attach to the process created

答案1

得分: 0

如果你只想在Linux上使用它,最简单的方法是调用syscall.Exec("/usr/bin/ssh", ..., os.Environ())。这将用SSH进程替换当前进程。

英文:

If you just want to use it on linux, the easiest wait is to call syscall.Exec("/usr/bin/ssh", ..., os.Environ()). This will replace the current process with the SSH process.

huangapple
  • 本文由 发表于 2022年1月13日 03:32:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/70687390.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定