plink.but 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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.70
  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 -noshare disable use of connection sharing
  68. \c -share enable use of connection sharing
  69. \c -hostkey aa:bb:cc:...
  70. \c manually specify a host key (may be repeated)
  71. \c -m file read remote command(s) from file
  72. \c -s remote command is an SSH subsystem (SSH-2 only)
  73. \c -N don't start a shell/command (SSH-2 only)
  74. \c -nc host:port
  75. \c open tunnel in place of session (SSH-2 only)
  76. \c -sshlog file
  77. \c -sshrawlog file
  78. \c log protocol details to a file
  79. \c -shareexists
  80. \c test whether a connection-sharing upstream exists
  81. Once this works, you are ready to use Plink.
  82. \S{plink-usage-interactive} Using Plink for interactive logins
  83. To make a simple interactive connection to a remote server, just
  84. type \c{plink} and then the host name:
  85. \c Z:\sysosd>plink login.example.com
  86. \c
  87. \c Debian GNU/Linux 2.2 flunky.example.com
  88. \c flunky login:
  89. You should then be able to log in as normal and run a session. The
  90. output sent by the server will be written straight to your command
  91. prompt window, which will most likely not interpret terminal \i{control
  92. codes} in the way the server expects it to. So if you run any
  93. full-screen applications, for example, you can expect to see strange
  94. characters appearing in your window. Interactive connections like
  95. this are not the main point of Plink.
  96. In order to connect with a different protocol, you can give the
  97. command line options \c{-ssh}, \c{-telnet}, \c{-rlogin} or \c{-raw}.
  98. To make an SSH connection, for example:
  99. \c Z:\sysosd>plink -ssh login.example.com
  100. \c login as:
  101. If you have already set up a PuTTY saved session, then instead of
  102. supplying a host name, you can give the saved session name. This
  103. allows you to use public-key authentication, specify a user name,
  104. and use most of the other features of PuTTY:
  105. \c Z:\sysosd>plink my-ssh-session
  106. \c Sent username "fred"
  107. \c Authenticating with public key "fred@winbox"
  108. \c Last login: Thu Dec 6 19:25:33 2001 from :0.0
  109. \c fred@flunky:~$
  110. (You can also use the \c{-load} command-line option to load a saved
  111. session; see \k{using-cmdline-load}. If you use \c{-load}, the saved
  112. session exists, and it specifies a hostname, you cannot also specify a
  113. \c{host} or \c{user@host} argument - it will be treated as part of the
  114. remote command.)
  115. \S{plink-usage-batch} Using Plink for automated connections
  116. More typically Plink is used with the SSH protocol, to enable you to
  117. talk directly to a program running on the server. To do this you
  118. have to ensure Plink is \e{using} the SSH protocol. You can do this
  119. in several ways:
  120. \b Use the \c{-ssh} option as described in
  121. \k{plink-usage-interactive}.
  122. \b Set up a PuTTY saved session that describes the server you are
  123. connecting to, and that also specifies the protocol as SSH.
  124. \b Set the Windows environment variable \i\c{PLINK_PROTOCOL} to the
  125. word \c{ssh}.
  126. Usually Plink is not invoked directly by a user, but run
  127. automatically by another process. Therefore you typically do not
  128. want Plink to prompt you for a user name or a password.
  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. To avoid being prompted for the server host key when using Plink for
  134. an automated connection, you should first make a \e{manual}
  135. connection (using either of PuTTY or Plink) to the same server,
  136. verify the host key (see \k{gs-hostkey} for more information), and
  137. select Yes to add the host key to the Registry. After that, Plink
  138. commands connecting to that server should not give a host key prompt
  139. unless the host key changes.
  140. To avoid being prompted for a user name, you can:
  141. \b Use the \c{-l} option to specify a user name on the command line.
  142. For example, \c{plink login.example.com -l fred}.
  143. \b Set up a PuTTY saved session that describes the server you are
  144. connecting to, and that also specifies the username to log in as
  145. (see \k{config-username}).
  146. To avoid being prompted for a password, you should almost certainly
  147. set up \i{public-key authentication}. (See \k{pubkey} for a general
  148. introduction to public-key authentication.) Again, you can do this
  149. in two ways:
  150. \b Set up a PuTTY saved session that describes the server you are
  151. connecting to, and that also specifies a private key file (see
  152. \k{config-ssh-privkey}). For this to work without prompting, your
  153. private key will need to have no passphrase.
  154. \b Store the private key in Pageant. See \k{pageant} for further
  155. information.
  156. Once you have done all this, you should be able to run a remote
  157. command on the SSH server machine and have it execute automatically
  158. with no prompting:
  159. \c Z:\sysosd>plink login.example.com -l fred echo hello, world
  160. \c hello, world
  161. \c
  162. \c Z:\sysosd>
  163. Or, if you have set up a saved session with all the connection
  164. details:
  165. \c Z:\sysosd>plink mysession echo hello, world
  166. \c hello, world
  167. \c
  168. \c Z:\sysosd>
  169. Then you can set up other programs to run this Plink command and
  170. talk to it as if it were a process on the server machine.
  171. \S{plink-options} Plink command line options
  172. Plink accepts all the general command line options supported by the
  173. PuTTY tools. See \k{using-general-opts} for a description of these
  174. options.
  175. Plink also supports some of its own options. The following sections
  176. describe Plink's specific command-line options.
  177. \S2{plink-option-batch} \I{-batch-plink}\c{-batch}: disable all
  178. interactive prompts
  179. If you use the \c{-batch} option, Plink will never give an
  180. interactive prompt while establishing the connection. If the
  181. server's host key is invalid, for example (see \k{gs-hostkey}), then
  182. the connection will simply be abandoned instead of asking you what
  183. to do next.
  184. This may help Plink's behaviour when it is used in automated
  185. scripts: using \c{-batch}, if something goes wrong at connection
  186. time, the batch job will fail rather than hang.
  187. \S2{plink-option-s} \I{-s-plink}\c{-s}: remote command is SSH subsystem
  188. If you specify the \c{-s} option, Plink passes the specified command
  189. as the name of an SSH \q{\i{subsystem}} rather than an ordinary command
  190. line.
  191. (This option is only meaningful with the SSH-2 protocol.)
  192. \S2{plink-option-share} \I{-share-plink}\c{-share}:
  193. Test and try to share an existing connection.
  194. This option tris to detect if an existing connection can be shared
  195. (See \k{config-ssh-sharing} for more information about SSH connection
  196. sharing.) and reuses that connection.
  197. A Plink invocation of the form:
  198. \c plink -share <session>
  199. \e iiiiiiiii
  200. will test whether there is currently a viable \q{upstream} for the
  201. session in question, which can be specified using any syntax you'd
  202. normally use with Plink to make an actual connection (a host/port
  203. number, a bare saved session name, \c{-load}, etc). If no \q{upstream}
  204. viable session is found and \c{-share} is specified, this connection
  205. will be become the \q{upstream} connection for subsequent connection
  206. sharing tries.
  207. (This option is only meaningful with the SSH-2 protocol.)
  208. \S2{plink-option-shareexists} \I{-shareexists-plink}\c{-shareexists}:
  209. test for connection-sharing upstream
  210. This option does not make a new connection; instead it allows testing
  211. for the presence of an existing connection that can be shared.
  212. (See \k{config-ssh-sharing} for more information about SSH connection
  213. sharing.)
  214. A Plink invocation of the form:
  215. \c plink -shareexists <session>
  216. \e iiiiiiiii
  217. will test whether there is currently a viable \q{upstream} for the
  218. session in question, which can be specified using any syntax you'd
  219. normally use with Plink to make an actual connection (a host/port
  220. number, a bare saved session name, \c{-load}, etc). It returns a
  221. zero exit status if a usable \q{upstream} exists, nonzero otherwise.
  222. (This option is only meaningful with the SSH-2 protocol.)
  223. \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
  224. Once you have set up Plink to be able to log in to a remote server
  225. without any interactive prompting (see \k{plink-usage-batch}), you
  226. can use it for lots of scripting and batch purposes. For example, to
  227. start a backup on a remote machine, you might use a command like:
  228. \c plink root@myserver /etc/backups/do-backup.sh
  229. Or perhaps you want to fetch all system log lines relating to a
  230. particular web area:
  231. \c plink mysession grep /~fred/ /var/log/httpd/access.log > fredlog
  232. Any non-interactive command you could usefully run on the server
  233. command line, you can run in a batch file using Plink in this way.
  234. \H{plink-cvs} Using Plink with \i{CVS}
  235. To use Plink with CVS, you need to set the environment variable
  236. \i\c{CVS_RSH} to point to Plink:
  237. \c set CVS_RSH=\path\to\plink.exe
  238. You also need to arrange to be able to connect to a remote host
  239. without any interactive prompts, as described in
  240. \k{plink-usage-batch}.
  241. You should then be able to run CVS as follows:
  242. \c cvs -d :ext:user@sessionname:/path/to/repository co module
  243. If you specified a username in your saved session, you don't even
  244. need to specify the \q{user} part of this, and you can just say:
  245. \c cvs -d :ext:sessionname:/path/to/repository co module
  246. \H{plink-wincvs} Using Plink with \i{WinCVS}
  247. Plink can also be used with WinCVS. Firstly, arrange for Plink to be
  248. able to connect to a remote host non-interactively, as described in
  249. \k{plink-usage-batch}.
  250. Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
  251. \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
  252. labelled \q{Check for an alternate \cw{rsh} name} and in the text
  253. entry field to the right enter the full path to \c{plink.exe}.
  254. Select \q{OK} on the \q{Preferences} dialogue box.
  255. Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type
  256. a CVS command as in \k{plink-cvs}, for example:
  257. \c cvs -d :ext:user@hostname:/path/to/repository co module
  258. or (if you're using a saved session):
  259. \c cvs -d :ext:user@sessionname:/path/to/repository co module
  260. Select the folder you want to check out to with the \q{Change Folder}
  261. button, and click \q{OK} to check out your module. Once you've got
  262. modules checked out, WinCVS will happily invoke plink from the GUI for
  263. CVS operations.
  264. \# \H{plink-whatelse} Using Plink with... ?