英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论