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