1 \define{versionidplink} \versionid $Id$
3 \C{plink} Using the command-line connection tool \i{Plink}
5 \i{Plink} (PuTTY Link) is a command-line connection tool similar to
6 UNIX \c{ssh}. It is mostly used for \i{automated operations}, such as
7 making CVS access a repository on a remote server.
9 Plink is probably not what you want if you want to run an
10 \i{interactive session} in a console window.
12 \H{plink-starting} Starting Plink
14 Plink is a command line application. This means that you cannot just
15 double-click on its icon to run it and instead you have to bring up
16 a \i{console window}. In Windows 95, 98, and ME, this is called an
17 \q{MS-DOS Prompt}, and in Windows NT, 2000, and XP, it is called a
18 \q{Command Prompt}. It should be available from the Programs section
21 In order to use Plink, the file \c{plink.exe} will need either to be
22 on your \i{\c{PATH}} or in your current directory. To add the
23 directory containing Plink to your \c{PATH} environment variable,
24 type into the console window:
26 \c set PATH=C:\path\to\putty\directory;%PATH%
28 This will only work for the lifetime of that particular console
29 window. To set your \c{PATH} more permanently on Windows NT, 2000,
30 and XP, use the Environment tab of the System Control Panel. On
31 Windows 95, 98, and ME, you will need to edit your \i\c{AUTOEXEC.BAT}
32 to include a \c{set} command like the one above.
34 \H{plink-usage} Using Plink
36 This section describes the basics of how to use Plink for
37 interactive logins and for automated processes.
39 Once you've got a console window to type into, you can just type
40 \c{plink} on its own to bring up a usage message. This tells you the
41 version of Plink you're using, and gives you a brief summary of how to
45 \c PuTTY Link: command-line connection utility
47 \c Usage: plink [options] [user@]host [command]
48 \c ("host" can also be a PuTTY saved session name)
50 \c -V print version information and exit
51 \c -pgpfp print PGP key fingerprints and exit
52 \c -v show verbose messages
53 \c -load sessname Load settings from saved session
54 \c -ssh -telnet -rlogin -raw
55 \c force use of a particular protocol
56 \c -P port connect to specified port
57 \c -l user connect with specified username
58 \c -batch disable all interactive prompts
59 \c The following options only apply to SSH connections:
60 \c -pw passw login with specified password
61 \c -D [listen-IP:]listen-port
62 \c Dynamic SOCKS-based port forwarding
63 \c -L [listen-IP:]listen-port:host:port
64 \c Forward local port to remote address
65 \c -R [listen-IP:]listen-port:host:port
66 \c Forward remote port to local address
67 \c -X -x enable / disable X11 forwarding
68 \c -A -a enable / disable agent forwarding
69 \c -t -T enable / disable pty allocation
70 \c -1 -2 force use of particular protocol version
71 \c -4 -6 force use of IPv4 or IPv6
72 \c -C enable compression
73 \c -i key private key file for authentication
74 \c -noagent disable use of Pageant
75 \c -agent enable use of Pageant
76 \c -m file read remote command(s) from file
77 \c -s remote command is an SSH subsystem (SSH-2 only)
78 \c -N don't start a shell/command (SSH-2 only)
80 Once this works, you are ready to use Plink.
82 \S{plink-usage-interactive} Using Plink for interactive logins
84 To make a simple interactive connection to a remote server, just
85 type \c{plink} and then the host name:
87 \c Z:\sysosd>plink login.example.com
89 \c Debian GNU/Linux 2.2 flunky.example.com
92 You should then be able to log in as normal and run a session. The
93 output sent by the server will be written straight to your command
94 prompt window, which will most likely not interpret terminal \i{control
95 codes} in the way the server expects it to. So if you run any
96 full-screen applications, for example, you can expect to see strange
97 characters appearing in your window. Interactive connections like
98 this are not the main point of Plink.
100 In order to connect with a different protocol, you can give the
101 command line options \c{-ssh}, \c{-telnet}, \c{-rlogin} or \c{-raw}.
102 To make an SSH connection, for example:
104 \c Z:\sysosd>plink -ssh login.example.com
107 If you have already set up a PuTTY saved session, then instead of
108 supplying a host name, you can give the saved session name. This
109 allows you to use public-key authentication, specify a user name,
110 and use most of the other features of PuTTY:
112 \c Z:\sysosd>plink my-ssh-session
113 \c Sent username "fred"
114 \c Authenticating with public key "fred@winbox"
115 \c Last login: Thu Dec 6 19:25:33 2001 from :0.0
118 (You can also use the \c{-load} command-line option to load a saved
119 session; see \k{using-cmdline-load}. If you use \c{-load}, the saved
120 session exists, and it specifies a hostname, you cannot also specify a
121 \c{host} or \c{user@host} argument - it will be treated as part of the
124 \S{plink-usage-batch} Using Plink for automated connections
126 More typically Plink is used with the SSH protocol, to enable you to
127 talk directly to a program running on the server. To do this you
128 have to ensure Plink is \e{using} the SSH protocol. You can do this
131 \b Use the \c{-ssh} option as described in
132 \k{plink-usage-interactive}.
134 \b Set up a PuTTY saved session that describes the server you are
135 connecting to, and that also specifies the protocol as SSH.
137 \b Set the Windows environment variable \i\c{PLINK_PROTOCOL} to the
140 Usually Plink is not invoked directly by a user, but run
141 automatically by another process. Therefore you typically do not
142 want Plink to prompt you for a user name or a password.
144 Next, you are likely to need to avoid the various interactive
145 prompts Plink can produce. You might be prompted to verify the host
146 key of the server you're connecting to, to enter a user name, or to
149 To avoid being prompted for the server host key when using Plink for
150 an automated connection, you should first make a \e{manual}
151 connection (using either of PuTTY or Plink) to the same server,
152 verify the host key (see \k{gs-hostkey} for more information), and
153 select Yes to add the host key to the Registry. After that, Plink
154 commands connecting to that server should not give a host key prompt
155 unless the host key changes.
157 To avoid being prompted for a user name, you can:
159 \b Use the \c{-l} option to specify a user name on the command line.
160 For example, \c{plink login.example.com -l fred}.
162 \b Set up a PuTTY saved session that describes the server you are
163 connecting to, and that also specifies the username to log in as
164 (see \k{config-username}).
166 To avoid being prompted for a password, you should almost certainly
167 set up \i{public-key authentication}. (See \k{pubkey} for a general
168 introduction to public-key authentication.) Again, you can do this
171 \b Set up a PuTTY saved session that describes the server you are
172 connecting to, and that also specifies a private key file (see
173 \k{config-ssh-privkey}). For this to work without prompting, your
174 private key will need to have no passphrase.
176 \b Store the private key in Pageant. See \k{pageant} for further
179 Once you have done all this, you should be able to run a remote
180 command on the SSH server machine and have it execute automatically
183 \c Z:\sysosd>plink login.example.com -l fred echo hello, world
188 Or, if you have set up a saved session with all the connection
191 \c Z:\sysosd>plink mysession echo hello, world
196 Then you can set up other programs to run this Plink command and
197 talk to it as if it were a process on the server machine.
199 \S{plink-options} Plink command line options
201 Plink accepts all the general command line options supported by the
202 PuTTY tools. See \k{using-general-opts} for a description of these
205 Plink also supports some of its own options. The following sections
206 describe Plink's specific command-line options.
208 \S2{plink-option-batch} \I{-batch-plink}\c{-batch}: disable all
211 If you use the \c{-batch} option, Plink will never give an
212 interactive prompt while establishing the connection. If the
213 server's host key is invalid, for example (see \k{gs-hostkey}), then
214 the connection will simply be abandoned instead of asking you what
217 This may help Plink's behaviour when it is used in automated
218 scripts: using \c{-batch}, if something goes wrong at connection
219 time, the batch job will fail rather than hang.
221 \S2{plink-option-s} \I{-s-plink}\c{-s}: remote command is SSH subsystem
223 If you specify the \c{-s} option, Plink passes the specified command
224 as the name of an SSH \q{\i{subsystem}} rather than an ordinary command
227 (This option is only meaningful with the SSH-2 protocol.)
229 \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
231 Once you have set up Plink to be able to log in to a remote server
232 without any interactive prompting (see \k{plink-usage-batch}), you
233 can use it for lots of scripting and batch purposes. For example, to
234 start a backup on a remote machine, you might use a command like:
236 \c plink root@myserver /etc/backups/do-backup.sh
238 Or perhaps you want to fetch all system log lines relating to a
241 \c plink mysession grep /~fred/ /var/log/httpd/access.log > fredlog
243 Any non-interactive command you could usefully run on the server
244 command line, you can run in a batch file using Plink in this way.
246 \H{plink-cvs} Using Plink with \i{CVS}
248 To use Plink with CVS, you need to set the environment variable
249 \i\c{CVS_RSH} to point to Plink:
251 \c set CVS_RSH=\path\to\plink.exe
253 You also need to arrange to be able to connect to a remote host
254 without any interactive prompts, as described in
255 \k{plink-usage-batch}.
257 You should then be able to run CVS as follows:
259 \c cvs -d :ext:user@sessionname:/path/to/repository co module
261 If you specified a username in your saved session, you don't even
262 need to specify the \q{user} part of this, and you can just say:
264 \c cvs -d :ext:sessionname:/path/to/repository co module
266 \H{plink-wincvs} Using Plink with \i{WinCVS}
268 Plink can also be used with WinCVS. Firstly, arrange for Plink to be
269 able to connect to a remote host non-interactively, as described in
270 \k{plink-usage-batch}.
272 Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
273 \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
274 labelled \q{Check for an alternate \cw{rsh} name} and in the text
275 entry field to the right enter the full path to \c{plink.exe}.
276 Select \q{OK} on the \q{Preferences} dialogue box.
278 Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type
279 a CVS command as in \k{plink-cvs}, for example:
281 \c cvs -d :ext:user@hostname:/path/to/repository co module
283 or (if you're using a saved session):
285 \c cvs -d :ext:user@sessionname:/path/to/repository co module
287 Select the folder you want to check out to with the \q{Change Folder}
288 button, and click \q{OK} to check out your module. Once you've got
289 modules checked out, WinCVS will happily invoke plink from the GUI for
292 \# \H{plink-whatelse} Using Plink with... ?