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