plink.but 13 KB

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