1 \versionid $Id: plink.but,v 1.16 2002/08/07 19:20:06 simon Exp $
3 \C{plink} Using the command-line connection tool Plink
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.
9 Plink is probably not what you want if you want to run an
10 interactive session in a console window.
12 \H{plink-starting} Starting Plink
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
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:
26 \c set PATH=C:\path\to\putty\directory;%PATH%
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.
34 \H{plink-usage} Using Plink
36 This section describes the basics of how to use Plink for
37 interactive logins and for automated processes.
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
45 \c PuTTY Link: command-line connection utility
47 \c Usage: plink [options] [user@]host [command]
49 \c -v show verbose messages
50 \c -ssh force use of ssh protocol
51 \c -P port connect to specified port
52 \c -pw passw login with specified password
54 Once this works, you are ready to use Plink.
56 \S{plink-usage-interactive} Using Plink for interactive logins
58 To make a simple interactive connection to a remote server, just
59 type \c{plink} and then the host name:
61 \c Z:\sysosd>plink login.example.com
63 \c Debian GNU/Linux 2.2 flunky.example.com
66 You should then be able to log in as normal and run a session. The
67 output sent by the server will be written straight to your command
68 prompt window, which will most likely not interpret terminal control
69 codes in the way the server expects it to. So if you run any
70 full-screen applications, for example, you can expect to see strange
71 characters appearing in your window. Interactive connections like
72 this are not the main point of Plink.
74 In order to connect with a different protocol, you can give the
75 command line options \c{-ssh}, \c{-telnet}, \c{-rlogin} or \c{-raw}.
76 To make an SSH connection, for example:
78 \c Z:\sysosd>plink -ssh login.example.com
81 If you have already set up a PuTTY saved session, then instead of
82 supplying a host name, you can give the saved session name. This
83 allows you to use public-key authentication, specify a user name,
84 and use most of the other features of PuTTY:
86 \c Z:\sysosd>plink my-ssh-session
87 \c Sent username "fred"
88 \c Authenticating with public key "fred@winbox"
89 \c Last login: Thu Dec 6 19:25:33 2001 from :0.0
92 \S{plink-usage-batch} Using Plink for automated connections
94 More typically Plink is used with the SSH protocol, to enable you to
95 talk directly to a program running on the server. To do this you
96 have to ensure Plink is \e{using} the SSH protocol. You can do this
99 \b Use the \c{-ssh} option as described in
100 \k{plink-usage-interactive}.
102 \b Set up a PuTTY saved session that describes the server you are
103 connecting to, and that also specifies the protocol as SSH.
105 \b Set the Windows environment variable \c{PLINK_PROTOCOL} to the
108 Usually Plink is not invoked directly by a user, but run
109 automatically by another process. Therefore you typically do not
110 want Plink to prompt you for a user name or a password.
112 To avoid being prompted for a user name, you can:
114 \b Use the \c{-l} option to specify a user name on the command line.
115 For example, \c{plink login.example.com -l fred}.
117 \b Set up a PuTTY saved session that describes the server you are
118 connecting to, and that also specifies the username to log in as
119 (see \k{config-username}).
121 To avoid being prompted for a password, you should almost certainly
122 set up public-key authentication. (See \k{pubkey} for a general
123 introduction to public-key authentication.) Again, you can do this
126 \b Set up a PuTTY saved session that describes the server you are
127 connecting to, and that also specifies a private key file (see
128 \k{config-ssh-privkey}). For this to work without prompting, your
129 private key will need to have no passphrase.
131 \b Store the private key in Pageant. See \k{pageant} for further
134 Once you have done all this, you should be able to run a remote
135 command on the SSH server machine and have it execute automatically
138 \c Z:\sysosd>plink login.example.com -l fred echo hello, world
143 Or, if you have set up a saved session with all the connection
146 \c Z:\sysosd>plink mysession echo hello, world
151 Then you can set up other programs to run this Plink command and
152 talk to it as if it were a process on the server machine.
154 \S{plink-options} Plink command line options
156 Plink accepts all the general command line options supported by the
157 PuTTY tools. See \k{using-general-opts} for a description of these
160 In addition to this, Plink accepts one other option: the \c{-batch}
161 option. If you use the \c{-batch} option, Plink will never give an
162 interactive prompt while establishing the connection. If the
163 server's host key is invalid, for example (see \k{gs-hostkey}), then
164 the connection will simply be abandoned instead of asking you what
167 This may help Plink's behaviour when it is used in automated
168 scripts: using \c{-batch}, if something goes wrong at connection
169 time, the batch job will fail rather than hang.
171 \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
173 Once you have set up Plink to be able to log in to a remote server
174 without any interactive prompting (see \k{plink-usage-batch}), you
175 can use it for lots of scripting and batch purposes. For example, to
176 start a backup on a remote machine, you might use a command like:
178 \c plink root@myserver /etc/backups/do-backup.sh
180 Or perhaps you want to fetch all system log lines relating to a
183 \c plink mysession grep /~fjbloggs/ /var/log/httpd/access.log > fredlogs
185 Any non-interactive command you could usefully run on the server
186 command line, you can run in a batch file using Plink in this way.
188 \H{plink-cvs} Using Plink with \i{CVS}
190 To use Plink with CVS, you need to set the environment variable
191 \c{CVS_RSH} to point to Plink:
193 \c set CVS_RSH=\path\to\plink.exe
195 You also need to arrange to be able to connect to a remote host
196 without any interactive prompts, as described in
197 \k{plink-usage-batch}.
199 You should then be able to run CVS as follows:
201 \c cvs -d :ext:user@sessionname:/path/to/repository co module
203 If you specified a username in your saved session, you don't even
204 need to specify the \q{user} part of this, and you can just say:
206 \c cvs -d :ext:sessionname:/path/to/repository co module
208 \H{plink-wincvs} Using Plink with \i{WinCVS}
210 Plink can also be used with WinCVS. Firstly, arrange for Plink to be
211 able to connect to a remote host non-interactively, as described in
212 \k{plink-usage-batch}.
214 Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
215 \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
216 labelled \q{Check for an alternate \cw{rsh} name} and in the text
217 entry field to the right enter the full path to \c{plink.exe}.
218 Select \q{OK} on the \q{Preferences} dialogue box.
220 Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type
221 a CVS command as in \k{plink-cvs}, for example:
223 \c cvs -d :ext:user@hostname:/path/to/repository co module
225 or (if you're using a saved session):
227 \c cvs -d :ext:user@sessionname:/path/to/repository co module
229 Select the folder you want to check out to with the \q{Change Folder}
230 button, and click \q{OK} to check out your module. Once you've got
231 modules checked out, WinCVS will happily invoke plink from the GUI for
234 \# \H{plink-whatelse} Using Plink with... ?