-nc
: make a remote network connection in place of a remote shell or command
The -nc
option prevents Plink (or PuTTY) from attempting to start a shell or command on the remote server. Instead, it will instruct the remote server to open a network connection to a host name and port number specified by you, and treat that network connection as if it were the main session.
You specify a host and port as an argument to the -nc
option, with a colon separating the host name from the port number, like this:
plink host1.example.com -nc host2.example.com:1234
This can be useful if you're trying to make a connection to a target host which you can only reach by SSH forwarding through a proxy host. One way to do this would be to have an existing SSH connection to the proxy host, with a port forwarding, but if you prefer to have the connection started on demand as needed, then this approach can also work.
However, this does depend on the program using the proxy being able to run a subprocess in place of making a network connection. PuTTY itself can do this using the ‘Local’ proxy type, but there's a built-in more flexible way using the ‘SSH’ proxy type. (See section 4.16.1 for a description of both.) So this feature is probably most useful with another client program as the end user.
This feature is only available in SSH protocol version 2 (since the version 1 protocol assumes you will always want to run a shell). It is not available in the file transfer tools PSCP and PSFTP. It is available in PuTTY itself, although it is unlikely to be very useful in any tool other than Plink. Also, -nc
uses the same server functionality as port forwarding, so it will not work if your server administrator has disabled port forwarding.
(The option is named -nc
after the Unix program nc
, short for ‘netcat’. The command ‘plink host1 -nc host2:port
’ is very similar in functionality to ‘plink host1 nc host2 port
’, which invokes nc
on the server and tells it to connect to the specified destination. However, Plink's built-in -nc
option does not depend on the nc
program being installed on the server.)