How to SSH via intermediate server [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite
1













This question already has an answer here:



  • Correct ssh config file settings to tunnel to a 3rd machine

    2 answers



Three server A,B & C. How to ssh connect from A to C via intermediate server B, if A to B & C to B are password less(key)? I encountered this in an interview. Anyone knows how?







share|improve this question













marked as duplicate by Jakuje, MelBurslan, jimmij, Anthon, Rui F Ribeiro Jun 15 '16 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
    – Jakuje
    Jun 15 '16 at 19:27

















up vote
1
down vote

favorite
1













This question already has an answer here:



  • Correct ssh config file settings to tunnel to a 3rd machine

    2 answers



Three server A,B & C. How to ssh connect from A to C via intermediate server B, if A to B & C to B are password less(key)? I encountered this in an interview. Anyone knows how?







share|improve this question













marked as duplicate by Jakuje, MelBurslan, jimmij, Anthon, Rui F Ribeiro Jun 15 '16 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
    – Jakuje
    Jun 15 '16 at 19:27













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1






This question already has an answer here:



  • Correct ssh config file settings to tunnel to a 3rd machine

    2 answers



Three server A,B & C. How to ssh connect from A to C via intermediate server B, if A to B & C to B are password less(key)? I encountered this in an interview. Anyone knows how?







share|improve this question














This question already has an answer here:



  • Correct ssh config file settings to tunnel to a 3rd machine

    2 answers



Three server A,B & C. How to ssh connect from A to C via intermediate server B, if A to B & C to B are password less(key)? I encountered this in an interview. Anyone knows how?





This question already has an answer here:



  • Correct ssh config file settings to tunnel to a 3rd machine

    2 answers









share|improve this question












share|improve this question




share|improve this question








edited Jun 15 '16 at 19:55









Jakuje

15.6k52850




15.6k52850









asked Jun 15 '16 at 18:26









user2700022

61




61




marked as duplicate by Jakuje, MelBurslan, jimmij, Anthon, Rui F Ribeiro Jun 15 '16 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Jakuje, MelBurslan, jimmij, Anthon, Rui F Ribeiro Jun 15 '16 at 19:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
    – Jakuje
    Jun 15 '16 at 19:27

















  • Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
    – Jakuje
    Jun 15 '16 at 19:27
















Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
– Jakuje
Jun 15 '16 at 19:27





Anyway, how do you want to connect to C, when you don't have the authentication there from B nor from A? There is probably some of the context missing, because at this time it does not make much sense, unless they wanted to hear from you about the remote port forwarding.
– Jakuje
Jun 15 '16 at 19:27











3 Answers
3






active

oldest

votes

















up vote
1
down vote













You are in server A:



ssh user@serverB ssh user@serverC 


Or you can use proxy command (see here for more info Proxies and Jump Hosts) as follows:



Create a config file under ~/.ssh in server A with following data:



Host serverC
HostName serverC
User user
ProxyCommand ssh -l user serverB -W %h:%p


Then you can just user ssh serverC to reach it from serverA via serverB.






share|improve this answer























  • This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
    – Jakuje
    Jun 15 '16 at 18:39










  • @Jakuje OK, updated link! Seems the wiki is up to date enough.
    – coffeMug
    Jun 15 '16 at 18:42











  • @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
    – user2700022
    Jun 15 '16 at 18:51










  • @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
    – user2700022
    Jun 15 '16 at 19:02










  • @user2700022 it should ask you for password.
    – coffeMug
    Jun 15 '16 at 19:05

















up vote
0
down vote














@coffeMug I tried out your 1st solution, it will work only if B->C
also is password less isn't ? here in my case A->B & C->B are password
less. but not B-> C.




Maybe, and only maybe C have a config allowing A, but does not communicate directly to A, requiring the middle server B only for the network communication. If that is true. iptables on server B using the table nat can do something for you.



Sorry i tried to help... so give it a try, is the only possibility, because in all others it will ask you for a password, because B->C no-password is required to this get working using ssh only.






share|improve this answer




























    up vote
    0
    down vote













    The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:



    Create a tunnel B->C from C:



    C$ ssh -R 2222:localhost:22 B


    and then connecting from A to C like this:



    A$ ssh A ssh -p 2222 localhost


    Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.






    share|improve this answer




























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      You are in server A:



      ssh user@serverB ssh user@serverC 


      Or you can use proxy command (see here for more info Proxies and Jump Hosts) as follows:



      Create a config file under ~/.ssh in server A with following data:



      Host serverC
      HostName serverC
      User user
      ProxyCommand ssh -l user serverB -W %h:%p


      Then you can just user ssh serverC to reach it from serverA via serverB.






      share|improve this answer























      • This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
        – Jakuje
        Jun 15 '16 at 18:39










      • @Jakuje OK, updated link! Seems the wiki is up to date enough.
        – coffeMug
        Jun 15 '16 at 18:42











      • @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
        – user2700022
        Jun 15 '16 at 18:51










      • @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
        – user2700022
        Jun 15 '16 at 19:02










      • @user2700022 it should ask you for password.
        – coffeMug
        Jun 15 '16 at 19:05














      up vote
      1
      down vote













      You are in server A:



      ssh user@serverB ssh user@serverC 


      Or you can use proxy command (see here for more info Proxies and Jump Hosts) as follows:



      Create a config file under ~/.ssh in server A with following data:



      Host serverC
      HostName serverC
      User user
      ProxyCommand ssh -l user serverB -W %h:%p


      Then you can just user ssh serverC to reach it from serverA via serverB.






      share|improve this answer























      • This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
        – Jakuje
        Jun 15 '16 at 18:39










      • @Jakuje OK, updated link! Seems the wiki is up to date enough.
        – coffeMug
        Jun 15 '16 at 18:42











      • @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
        – user2700022
        Jun 15 '16 at 18:51










      • @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
        – user2700022
        Jun 15 '16 at 19:02










      • @user2700022 it should ask you for password.
        – coffeMug
        Jun 15 '16 at 19:05












      up vote
      1
      down vote










      up vote
      1
      down vote









      You are in server A:



      ssh user@serverB ssh user@serverC 


      Or you can use proxy command (see here for more info Proxies and Jump Hosts) as follows:



      Create a config file under ~/.ssh in server A with following data:



      Host serverC
      HostName serverC
      User user
      ProxyCommand ssh -l user serverB -W %h:%p


      Then you can just user ssh serverC to reach it from serverA via serverB.






      share|improve this answer















      You are in server A:



      ssh user@serverB ssh user@serverC 


      Or you can use proxy command (see here for more info Proxies and Jump Hosts) as follows:



      Create a config file under ~/.ssh in server A with following data:



      Host serverC
      HostName serverC
      User user
      ProxyCommand ssh -l user serverB -W %h:%p


      Then you can just user ssh serverC to reach it from serverA via serverB.







      share|improve this answer















      share|improve this answer



      share|improve this answer








      edited Jun 15 '16 at 19:04


























      answered Jun 15 '16 at 18:35









      coffeMug

      6,50892345




      6,50892345











      • This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
        – Jakuje
        Jun 15 '16 at 18:39










      • @Jakuje OK, updated link! Seems the wiki is up to date enough.
        – coffeMug
        Jun 15 '16 at 18:42











      • @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
        – user2700022
        Jun 15 '16 at 18:51










      • @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
        – user2700022
        Jun 15 '16 at 19:02










      • @user2700022 it should ask you for password.
        – coffeMug
        Jun 15 '16 at 19:05
















      • This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
        – Jakuje
        Jun 15 '16 at 18:39










      • @Jakuje OK, updated link! Seems the wiki is up to date enough.
        – coffeMug
        Jun 15 '16 at 18:42











      • @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
        – user2700022
        Jun 15 '16 at 18:51










      • @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
        – user2700022
        Jun 15 '16 at 19:02










      • @user2700022 it should ask you for password.
        – coffeMug
        Jun 15 '16 at 19:05















      This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
      – Jakuje
      Jun 15 '16 at 18:39




      This article is very outdated. You should use ProxyCommand with the ssh -W switch, rather than the nc.
      – Jakuje
      Jun 15 '16 at 18:39












      @Jakuje OK, updated link! Seems the wiki is up to date enough.
      – coffeMug
      Jun 15 '16 at 18:42





      @Jakuje OK, updated link! Seems the wiki is up to date enough.
      – coffeMug
      Jun 15 '16 at 18:42













      @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
      – user2700022
      Jun 15 '16 at 18:51




      @coffeMug I understood the first method, can you please elaborate on using with proxy? if possible with eg?
      – user2700022
      Jun 15 '16 at 18:51












      @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
      – user2700022
      Jun 15 '16 at 19:02




      @coffeMug I tried out your 1st solution, it will work only if B->C also is password less isn't ? here in my case A->B & C->B are password less. but not B-> C.
      – user2700022
      Jun 15 '16 at 19:02












      @user2700022 it should ask you for password.
      – coffeMug
      Jun 15 '16 at 19:05




      @user2700022 it should ask you for password.
      – coffeMug
      Jun 15 '16 at 19:05












      up vote
      0
      down vote














      @coffeMug I tried out your 1st solution, it will work only if B->C
      also is password less isn't ? here in my case A->B & C->B are password
      less. but not B-> C.




      Maybe, and only maybe C have a config allowing A, but does not communicate directly to A, requiring the middle server B only for the network communication. If that is true. iptables on server B using the table nat can do something for you.



      Sorry i tried to help... so give it a try, is the only possibility, because in all others it will ask you for a password, because B->C no-password is required to this get working using ssh only.






      share|improve this answer

























        up vote
        0
        down vote














        @coffeMug I tried out your 1st solution, it will work only if B->C
        also is password less isn't ? here in my case A->B & C->B are password
        less. but not B-> C.




        Maybe, and only maybe C have a config allowing A, but does not communicate directly to A, requiring the middle server B only for the network communication. If that is true. iptables on server B using the table nat can do something for you.



        Sorry i tried to help... so give it a try, is the only possibility, because in all others it will ask you for a password, because B->C no-password is required to this get working using ssh only.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote










          @coffeMug I tried out your 1st solution, it will work only if B->C
          also is password less isn't ? here in my case A->B & C->B are password
          less. but not B-> C.




          Maybe, and only maybe C have a config allowing A, but does not communicate directly to A, requiring the middle server B only for the network communication. If that is true. iptables on server B using the table nat can do something for you.



          Sorry i tried to help... so give it a try, is the only possibility, because in all others it will ask you for a password, because B->C no-password is required to this get working using ssh only.






          share|improve this answer














          @coffeMug I tried out your 1st solution, it will work only if B->C
          also is password less isn't ? here in my case A->B & C->B are password
          less. but not B-> C.




          Maybe, and only maybe C have a config allowing A, but does not communicate directly to A, requiring the middle server B only for the network communication. If that is true. iptables on server B using the table nat can do something for you.



          Sorry i tried to help... so give it a try, is the only possibility, because in all others it will ask you for a password, because B->C no-password is required to this get working using ssh only.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jun 15 '16 at 19:26









          Luciano Andress Martini

          2,628725




          2,628725




















              up vote
              0
              down vote













              The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:



              Create a tunnel B->C from C:



              C$ ssh -R 2222:localhost:22 B


              and then connecting from A to C like this:



              A$ ssh A ssh -p 2222 localhost


              Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.






              share|improve this answer

























                up vote
                0
                down vote













                The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:



                Create a tunnel B->C from C:



                C$ ssh -R 2222:localhost:22 B


                and then connecting from A to C like this:



                A$ ssh A ssh -p 2222 localhost


                Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:



                  Create a tunnel B->C from C:



                  C$ ssh -R 2222:localhost:22 B


                  and then connecting from A to C like this:



                  A$ ssh A ssh -p 2222 localhost


                  Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.






                  share|improve this answer













                  The original question does not make much sense. But I can guess they wanted to ask about the servers A and C in private networks (so they do not "see" each other) and B visible to both of them. In this case, the answer is Remote Port Forwarding. With example:



                  Create a tunnel B->C from C:



                  C$ ssh -R 2222:localhost:22 B


                  and then connecting from A to C like this:



                  A$ ssh A ssh -p 2222 localhost


                  Or in more elegant way with ssh_config. You will have to certainly write the password to connect to the server C (localhost:2222 from B), if there is not set up pubkey authentication, but that should not be a problem.







                  share|improve this answer













                  share|improve this answer



                  share|improve this answer











                  answered Jun 15 '16 at 19:54









                  Jakuje

                  15.6k52850




                  15.6k52850












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?