3.8.3.5 -L, -R and -D: set up port forwardingsAs well as setting up port forwardings in the PuTTY configuration (see section 4.25
), you can also set up forwardings on the command line. The command-line options work just like the ones in Unix ssh programs. To forward a local port (say 5110) to a remote destination (say popserver.example.com port 110), you can write something like one of these: putty -L 5110:popserver.example.com:110 -load mysession
plink mysession -L 5110:popserver.example.com:110
To forward a remote port to a local destination, just use the -R option instead of -L: putty -R 5023:mytelnetserver.myhouse.org:23 -load mysession
plink mysession -R 5023:mytelnetserver.myhouse.org:23
To specify an IP address for the listening end of the tunnel, prepend it to the argument: plink -L 127.0.0.5:23:localhost:23 myhost
To set up SOCKS-based dynamic port forwarding on a local port, use the -D option. For this one you only have to pass the port number: putty -D 4096 -load mysession
For general information on port forwarding, see section 3.5
. These options are not available in the file transfer tools PSCP and PSFTP.
3.8.3.6 -m: read a remote command or script from a file The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1
). However, the -m option expects to be given a local file name, and it will read a command from that file. With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers. This option is not available in the file transfer tools PSCP and PSFTP.
3.8.3.7 -P: specify a port number The -P option is used to specify the port number to connect to. If you have a Telnet server running on port 9696 of a machine instead of port 23, for example:
putty -telnet -P 9696 host.name
plink -telnet -P 9696 host.name
(Note that this option is more useful in Plink than in PuTTY, because in PuTTY you can write putty -telnet host.name 9696 in any case.)
This option is equivalent to the port number control in the Session panel of the PuTTY configuration box (see section 4.1.1
). 3.8.3.8 -pw: specify a password A simple way to automate a remote login is to supply your password on the command line. This is not recommended for reasons of security. If you possibly can, we recommend you set up public-key authentication instead. See chapter 8
for details. Note that the -pw option only works when you are using the SSH protocol. Due to fundamental limitations of Telnet and Rlogin, these protocols do not support automated password authentication.