abcf42fefec4b57ad6093605a802aafe347381a6
[u/mdw/putty] / doc / plink.but
1 \define{versionidplink} \versionid $Id$
2
3 \C{plink} Using the command-line connection tool Plink
4
5 \i{Plink} (PuTTY Link) is a command-line connection tool similar to
6 UNIX \c{ssh}. It is mostly used for automated operations, such as
7 making CVS access a repository on a remote server.
8
9 Plink is probably not what you want if you want to run an
10 interactive session in a console window.
11
12 \H{plink-starting} Starting Plink
13
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 and 2000 it is called a
18 \q{Command Prompt}. It should be available from the Programs section
19 of your Start Menu.
20
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:
25
26 \c set PATH=C:\path\to\putty\directory;%PATH%
27
28 This will only work for the lifetime of that particular console
29 window. To set your \c{PATH} more permanently on Windows NT, use the
30 Environment tab of the System Control Panel. On Windows 95, 98, and
31 ME, you will need to edit your \c{AUTOEXEC.BAT} to include a \c{set}
32 command like the one above.
33
34 \H{plink-usage} Using Plink
35
36 This section describes the basics of how to use Plink for
37 interactive logins and for automated processes.
38
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
42 use Plink:
43
44 \c Z:\sysosd>plink
45 \c PuTTY Link: command-line connection utility
46 \c Release 0.XX
47 \c Usage: plink [options] [user@]host [command]
48 \c ("host" can also be a PuTTY saved session name)
49 \c Options:
50 \c -V print version information
51 \c -v show verbose messages
52 \c -load sessname Load settings from saved session
53 \c -ssh -telnet -rlogin -raw
54 \c force use of a particular protocol
55 \c -P port connect to specified port
56 \c -l user connect with specified username
57 \c -m file read remote command(s) from file
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 -C enable compression
72 \c -i key private key file for authentication
73 \c -s remote command is an SSH subsystem (SSH-2 only)
74 \c -N don't start a shell/command (SSH-2 only)
75
76 Once this works, you are ready to use Plink.
77
78 \S{plink-usage-interactive} Using Plink for interactive logins
79
80 To make a simple interactive connection to a remote server, just
81 type \c{plink} and then the host name:
82
83 \c Z:\sysosd>plink login.example.com
84 \c
85 \c Debian GNU/Linux 2.2 flunky.example.com
86 \c flunky login:
87
88 You should then be able to log in as normal and run a session. The
89 output sent by the server will be written straight to your command
90 prompt window, which will most likely not interpret terminal control
91 codes in the way the server expects it to. So if you run any
92 full-screen applications, for example, you can expect to see strange
93 characters appearing in your window. Interactive connections like
94 this are not the main point of Plink.
95
96 In order to connect with a different protocol, you can give the
97 command line options \c{-ssh}, \c{-telnet}, \c{-rlogin} or \c{-raw}.
98 To make an SSH connection, for example:
99
100 \c Z:\sysosd>plink -ssh login.example.com
101 \c login as:
102
103 If you have already set up a PuTTY saved session, then instead of
104 supplying a host name, you can give the saved session name. This
105 allows you to use public-key authentication, specify a user name,
106 and use most of the other features of PuTTY:
107
108 \c Z:\sysosd>plink my-ssh-session
109 \c Sent username "fred"
110 \c Authenticating with public key "fred@winbox"
111 \c Last login: Thu Dec 6 19:25:33 2001 from :0.0
112 \c fred@flunky:~$
113
114 \S{plink-usage-batch} Using Plink for automated connections
115
116 More typically Plink is used with the SSH protocol, to enable you to
117 talk directly to a program running on the server. To do this you
118 have to ensure Plink is \e{using} the SSH protocol. You can do this
119 in several ways:
120
121 \b Use the \c{-ssh} option as described in
122 \k{plink-usage-interactive}.
123
124 \b Set up a PuTTY saved session that describes the server you are
125 connecting to, and that also specifies the protocol as SSH.
126
127 \b Set the Windows environment variable \c{PLINK_PROTOCOL} to the
128 word \c{ssh}.
129
130 Usually Plink is not invoked directly by a user, but run
131 automatically by another process. Therefore you typically do not
132 want Plink to prompt you for a user name or a password.
133
134 Next, you are likely to need to avoid the various interactive
135 prompts Plink can produce. You might be prompted to verify the host
136 key of the server you're connecting to, to enter a user name, or to
137 enter a password.
138
139 To avoid being prompted for the server host key when using Plink for
140 an automated connection, you should first make a \e{manual}
141 connection (using either of PuTTY or Plink) to the same server,
142 verify the host key (see \k{gs-hostkey} for more information), and
143 select Yes to add the host key to the Registry. After that, Plink
144 commands connecting to that server should not give a host key prompt
145 unless the host key changes.
146
147 To avoid being prompted for a user name, you can:
148
149 \b Use the \c{-l} option to specify a user name on the command line.
150 For example, \c{plink login.example.com -l fred}.
151
152 \b Set up a PuTTY saved session that describes the server you are
153 connecting to, and that also specifies the username to log in as
154 (see \k{config-username}).
155
156 To avoid being prompted for a password, you should almost certainly
157 set up public-key authentication. (See \k{pubkey} for a general
158 introduction to public-key authentication.) Again, you can do this
159 in two ways:
160
161 \b Set up a PuTTY saved session that describes the server you are
162 connecting to, and that also specifies a private key file (see
163 \k{config-ssh-privkey}). For this to work without prompting, your
164 private key will need to have no passphrase.
165
166 \b Store the private key in Pageant. See \k{pageant} for further
167 information.
168
169 Once you have done all this, you should be able to run a remote
170 command on the SSH server machine and have it execute automatically
171 with no prompting:
172
173 \c Z:\sysosd>plink login.example.com -l fred echo hello, world
174 \c hello, world
175 \c
176 \c Z:\sysosd>
177
178 Or, if you have set up a saved session with all the connection
179 details:
180
181 \c Z:\sysosd>plink mysession echo hello, world
182 \c hello, world
183 \c
184 \c Z:\sysosd>
185
186 Then you can set up other programs to run this Plink command and
187 talk to it as if it were a process on the server machine.
188
189 \S{plink-options} Plink command line options
190
191 Plink accepts all the general command line options supported by the
192 PuTTY tools. See \k{using-general-opts} for a description of these
193 options.
194
195 Plink also supports some of its own options. The following sections
196 describe Plink's specific command-line options.
197
198 \S2{plink-option-batch} \c{-batch}: disable all interactive prompts
199
200 If you use the \c{-batch} option, Plink will never give an
201 interactive prompt while establishing the connection. If the
202 server's host key is invalid, for example (see \k{gs-hostkey}), then
203 the connection will simply be abandoned instead of asking you what
204 to do next.
205
206 This may help Plink's behaviour when it is used in automated
207 scripts: using \c{-batch}, if something goes wrong at connection
208 time, the batch job will fail rather than hang.
209
210 \S2{plink-option-s} \c{-s}: remote command is SSH subsystem
211
212 If you specify the \c{-s} option, Plink passes the specified command
213 as the name of an SSH \q{subsystem} rather than an ordinary command
214 line.
215
216 (This option is only meaningful with the SSH-2 protocol.)
217
218 \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
219
220 Once you have set up Plink to be able to log in to a remote server
221 without any interactive prompting (see \k{plink-usage-batch}), you
222 can use it for lots of scripting and batch purposes. For example, to
223 start a backup on a remote machine, you might use a command like:
224
225 \c plink root@myserver /etc/backups/do-backup.sh
226
227 Or perhaps you want to fetch all system log lines relating to a
228 particular web area:
229
230 \c plink mysession grep /~fred/ /var/log/httpd/access.log > fredlog
231
232 Any non-interactive command you could usefully run on the server
233 command line, you can run in a batch file using Plink in this way.
234
235 \H{plink-cvs} Using Plink with \i{CVS}
236
237 To use Plink with CVS, you need to set the environment variable
238 \c{CVS_RSH} to point to Plink:
239
240 \c set CVS_RSH=\path\to\plink.exe
241
242 You also need to arrange to be able to connect to a remote host
243 without any interactive prompts, as described in
244 \k{plink-usage-batch}.
245
246 You should then be able to run CVS as follows:
247
248 \c cvs -d :ext:user@sessionname:/path/to/repository co module
249
250 If you specified a username in your saved session, you don't even
251 need to specify the \q{user} part of this, and you can just say:
252
253 \c cvs -d :ext:sessionname:/path/to/repository co module
254
255 \H{plink-wincvs} Using Plink with \i{WinCVS}
256
257 Plink can also be used with WinCVS. Firstly, arrange for Plink to be
258 able to connect to a remote host non-interactively, as described in
259 \k{plink-usage-batch}.
260
261 Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
262 \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
263 labelled \q{Check for an alternate \cw{rsh} name} and in the text
264 entry field to the right enter the full path to \c{plink.exe}.
265 Select \q{OK} on the \q{Preferences} dialogue box.
266
267 Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type
268 a CVS command as in \k{plink-cvs}, for example:
269
270 \c cvs -d :ext:user@hostname:/path/to/repository co module
271
272 or (if you're using a saved session):
273
274 \c cvs -d :ext:user@sessionname:/path/to/repository co module
275
276 Select the folder you want to check out to with the \q{Change Folder}
277 button, and click \q{OK} to check out your module. Once you've got
278 modules checked out, WinCVS will happily invoke plink from the GUI for
279 CVS operations.
280
281 \# \H{plink-whatelse} Using Plink with... ?