0

In our ENV we have 2 jumphost server in which we try to get login and run ssh command on the remote server, we have ssh/confg file for each location with the help of sshproxy we get into the Jump2 server. we want to merge the config file so that we can access all the location server at the same time.

Refer Below ENV
Laptop --------> Jumphost1 ---------> Jumphost2 ---------> Remote server

Actually we are planning to run a script from my local machine and get the output stored in the local. So for archiving this task we need to do ssh to 2 jumphost and run the below command on remote server, which will run the script form the local machine and get the output on the local machine itself.

Jump1 is accessible via 2222 port user will be the same user

but to access remote server there is a different user1

ssh user1@ip < ./script >> file.txt &&

Set your ~/.ssh/config:

Host Jump1 User jump1user Port 2222 Host Jump2 ProxyCommand ssh -W %h:%p Jump1 User jump2user Host RemoveServer ProxyCommand ssh -W %h:%p Jump2 User remoteUser

With this above file we can directly login to jump2 server without any problem. But we have to change the config file every time for each location.

For running this below example ssh command in a script for gathering information from each region we need a single config file.

Example

ssh jump2 | ssh user1@remoteserver-ip < ./script >> file.txt &&

closed as unclear what you're asking by Jakuje, Rui F Ribeiro, Eric Renouf, jimmij, Gilles Apr 22 '17 at 21:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What did you try that didn't work? You can even use 'host *' to use the same ProxyCommand for all hosts. – ctx Apr 21 '17 at 15:49
  • We are having 2 file for each location one is the host file and the other is config file, ssh is done via hostname. how can we use host * to use the proxy command. – Shanker Apr 21 '17 at 16:42
2

I hope this example will enable you to use just one file:

Host *
    User username
    IdentityFile /home/username/.ssh/identity

Host some*
    ProxyCommand /usr/bin/ssh -p 2222 username@jumphost /usr/bin/nc %h %p 2> /dev/null

Host other*
    ProxyCommand /usr/bin/ssh -p 2222 username@otherjumphost /usr/bin/nc %h %p 2> /dev/null

Host something
    HostName 1.2.3.4

Host somethingelse
    HostName 2.3.4.5

Host otherthing
    HostName 3.4.5.6
  • How is it possible to to connect the Remote server it will ask password which we have give via command. – Shanker Apr 21 '17 at 17:42
2
Host remotehost
    ProxyCommand /usr/bin/ssh -p 2222 username@jumphost /usr/bin/nc %h %p 2> /dev/null

Since the jumphost is only accessible on port 2222 as you describe, you need to tell that fact to the proxy SSH connection.

As a further edit to the question has clarified that there are actually two hosts through which you will be proxying, this gets a little more complex, but only slightly so. Given:

  • local.example.com - The host on which you work directly
  • jump1.example.com - The host to which you directly connect from local
  • jump2.example.com - The host to which you directly connect from jump1
  • endpoint.example.com - The host to which you are ultimately connecting

On local.example.com, add the following to your SSH configuration:

host endpoint.example.com
    ProxyCommand /usr/bin/ssh -p 2222 username@jump1.example.com /usr/bin/nc %h %p 2> /dev/null

On jump1.example.com, add the following to your SSH configuration:

host endpoint.example.com
    ProxyCommand /user/bin/ssh -p 2222 username@jump2.example.com /usr/bin/nc %h %p 2> /dev/null

You will now be able to ssh endpoint@example.com from local.example.com though both proxies.

  • How is it possible to to connect the Remote server it will ask password which we have give via command. – Shanker Apr 21 '17 at 18:24
  • The authentication from the remote host gets passed back to you through the proxy; that's kind of the whole point. – DopeGhoti Apr 21 '17 at 18:50
  • I have added my config file to the question there is 2 jumphost and then the remote server. – Shanker Apr 24 '17 at 5:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.