plink.but 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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 C:\>plink
  32. \c Plink: command-line connection utility
  33. \c Release 0.81
  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 -ssh-connection
  44. \c force use of the bare ssh-connection protocol
  45. \c -P port connect to specified port
  46. \c -l user connect with specified username
  47. \c -batch disable all interactive prompts
  48. \c -proxycmd command
  49. \c use 'command' as local proxy
  50. \c -sercfg configuration-string (e.g. 19200,8,n,1,X)
  51. \c Specify the serial configuration (serial only)
  52. \c The following options only apply to SSH connections:
  53. \c -pwfile file login with password read from specified file
  54. \c -D [listen-IP:]listen-port
  55. \c Dynamic SOCKS-based port forwarding
  56. \c -L [listen-IP:]listen-port:host:port
  57. \c Forward local port to remote address
  58. \c -R [listen-IP:]listen-port:host:port
  59. \c Forward remote port to local address
  60. \c -X -x enable / disable X11 forwarding
  61. \c -A -a enable / disable agent forwarding
  62. \c -t -T enable / disable pty allocation
  63. \c -1 -2 force use of particular SSH protocol version
  64. \c -4 -6 force use of IPv4 or IPv6
  65. \c -C enable compression
  66. \c -i key private key file for user authentication
  67. \c -noagent disable use of Pageant
  68. \c -agent enable use of Pageant
  69. \c -no-trivial-auth
  70. \c disconnect if SSH authentication succeeds trivially
  71. \c -noshare disable use of connection sharing
  72. \c -share enable use of connection sharing
  73. \c -hostkey keyid
  74. \c manually specify a host key (may be repeated)
  75. \c -sanitise-stderr, -sanitise-stdout, -no-sanitise-stderr, -no-sanitise-stdout
  76. \c do/don't strip control chars from standard output/error
  77. \c -no-antispoof omit anti-spoofing prompt after authentication
  78. \c -m file read remote command(s) from file
  79. \c -s remote command is an SSH subsystem (SSH-2 only)
  80. \c -N don't start a shell/command (SSH-2 only)
  81. \c -nc host:port
  82. \c open tunnel in place of session (SSH-2 only)
  83. \c -sshlog file
  84. \c -sshrawlog file
  85. \c log protocol details to a file
  86. \c -logoverwrite
  87. \c -logappend
  88. \c control what happens when a log file already exists
  89. \c -shareexists
  90. \c test whether a connection-sharing upstream exists
  91. Once this works, you are ready to use Plink.
  92. \S{plink-usage-interactive} Using Plink for interactive logins
  93. To make a simple interactive connection to a remote server, just
  94. type \c{plink} and then the host name:
  95. \c C:\>plink login.example.com
  96. \c
  97. \c Debian GNU/Linux 2.2 flunky.example.com
  98. \c flunky login:
  99. You should then be able to log in as normal and run a session. The
  100. output sent by the server will be written straight to your command
  101. prompt window, which will most likely not interpret terminal \i{control
  102. codes} in the way the server expects it to. So if you run any
  103. full-screen applications, for example, you can expect to see strange
  104. characters appearing in your window. Interactive connections like
  105. this are not the main point of Plink.
  106. In order to connect with a different protocol, you can give the
  107. command line options \c{-ssh}, \c{-ssh-connection}, \c{-telnet},
  108. \c{-rlogin}, or \c{-raw}. To make an SSH connection, for example:
  109. \c C:\>plink -ssh login.example.com
  110. \c login as:
  111. If you have already set up a PuTTY saved session, then instead of
  112. supplying a host name, you can give the saved session name. This
  113. allows you to use public-key authentication, specify a user name,
  114. and use most of the other features of PuTTY:
  115. \c C:\>plink my-ssh-session
  116. \c Sent username "fred"
  117. \c Authenticating with public key "fred@winbox"
  118. \c Last login: Thu Dec 6 19:25:33 2001 from :0.0
  119. \c fred@flunky:~$
  120. (You can also use the \c{-load} command-line option to load a saved
  121. session; see \k{using-cmdline-load}. If you use \c{-load}, the saved
  122. session exists, and it specifies a hostname, you cannot also specify a
  123. \c{host} or \c{user@host} argument - it will be treated as part of the
  124. remote command.)
  125. \S{plink-usage-batch} Using Plink for automated connections
  126. More typically Plink is used with the SSH protocol, to enable you to
  127. talk directly to a program running on the server. To do this you
  128. have to ensure Plink is \e{using} the SSH protocol. You can do this
  129. in several ways:
  130. \b Use the \c{-ssh} option as described in
  131. \k{plink-usage-interactive}.
  132. \b Set up a PuTTY saved session that describes the server you are
  133. connecting to, and that also specifies the protocol as SSH.
  134. \b Set the Windows environment variable \i\c{PLINK_PROTOCOL} to the
  135. word \c{ssh}.
  136. Usually Plink is not invoked directly by a user, but run
  137. automatically by another process. Therefore you typically do not
  138. want Plink to prompt you for a user name or a password.
  139. Next, you are likely to need to avoid the various interactive
  140. prompts Plink can produce. You might be prompted to verify the host
  141. key of the server you're connecting to, to enter a user name, or to
  142. enter a password.
  143. To avoid being prompted for the server host key when using Plink for
  144. an automated connection, you can first make a \e{manual}
  145. connection (using either of PuTTY or Plink) to the same server,
  146. verify the host key (see \k{gs-hostkey} for more information), and
  147. select \q{Accept} to add the host key to the Registry. After that,
  148. Plink commands connecting to that server should not give a host key
  149. prompt unless the host key changes. Alternatively, you can specify
  150. the appropriate host key(s) on Plink's command line every time you
  151. use it; see \k{using-cmdline-hostkey}.
  152. To avoid being prompted for a user name, you can:
  153. \b Use the \c{-l} option to specify a user name on the command line.
  154. For example, \c{plink login.example.com -l fred}.
  155. \b Set up a PuTTY saved session that describes the server you are
  156. connecting to, and that also specifies the username to log in as
  157. (see \k{config-username}).
  158. To avoid being prompted for a password, you should almost certainly
  159. set up \i{public-key authentication}. (See \k{pubkey} for a general
  160. introduction to public-key authentication.) Again, you can do this
  161. in two ways:
  162. \b Set up a PuTTY saved session that describes the server you are
  163. connecting to, and that also specifies a private key file (see
  164. \k{config-ssh-privkey}). For this to work without prompting, your
  165. private key will need to have no passphrase.
  166. \b Store the private key in Pageant. See \k{pageant} for further
  167. information.
  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. \c C:\>plink login.example.com -l fred echo hello, world
  172. \c hello, world
  173. \c
  174. \c C:\>
  175. Or, if you have set up a saved session with all the connection
  176. details:
  177. \c C:\>plink mysession echo hello, world
  178. \c hello, world
  179. \c
  180. \c C:\>
  181. Then you can set up other programs to run this Plink command and
  182. talk to it as if it were a process on the server machine.
  183. \S{plink-options} Plink command line options
  184. Plink accepts all the general command line options supported by the
  185. PuTTY tools. See \k{using-general-opts} for a description of these
  186. options.
  187. Plink also supports some of its own options. The following sections
  188. describe Plink's specific command-line options.
  189. \S2{plink-option-batch} \I{-batch-plink}\c{-batch}: disable all
  190. interactive prompts
  191. If you use the \c{-batch} option, Plink will never give an
  192. interactive prompt while establishing the connection. If the
  193. server's host key is invalid, for example (see \k{gs-hostkey}), then
  194. the connection will simply be abandoned instead of asking you what
  195. to do next.
  196. This may help Plink's behaviour when it is used in automated
  197. scripts: using \c{-batch}, if something goes wrong at connection
  198. time, the batch job will fail rather than hang.
  199. \S2{plink-option-s} \I{-s-plink}\c{-s}: remote command is SSH subsystem
  200. If you specify the \c{-s} option, Plink passes the specified command
  201. as the name of an SSH \q{\i{subsystem}} rather than an ordinary command
  202. line.
  203. (This option is only meaningful with the SSH-2 protocol.)
  204. \S2{plink-option-share} \I{-share-plink}\c{-share}:
  205. Test and try to share an existing connection.
  206. This option tries to detect if an existing connection can be shared
  207. (See \k{config-ssh-sharing} for more information about SSH connection
  208. sharing.) and reuses that connection.
  209. A Plink invocation of the form:
  210. \c plink -share <session>
  211. \e iiiiiiiii
  212. will test whether there is currently a viable \q{upstream} for the
  213. session in question, which can be specified using any syntax you'd
  214. normally use with Plink to make an actual connection (a host/port
  215. number, a bare saved session name, \c{-load}, etc). If no \q{upstream}
  216. viable session is found and \c{-share} is specified, this connection
  217. will be become the \q{upstream} connection for subsequent connection
  218. sharing tries.
  219. (This option is only meaningful with the SSH-2 protocol.)
  220. \S2{plink-option-shareexists} \I{-shareexists-plink}\c{-shareexists}:
  221. test for connection-sharing upstream
  222. This option does not make a new connection; instead it allows testing
  223. for the presence of an existing connection that can be shared.
  224. (See \k{config-ssh-sharing} for more information about SSH connection
  225. sharing.)
  226. A Plink invocation of the form:
  227. \c plink -shareexists <session>
  228. \e iiiiiiiii
  229. will test whether there is currently a viable \q{upstream} for the
  230. session in question, which can be specified using any syntax you'd
  231. normally use with Plink to make an actual connection (a host/port
  232. number, a bare saved session name, \c{-load}, etc). It returns a
  233. zero exit status if a usable \q{upstream} exists, nonzero otherwise.
  234. (This option is only meaningful with the SSH-2 protocol.)
  235. \S2{plink-option-sanitise} \I{-sanitise-stderr}\I{-sanitise-stdout}\I{-no-sanitise-stderr}\I{-no-sanitise-stdout}\c{-sanitise-}\e{stream}: control output sanitisation
  236. In some situations, Plink applies a sanitisation pass to the output
  237. received from the server, to strip out control characters such as
  238. backspace and the escape character.
  239. The idea of this is to prevent remote processes from sending confusing
  240. escape sequences through the standard error channel when Plink is
  241. being used as a transport for something like \cw{git} or CVS. If the
  242. server actually wants to send an error message, it will probably be
  243. plain text; if the server abuses that channel to try to write over
  244. unexpected parts of your terminal display, Plink will try to stop it.
  245. By default, this only happens for output channels which are sent to a
  246. Windows console device, or a Unix terminal device. (Any output stream
  247. going somewhere else is likely to be needed by an 8-bit protocol and
  248. must not be tampered with at all.) It also stops happening if you tell
  249. Plink to allocate a remote pseudo-terminal (see \k{using-cmdline-pty}
  250. and \k{config-ssh-pty}), on the basis that in that situation you often
  251. \e{want} escape sequences from the server to go to your terminal.
  252. But in case Plink guesses wrong about whether you want this
  253. sanitisation, you can override it in either direction, using one of
  254. these options:
  255. \dt \c{-sanitise-stderr}
  256. \dd Sanitise server data written to Plink's standard error channel,
  257. regardless of terminals and consoles and remote ptys.
  258. \dt \c{-no-sanitise-stderr}
  259. \dd Do not sanitise server data written to Plink's standard error
  260. channel.
  261. \dt \c{-sanitise-stdout}
  262. \dd Sanitise server data written to Plink's standard output channel.
  263. \dt \c{-no-sanitise-stdout}
  264. \dd Do not sanitise server data written to Plink's standard output
  265. channel.
  266. \S2{plink-option-antispoof} \i{-no-antispoof}: turn off authentication spoofing protection prompt
  267. In SSH, some possible server authentication methods require user input
  268. (for example, password authentication, or entering a private key
  269. passphrase), and others do not (e.g. a private key held in Pageant).
  270. If you use Plink to run an interactive login session, and if Plink
  271. authenticates without needing any user interaction, and if the server
  272. is malicious or compromised, it could try to trick you into giving it
  273. authentication data that should not go to the server (such as your
  274. private key passphrase), by sending what \e{looks} like one of Plink's
  275. local prompts, as if Plink had not already authenticated.
  276. To protect against this, Plink's default policy is to finish the
  277. authentication phase with a final trivial prompt looking like this:
  278. \c Access granted. Press Return to begin session.
  279. so that if you saw anything that looked like an authentication prompt
  280. \e{after} that line, you would know it was not from Plink.
  281. That extra interactive step is inconvenient. So Plink will turn it off
  282. in as many situations as it can:
  283. \b If Plink's standard input is not pointing at a console or terminal
  284. device \dash for example, if you're using Plink as a transport for
  285. some automated application like version control \dash then you
  286. \e{can't} type passphrases into the server anyway. In that situation,
  287. Plink won't try to protect you from the server trying to fool you into
  288. doing so.
  289. \b If Plink is in batch mode (see \k{plink-usage-batch}), then it
  290. \e{never} does any interactive authentication. So anything looking
  291. like an interactive authentication prompt is automatically suspect,
  292. and so Plink omits the anti-spoofing prompt.
  293. But if you still find the protective prompt inconvenient, and you
  294. trust the server not to try a trick like this, you can turn it off
  295. using the \cq{-no-antispoof} option.
  296. \H{plink-batch} Using Plink in \i{batch files} and \i{scripts}
  297. Once you have set up Plink to be able to log in to a remote server
  298. without any interactive prompting (see \k{plink-usage-batch}), you
  299. can use it for lots of scripting and batch purposes. For example, to
  300. start a backup on a remote machine, you might use a command like:
  301. \c plink root@myserver /etc/backups/do-backup.sh
  302. Or perhaps you want to fetch all system log lines relating to a
  303. particular web area:
  304. \c plink mysession grep /~fred/ /var/log/httpd/access.log > fredlog
  305. Any non-interactive command you could usefully run on the server
  306. command line, you can run in a batch file using Plink in this way.
  307. \H{plink-cvs} Using Plink with \i{CVS}
  308. To use Plink with CVS, you need to set the environment variable
  309. \i\c{CVS_RSH} to point to Plink:
  310. \c set CVS_RSH=\path\to\plink.exe
  311. You also need to arrange to be able to connect to a remote host
  312. without any interactive prompts, as described in
  313. \k{plink-usage-batch}.
  314. You should then be able to run CVS as follows:
  315. \c cvs -d :ext:user@sessionname:/path/to/repository co module
  316. If you specified a username in your saved session, you don't even
  317. need to specify the \q{user} part of this, and you can just say:
  318. \c cvs -d :ext:sessionname:/path/to/repository co module
  319. \H{plink-wincvs} Using Plink with \i{WinCVS}
  320. Plink can also be used with WinCVS. Firstly, arrange for Plink to be
  321. able to connect to a remote host non-interactively, as described in
  322. \k{plink-usage-batch}.
  323. Then, in WinCVS, bring up the \q{Preferences} dialogue box from the
  324. \e{Admin} menu, and switch to the \q{Ports} tab. Tick the box there
  325. labelled \q{Check for an alternate \cw{rsh} name} and in the text
  326. entry field to the right enter the full path to \c{plink.exe}.
  327. Select \q{OK} on the \q{Preferences} dialogue box.
  328. Next, select \q{Command Line} from the WinCVS \q{Admin} menu, and type
  329. a CVS command as in \k{plink-cvs}, for example:
  330. \c cvs -d :ext:user@hostname:/path/to/repository co module
  331. or (if you're using a saved session):
  332. \c cvs -d :ext:user@sessionname:/path/to/repository co module
  333. Select the folder you want to check out to with the \q{Change Folder}
  334. button, and click \q{OK} to check out your module. Once you've got
  335. modules checked out, WinCVS will happily invoke plink from the GUI for
  336. CVS operations.
  337. \# \H{plink-whatelse} Using Plink with... ?