plink.but 12 KB

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