通过中间主机通过 SSH 连接到机器 [英] SSH to machine through a middle host

查看:40
本文介绍了通过中间主机通过 SSH 连接到机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我与教授的工作中,我必须通过 ssh 连接到我们的服务器,然后从那里通过 ssh 连接到每个节点以运行我们的程序.我正在尝试编写一个 python 程序,它可以让我从本地机器在远程节点上完成我需要做的一切.我将在节点上运行的命令是:

In my work with my professor I have to ssh into our server and from there I ssh into each node to run our programs. I am trying to write a python program that will let me do everything that I need to do on the remote node from my local machine. The commands that I will be running on the nodes are:

  • 从本地机器到远程节点的cp文件
  • 在每个节点上运行一个程序
  • 从节点检索文件到我的本地机器
  • 也许可以复制 Fortran 程序并在节点上编译它,还可以检查节点以查看是否有任何程序正在运行.

现在我在本地机器上制作我的输入文件,将它们 scp 到服务器,然后我将文件复制到每个节点并在每个节点上运行我们的 fluid_dynamics 程序.然后我做相反的事情,让我们的输出回到我的本地机器.

Right now I make my input files on my local machine, scp them to the server, then I copy the files to each node and run our fluid_dynamics program on each node. I then do the reverse to get our output back to my local machine.

我正在查看 paramiko,但我不知道如何使用它从我的本地机器到节点,因为我必须通过服务器.本地-ssh--> 服务器-ssh--> 节点

I was looking at paramiko but I can not figure out how I can use it to get from my local machine to the nodes because I must go through the server. local -ssh--> server -ssh--> nodes

有没有办法在 python 中做到这一点,或者我应该尝试其他方法,例如:使用:

Is there a way to do this in python or should I try something else such as: using:

os.system(ssh -t server ssh node 'command')   

或者在服务器上为每个不同的命令(compile.sh、move_inputs.sh、retrieve_outputs.sh)制作一个 bash 脚本,然后连接到服务器并运行 bash 脚本.

or making a bash scripts on the server for each of the different commands (compile.sh, move_inputs.sh, retrieve_outputs.sh) and then just connecting to the server and running the bash scripts.

很抱歉,如果这没有意义或措辞不当,我们不胜感激.

Sorry if this doesn't make sense or if it is worded badly, any help is appreciated.

附加信息:我使用 python 的原因是因为我希望程序能够制作输入文件,将它们发送到节点并检索输出文件,并最终生成我们的数据图.我已经有了一些代码来生成我们的输入文件并根据输出制作图表.

Additional Info: The reason I am using python is because I want the program to be able to make the input files, send them to the nodes and retrieve the output files, and to finally generate graphs of our data. I already have some code to generate our input files and to make the graphs from the outputs.

推荐答案

您不需要 Python 来执行此操作.检查 SSH 的 ProxyCommand 配置选项.这是解释详细信息的教程.

You don't need Python to do this. Check the ProxyCommand configuration option for SSH. Here is a tutorial that explains the details.

这篇关于通过中间主机通过 SSH 连接到机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆