OSDN Git Service

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