Using the ProxyCommand Feature – Through an http Proxy
For the basics of this part see: OpenSSH Series (5) - Jumpserver and HTTP Proxy Usage
For complete usage see: Using a Proxy - HTTPProxy
1 | # note: the nc here must be netcat-openbsd (the openbsd version of nc; gnu's nc has no -X feature) |
Source Code
There was really no need to read the source; I mainly wanted to know how ssh connects using a proxy. Below is the related code, with comments added to the important parts. It mainly uses the pipe feature from the POSIX standard: a child process is created to connect to the proxy server, then the parent process communicates with the child via stdin/stdout redirection, and can thus communicate with the remote server. This code isn’t hard, but I suggest reading it together with the NodeJS-implemented proxy server in the blog.
Code source: https://github.com/openssh/libopenssh
1 | # search for the related code directly |
You can see the related code is in ssh/sshconnect.c
1 | // the ssh_connect function |
1 | /* |