Connect with SSH through a proxy

后端 未结 11 1608
我在风中等你
我在风中等你 2020-12-12 09:03

I have no real idea what I\'m doing here so please bear that in mind if you can help me!

I am trying to connect to my virtual server through a proxy but I can\'t con

相关标签:
11条回答
  • 2020-12-12 09:43
    $ which nc
    /bin/nc
    
    $ rpm -qf /bin/nc
    nmap-ncat-7.40-7.fc26.x86_64
    
    $ ssh -o "ProxyCommand nc --proxy <addr[:port]> %h %p" USER@HOST
    
    $ ssh -o "ProxyCommand nc --proxy <addr[:port]> --proxy-type <type> --proxy-auth <auth> %h %p" USER@HOST
    
    0 讨论(0)
  • 2020-12-12 09:45

    Here's how to do Richard Christensen's answer as a one-liner, no file editing required (replace capitalized with your own settings, PROXYPORT is frequently 80):

     ssh USER@FINAL_DEST -o "ProxyCommand=nc -X connect -x PROXYHOST:PROXYPORT %h %p"
    

    You can use the same -o ... option for scp as well, see https://superuser.com/a/752621/39364

    If you get this in OS X:

     nc: invalid option -- X
     Try `nc --help' for more information.
    

    it may be that you're accidentally using the homebrew version of netcat (you can see by doing a which -a nc command--/usr/bin/nc should be listed first). If there are two then one workaround is to specify the full path to the nc you want, like ProxyCommand=/usr/bin/nc ...

    For CentOS nc has the same problem of invalid option --X. connect-proxy is an alternative, easy to install using yum and works --

    ssh -o ProxyCommand="connect-proxy -S PROXYHOST:PROXYPORT %h %p" USER@FINAL_DEST
    
    0 讨论(0)
  • 2020-12-12 09:48

    For windows, @shoaly parameters didn't completely work for me. I was getting this error:

    NCAT DEBUG: Proxy returned status code 501.
    Ncat: Proxy returned status code 501.
    ssh_exchange_identification: Connection closed by remote host
    

    I wanted to ssh to a REMOTESERVER and the SSH port had been closed in my network. I found two solutions but the second is better.

    • To solve the problem using Ncat:

      1. I downloaded Tor Browser, run and wait to connect.
      2. I got Ncat from Nmap distribution and extracted ncat.exe into the current directory.
      3. SSH using Ncat as ProxyCommand in Git Bash with addition --proxy-type socks4 parameter:

        ssh -o "ProxyCommand=./ncat --proxy-type socks4 --proxy 127.0.0.1:9150 %h %p" USERNAME@REMOTESERVER
        

        Note that this implementation of Ncat does not support socks5.

    • THE BETTER SOLUTION:

      1. Do the previous step 1.
      2. SSH using connect.c as ProxyCommand in Git Bash:

        ssh -o "ProxyCommand=connect -a none -S 127.0.0.1:9150 %h %p"
        

        Note that connect.c supports socks version 4/4a/5.

    To use the proxy in git commands using ssh (for example while using GitHub) -- assuming you installed Git Bash in C:\Program Files\Git\ -- open ~/.ssh/config and add this entry:

    host github.com
        user git
        hostname github.com
        port 22
        proxycommand "/c/Program Files/Git/mingw64/bin/connect.exe" -a none -S 127.0.0.1:9150 %h %p
    
    0 讨论(0)
  • 2020-12-12 09:48
    ProxyCommand nc -proxy xxx.com:8080 %h %p
    

    remove -X connect and use -proxy instead.

    Worked for me.

    0 讨论(0)
  • 2020-12-12 09:52

    I use -o "ProxyCommand=nc -X 5 -x proxyhost:proxyport %h %p" ssh option to connect through socks5 proxy on OSX.

    0 讨论(0)
  • 2020-12-12 09:53

    If your SSH proxy connection is going to be used often, you don't have to pass them as parameters each time. you can add the following lines to ~/.ssh/config

    Host foobar.example.com
        ProxyCommand          nc -X connect -x proxyhost:proxyport %h %p
        ServerAliveInterval   10
    

    then to connect use

    ssh foobar.example.com
    

    Source:

    http://www.perkin.org.uk/posts/ssh-via-http-proxy-in-osx.html

    0 讨论(0)
提交回复
热议问题