]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - doc/plink.but
351e13ea7dc6f83aba65dc4aa90ce7facdb78829
[PuTTY.git] / doc / plink.but
1 \C{plink} Using the command-line connection tool \i{Plink}
2
3 \i{Plink} is a command-line connection tool similar to UNIX \c{ssh}.
4 It is mostly used for \i{automated operations}, such as making CVS
5 access a repository on a remote server.
6
7 Plink is probably not what you want if you want to run an
8 \i{interactive session} in a console window.
9
10 \H{plink-starting} Starting Plink
11
12 Plink is a command line application. This means that you cannot just
13 double-click on its icon to run it and instead you have to bring up
14 a \i{console window}. In Windows 95, 98, and ME, this is called an
15 \q{MS-DOS Prompt}, and in Windows NT, 2000, and XP, it is called a
16 \q{Command Prompt}. It should be available from the Programs section
17 of your Start Menu.
18
19 In order to use Plink, the file \c{plink.exe} will need either to be
20 on your \i{\c{PATH}} or in your current directory. To add the
21 directory containing Plink to your \c{PATH} environment variable,
22 type into the console window:
23
24 \c set PATH=C:\path\to\putty\directory;%PATH%
25
26 This will only work for the lifetime of that particular console
27 window.  To set your \c{PATH} more permanently on Windows NT, 2000,
28 and XP, use the Environment tab of the System Control Panel.  On
29 Windows 95, 98, and ME, you will need to edit your \i\c{AUTOEXEC.BAT}
30 to include a \c{set} command like the one above.
31
32 \H{plink-usage} Using Plink
33
34 This section describes the basics of how to use Plink for
35 interactive logins and for automated processes.
36
37 Once you've got a console window to type into, you can just type
38 \c{plink} on its own to bring up a usage message.  This tells you the
39 version of Plink you're using, and gives you a brief summary of how to
40 use Plink:
41
42 \c Z:\sysosd>plink
43 \c Plink: command-line connection utility
44 \c Release 0.68
45 \c Usage: plink [options] [user@]host [command]
46 \c        ("host" can also be a PuTTY saved session name)
47 \c Options:
48 \c   -V        print version information and exit
49 \c   -pgpfp    print PGP key fingerprints and exit
50 \c   -v        show verbose messages
51 \c   -load sessname  Load settings from saved session
52 \c   -ssh -telnet -rlogin -raw -serial
53 \c             force use of a particular protocol
54 \c   -P port   connect to specified port
55 \c   -l user   connect with specified username
56 \c   -batch    disable all interactive prompts
57 \c   -proxycmd command
58 \c             use 'command' as local proxy
59 \c   -sercfg configuration-string (e.g. 19200,8,n,1,X)
60 \c             Specify the serial configuration (serial only)
61 \c The following options only apply to SSH connections:
62 \c   -pw passw login with specified password
63 \c   -D [listen-IP:]listen-port
64 \c             Dynamic SOCKS-based port forwarding
65 \c   -L [listen-IP:]listen-port:host:port
66 \c             Forward local port to remote address
67 \c   -R [listen-IP:]listen-port:host:port
68 \c             Forward remote port to local address
69 \c   -X -x     enable / disable X11 forwarding
70 \c   -A -a     enable / disable agent forwarding
71 \c   -t -T     enable / disable pty allocation
72 \c   -1 -2     force use of particular protocol version
73 \c   -4 -6     force use of IPv4 or IPv6
74 \c   -C        enable compression
75 \c   -i key    private key file for user authentication
76 \c   -noagent  disable use of Pageant
77 \c   -agent    enable use of Pageant
78 \c   -hostkey aa:bb:cc:...
79 \c             manually specify a host key (may be repeated)
80 \c   -m file   read remote command(s) from file
81 \c   -s        remote command is an SSH subsystem (SSH-2 only)
82 \c   -N        don't start a shell/command (SSH-2 only)
83 \c   -nc host:port
84 \c             open tunnel in place of session (SSH-2 only)
85 \c   -sshlog file
86 \c   -sshrawlog file
87 \c             log protocol details to a file
88 \c   -shareexists
89 \c             test whether a connection-sharing upstream exists
90
91 Once this works, you are ready to use Plink.
92
93 \S{plink-usage-interactive} Using Plink for interactive logins
94
95 To make a simple interactive connection to a remote server, just
96 type \c{plink} and then the host name:
97
98 \c Z:\sysosd>plink login.example.com
99 \c
100 \c Debian GNU/Linux 2.2 flunky.example.com
101 \c flunky login:
102
103 You should then be able to log in as normal and run a session. The
104 output sent by the server will be written straight to your command
105 prompt window, which will most likely not interpret terminal \i{control
106 codes} in the way the server expects it to. So if you run any
107 full-screen applications, for example, you can expect to see strange
108 characters appearing in your window. Interactive connections like
109 this are not the main point of Plink.
110
111 In order to connect with a different protocol, you can give the
112 command line options \c{-ssh}, \c{-telnet}, \c{-rlogin} or \c{-raw}.
113 To make an SSH connection, for example:
114
115 \c Z:\sysosd>plink -ssh login.example.com
116 \c login as:
117
118 If you have already set up a PuTTY saved session, then instead of
119 supplying a host name, you can give the saved session name. This
120 allows you to use public-key authentication, specify a user name,
121 and use most of the other features of PuTTY:
122
123 \c Z:\sysosd>plink my-ssh-session
124 \c Sent username "fred"
125 \c Authenticating with public key "fred@winbox"
126 \c Last login: Thu Dec  6 19:25:33 2001 from :0.0
127 \c fred@flunky:~$
128
129 (You can also use the \c{-load} command-line option to load a saved
130 session; see \k{using-cmdline-load}. If you use \c{-load}, the saved
131 session exists, and it specifies a hostname, you cannot also specify a
132 \c{host} or \c{user@host} argument - it will be treated as part of the
133 remote command.)
134
135 \S{plink-usage-batch} Using Plink for automated connections
136
137 More typically Plink is used with the SSH protocol, to enable you to
138 talk directly to a program running on the server. To do this you
139 have to ensure Plink is \e{using} the SSH protocol. You can do this
140 in several ways:
141
142 \b Use the \c{-ssh} option as described in
143 \k{plink-usage-interactive}.
144
145 \b Set up a PuTTY saved session that describes the server you are
146 connecting to, and that also specifies the protocol as SSH.
147
148 \b Set the Windows environment variable \i\c{PLINK_PROTOCOL} to the
149 word \c{ssh}.
150
151 Usually Plink is not invoked directly by a user, but run
152 automatically by another process. Therefore you typically do not
153 want Plink to prompt you for a user name or a password.
154
155 Next, you are likely to need to avoid the various interactive
156 prompts Plink can produce. You might be prompted to verify the host
157 key of the server you're connecting to, to enter a user name, or to
158 enter a password.
159
160 To avoid being prompted for the server host key when using Plink for
161 an automated connection, you should first make a \e{manual}
162 connection (using either of PuTTY or Plink) to the same server,
163 verify the host key (see \k{gs-hostkey} for more information), and
164 select Yes to add the host key to the Registry. After that, Plink
165 commands connecting to that server should not give a host key prompt
166 unless the host key changes.
167
168 To avoid being prompted for a user name, you can:
169
170 \b Use the \c{-l} option to specify a user name on the command line.
171 For example, \c{plink login.example.com -l fred}.
172
173 \b Set up a PuTTY saved session that describes the server you are
174 connecting to, and that also specifies the username to log in as
175 (see \k{config-username}).
176
177 To avoid being prompted for a password, you should almost certainly
178 set up \i{public-key authentication}. (See \k{pubkey} for a general
179 introduction to public-key authentication.) Again, you can do this
180 in two ways:
181
182 \b Set up a PuTTY saved session that describes the server you are
183 connecting to, and that also specifies a private key file (see
184 \k{config-ssh-privkey}). For this to work without prompting, your
185 private key will need to have no passphrase.
186
187 \b Store the private key in Pageant. See \k{pageant} for further
188 information.
189
190 Once you have done all this, you should be able to run a remote
191 command on the SSH server machine and have it execute automatically
192 with no prompting:
193
194 \c Z:\sysosd>plink login.example.com -l fred echo hello, world
195 \c hello, world
196 \c
197 \c Z:\sysosd>
198
199 Or, if you have set up a saved session with all the connection
200 details:
201
202 \c Z:\sysosd>plink mysession echo hello, world
203 \c hello, world
204 \c
205 \c Z:\sysosd>
206
207 Then you can set up other programs to run this Plink command and
208 talk to it as if it were a process on the server machine.
209
210 \S{plink-options} Plink command line options
211
212 Plink accepts all the general command line options supported by the
213 PuTTY tools. See \k{using-general-opts} for a description of these
214 options.
215
216 Plink also supports some of its own options. The following sections
217 describe Plink's specific command-line options.
218
219 \S2{plink-option-batch} \I{-batch-plink}\c{-batch}: disable all
220 interactive prompts
221
222 If you use the \c{-batch} option, Plink will never give an
223 interactive prompt while establishing the connection. If the
224 server's host key is invalid, for example (see \k{gs-hostkey}), then
225 the connection will simply be abandoned instead of asking you what
226 to do next.
227
228 This may help Plink's behaviour when it is used in automated
229 scripts: using \c{-batch}, if something goes wrong at connection
230 time, the batch job will fail rather than hang.
231
232 \S2{plink-option-s} \I{-s-plink}\c{-s}: remote command is SSH subsystem
233
234 If you specify the \c{-s} option, Plink passes the specified command
235 as the name of an SSH \q{\i{subsystem}} rather than an ordinary command
236 line.
237
238 (This option is only meaningful with the SSH-2 protocol.)
239
240 \S2{plink-option-shareexists} \I{-shareexists-plink}\c{-shareexists}:
241 test for connection-sharing upstream
242
243 This option does not make a new connection; instead it allows testing
244 for the presence of an existing connection that can be shared.
245 (See \k{config-ssh-sharing} for more information about SSH connection
246 sharing.)
247
248 A Plink invocation of the form:
249
250 \c plink -shareexists <session>
251 \e                    iiiiiiiii
252
253 will test whether there is currently a viable \q{upstream} for the
254 session in question, which can be specified using any syntax you'd
255 normally use with Plink to make an actual connection (a host/port
256 number, a bare saved session name, \c{-load}, etc). It returns a
257 zero exit status if a usable \q{upstream} exists, nonzero otherwise.
258
259 (This option is only meaningful with the SSH-2 protocol.)
260
261 \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
262
263 Once you have set up Plink to be able to log in to a remote server
264 without any interactive prompting (see \k{plink-usage-batch}), you
265 can use it for lots of scripting and batch purposes. For example, to
266 start a backup on a remote machine, you might use a command like:
267
268 \c plink root@myserver /etc/backups/do-backup.sh
269
270 Or perhaps you want to fetch all system log lines relating to a
271 particular web area:
272
273 \c plink mysession grep /~fred/ /var/log/httpd/access.log > fredlog
274
275 Any non-interactive command you could usefully run on the server
276 command line, you can run in a batch file using Plink in this way.
277
278 \H{plink-cvs} Using Plink with \i{CVS}
279
280 To use Plink with CVS, you need to set the environment variable
281 \i\c{CVS_RSH} to point to Plink:
282
283 \c set CVS_RSH=\path\to\plink.exe
284
285 You also need to arrange to be able to connect to a remote host
286 without any interactive prompts, as described in
287 \k{plink-usage-batch}.
288
289 You should then be able to run CVS as follows:
290
291 \c cvs -d :ext:user@sessionname:/path/to/repository co module
292
293 If you specified a username in your saved session, you don't even
294 need to specify the \q{user} part of this, and you can just say:
295
296 \c cvs -d :ext:sessionname:/path/to/repository co module
297
298 \H{plink-wincvs} Using Plink with \i{WinCVS}
299
300 Plink can also be used with WinCVS.  Firstly, arrange for Plink to be
301 able to connect to a remote host non-interactively, as described in
302 \k{plink-usage-batch}.
303
304 Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
305 \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
306 labelled \q{Check for an alternate \cw{rsh} name} and in the text
307 entry field to the right enter the full path to \c{plink.exe}.
308 Select \q{OK} on the \q{Preferences} dialogue box.
309
310 Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type 
311 a CVS command as in \k{plink-cvs}, for example:
312
313 \c cvs -d :ext:user@hostname:/path/to/repository co module
314
315 or (if you're using a saved session):
316
317 \c cvs -d :ext:user@sessionname:/path/to/repository co module
318
319 Select the folder you want to check out to with the \q{Change Folder}
320 button, and click \q{OK} to check out your module.  Once you've got
321 modules checked out, WinCVS will happily invoke plink from the GUI for
322 CVS operations.
323
324 \# \H{plink-whatelse} Using Plink with... ?