Initial Commit
[packages] / xemacs-packages / tramp / texi / tramp.texi
1 \input texinfo   @c -*- mode: texinfo; coding: utf-8 -*-
2 @setfilename ../info/tramp
3 @c %**start of header
4 @settitle TRAMP User Manual
5 @include docstyle.texi
6 @c %**end of header
7
8 @c This is *so* much nicer :)
9 @footnotestyle end
10
11 @c In the Tramp repository, the version number is auto-frobbed from
12 @c configure.ac, so you should edit that file and run
13 @c "autoconf && ./configure" to change the version number.
14
15 @c Additionally, flags are set with respect to the Emacs flavor; and
16 @c depending whether Tramp is packaged into (X)Emacs, or standalone.
17
18 @include trampver.texi
19
20 @c Macro for formatting a file name according to the respective syntax.
21 @c xxx and yyy are auxiliary macros in order to omit leading and
22 @c trailing whitespace.  Not very elegant, but I don't know it better.
23
24 @c There are subtle differences between texinfo 4.13 and 5.0.  We must
25 @c declare two versions of the macro.  This will be improved, hopefully.
26
27 @c Texinfo 5.0.
28 @ifset txicommandconditionals
29 @macro xxx {one}
30 @set \one\
31 @end macro
32
33 @macro yyy {one, two}
34 @xxx{x\one\}@c
35 @ifclear x
36 \one\@w{}\two\@c
37 @end ifclear
38 @clear x\one\
39 @end macro
40
41 @macro trampfn {method, user, host, localname}
42 @value{prefix}@c
43 @yyy{\method\,@value{postfixhop}}@c
44 @yyy{\user\,@@}@c
45 \host\@value{postfix}\localname\
46 @end macro
47 @end ifset
48
49 @c Texinfo 4.13.
50 @ifclear txicommandconditionals
51 @macro xxx {one}@c
52 @set \one\@c
53 @end macro
54
55 @macro yyy {one, two}@c
56 @xxx{x\one\}@c
57 @ifclear x@c
58 \one\@w{}\two\@c
59 @end ifclear
60 @clear x\one\@c
61 @end macro
62
63 @macro trampfn {method, user, host, localname}@c
64 @value{prefix}@yyy{\method\,@value{postfixhop}}@yyy{\user\,@@}\host\@value{postfix}\localname\@c
65 @end macro
66 @end ifclear
67
68 @copying
69 Copyright @copyright{} 1999--2015 Free Software Foundation, Inc.
70
71 @quotation
72 Permission is granted to copy, distribute and/or modify this document
73 under the terms of the GNU Free Documentation License, Version 1.3 or
74 any later version published by the Free Software Foundation; with no
75 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
76 and with the Back-Cover Texts as in (a) below.  A copy of the license
77 is included in the section entitled ``GNU Free Documentation License''.
78
79 (a) The FSF's Back-Cover Text is: ``You have the freedom to
80 copy and modify this GNU manual.''
81 @end quotation
82 @end copying
83
84 @c Entries for @command{install-info} to use
85 @dircategory @value{emacsname} network features
86 @direntry
87 * TRAMP: (tramp).               Transparent Remote Access, Multiple Protocol
88                                   @value{emacsname} remote file access via ssh and scp.
89 @end direntry
90
91 @titlepage
92 @title @value{tramp} version @value{trampver} User Manual
93 @author by Daniel Pittman
94 @author based on documentation by Kai Großjohann
95 @page
96 @insertcopying
97 @end titlepage
98
99 @contents
100
101
102 @ifnottex
103 @node Top, Overview, (dir), (dir)
104 @top @value{tramp} version @value{trampver} User Manual
105
106 This file documents @value{tramp} version @value{trampver}, a remote file
107 editing package for @value{emacsname}.
108
109 @value{tramp} stands for ``Transparent Remote (file) Access, Multiple
110 Protocol''.  This package provides remote file editing, similar to
111 @value{ftppackagename}.
112
113 The difference is that @value{ftppackagename} uses FTP to transfer
114 files between the local and the remote host, whereas @value{tramp} uses a
115 combination of @command{rsh} and @command{rcp} or other work-alike
116 programs, such as @command{ssh}/@command{scp}.
117
118 You can find the latest version of this document on the web at
119 @uref{http://www.gnu.org/software/tramp/}.
120
121 @c Pointer to the other Emacs flavor is necessary only in case of
122 @c standalone installation.
123 @ifset installchapter
124 The manual has been generated for @value{emacsname}.
125 @ifinfo
126 If you want to read the info pages for @value{emacsothername}, you
127 should read in @ref{Installation} how to create them.
128 @end ifinfo
129 @ifhtml
130 If you're using the other Emacs flavor, you should read the
131 @uref{@value{emacsotherfilename}, @value{emacsothername}} pages.
132 @end ifhtml
133 @end ifset
134
135 @ifhtml
136 The latest release of @value{tramp} is available for
137 @uref{ftp://ftp.gnu.org/gnu/tramp/, download}, or you may see
138 @ref{Obtaining Tramp} for more details, including the Git server
139 details.
140
141 @value{tramp} also has a @uref{http://savannah.gnu.org/projects/tramp/,
142 Savannah Project Page}.
143 @end ifhtml
144
145 There is a mailing list for @value{tramp}, available at
146 @email{tramp-devel@@gnu.org}, and archived at
147 @uref{http://lists.gnu.org/archive/html/tramp-devel/, the
148 @value{tramp} Mail Archive}.
149 @ifhtml
150 Older archives are located at
151 @uref{http://sourceforge.net/mailarchive/forum.php?forum=tramp-devel,
152 SourceForge Mail Archive} and
153 @uref{http://www.mail-archive.com/emacs-rcp@@ls6.cs.uni-dortmund.de/,
154 The Mail Archive}.
155 @c in HTML output, there's no new paragraph.
156 @*@*
157 @end ifhtml
158
159 @insertcopying
160
161 @end ifnottex
162
163 @menu
164 * Overview::                    What @value{tramp} can and cannot do.
165
166 For the end user:
167
168 * Obtaining Tramp::             How to obtain @value{tramp}.
169 * History::                     History of @value{tramp}.
170 @ifset installchapter
171 * Installation::                Installing @value{tramp} with your @value{emacsname}.
172 @end ifset
173 * Configuration::               Configuring @value{tramp} for use.
174 * Usage::                       An overview of the operation of @value{tramp}.
175 * Bug Reports::                 Reporting Bugs and Problems.
176 * Frequently Asked Questions::  Questions and answers from the mailing list.
177
178 For the developer:
179
180 * Files directories and localnames::
181                                 How file names, directories and localnames
182                                   are mangled and managed.
183 * Traces and Profiles::         How to Customize Traces.
184 * Issues::                      Debatable Issues and What Was Decided.
185
186 * GNU Free Documentation License:: The license for this documentation.
187 * Function Index::              @value{tramp} functions.
188 * Variable Index::              User options and variables.
189 * Concept Index::               An item for each concept.
190
191 @detailmenu
192  --- The Detailed Node Listing ---
193 @c
194 @ifset installchapter
195 Installing @value{tramp} with your @value{emacsname}
196
197 * Installation parameters::     Parameters in order to control installation.
198 * Load paths::                  How to plug-in @value{tramp} into your environment.
199
200 @end ifset
201
202 Configuring @value{tramp} for use
203
204 * Connection types::            Types of connections to remote hosts.
205 * Inline methods::              Inline methods.
206 * External methods::            External methods.
207 @ifset emacsgvfs
208 * GVFS based methods::          GVFS based external methods.
209 @end ifset
210 @ifset emacsgw
211 * Gateway methods::             Gateway methods.
212 @end ifset
213 * Default Method::              Selecting a default method.
214 * Default User::                Selecting a default user.
215 * Default Host::                Selecting a default host.
216 * Multi-hops::                  Connecting to a remote host using multiple hops.
217 * Customizing Methods::         Using Non-Standard Methods.
218 * Customizing Completion::      Selecting config files for user/host name completion.
219 * Password handling::           Reusing passwords for several connections.
220 * Connection caching::          Reusing connection related information.
221 * Predefined connection information::
222                                 Setting own connection related information.
223 * Remote programs::             How @value{tramp} finds and uses programs on the remote host.
224 * Remote shell setup::          Remote shell setup hints.
225 * Android shell setup::         Android shell setup hints.
226 * Auto-save and Backup::        Auto-save and Backup.
227 * Windows setup hints::         Issues with Cygwin ssh.
228
229 Using @value{tramp}
230
231 * File name Syntax::            @value{tramp} file name conventions.
232 * File name completion::        File name completion.
233 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
234 * Remote processes::            Integration with other @value{emacsname} packages.
235 * Cleanup remote connections::  Cleanup remote connections.
236
237 How file names, directories and localnames are mangled and managed
238
239 * Localname deconstruction::    Breaking a localname into its components.
240 @ifset emacs
241 * External packages::           Integration with external Lisp packages.
242 @end ifset
243
244 @end detailmenu
245 @end menu
246
247
248 @node Overview
249 @chapter An overview of @value{tramp}
250 @cindex overview
251
252 @value{tramp} is for transparently accessing remote files from within
253 @value{emacsname}.  @value{tramp} enables an easy, convenient, and
254 consistent interface to remote files as if they are local files.
255 @value{tramp}'s transparency extends to editing, version control, and
256 @code{dired}.
257
258 @value{tramp} can access remote hosts using any number of access
259 methods, such as @command{rsh}, @command{rlogin}, @command{telnet},
260 and related programs.  If these programs can successfully pass
261 @acronym{ASCII]} characters, @value{tramp} can use them.
262 @value{tramp} does not require or mandate 8-bit clean connections.
263
264 @value{tramp}'s most common access method is through @command{ssh}, a
265 more secure alternative to @command{ftp} and other older access
266 methods.
267
268 @value{tramp} on Windows operating systems is integrated with the
269 PuTTY package, and uses the @command{plink} program.
270
271 @value{tramp} mostly operates transparently in the background using
272 the connection programs.  As long as these programs enable remote login
273 and can use the terminal, @value{tramp} can adapt them for seamless
274 and transparent access.
275
276 @value{tramp} temporarily transfers a remote file's contents to the
277 local host editing and related operations.  @value{tramp} can also
278 transfer files between hosts using standard Emacs interfaces, a
279 benefit of direct integration of @value{tramp} in @value{emacsname}.
280
281 @value{tramp} can transfer files using any number of available host
282 programs for remote files, such as @command{rcp}, @command{scp},
283 @command{rsync} or (under Windows) @command{pscp}.  @value{tramp}
284 provides easy ways to specify these programs and customize them to
285 specific files, hosts, or access methods.
286
287 For faster small-size file transfers, @value{tramp} supports encoded
288 transfers directly through the shell using @command{mimencode} or
289 @command{uuencode} provided such tools are available on the remote
290 host.
291
292
293 @subsubheading @value{tramp} behind the scenes
294 @cindex behind the scenes
295 @cindex details of operation
296 @cindex how it works
297
298 Accessing a remote file through @value{tramp} entails a series of
299 actions, many of which are transparent to the user.  Yet some actions
300 may require user response (such as entering passwords or completing
301 file names).  One typical scenario, opening a file on a remote host, is
302 presented here to illustrate the steps involved:
303
304 @kbd{C-x C-f} to initiate find-file, enter part of the @value{tramp}
305 file name, then hit @kbd{@key{TAB}} for completion.  If this is the
306 first time connection to that host, here's what happens:
307
308 @itemize
309 @item
310 @value{tramp} invokes @samp{telnet @var{host}} or @samp{rsh @var{host}
311 -l @var{user}} and establishes an external process to connect to the
312 remote host.  @value{tramp} communicates with the process through an
313 @value{emacsname} buffer, which also shows output from the remote
314 host.
315
316 @item
317 The remote host may prompt for a login name (for @command{telnet}, for
318 example) in the buffer.  If on the other hand, the login name was
319 included in the file name portion, @value{tramp} sends the login name
320 followed by a newline.
321
322 @item
323 The remote host may then prompt for a password or pass phrase (for
324 @command{rsh} or for @command{telnet}).  @value{tramp} displays the
325 password prompt in the minibuffer.  @value{tramp} then sends whatever
326 is entered to the remote host, followed by a newline.
327
328 @item
329 @value{tramp} now waits for either the shell prompt or a failed login
330 message.
331
332 If @value{tramp} does not receive any messages within a timeout period
333 (a minute, for example), then @value{tramp} responds with an error
334 message about not finding the remote shell prompt.  If any messages
335 from the remote host, @value{tramp} displays them in the buffer.
336
337 For any @samp{login failed} message from the remote host,
338 @value{tramp} aborts the login attempt, and repeats the login steps
339 again.
340
341 @item
342 Upon successful login and @value{tramp} recognizes the shell prompt
343 from the remote host, @value{tramp} prepares the shell environment by
344 turning off echoing, setting shell prompt, and other housekeeping
345 chores.
346
347 @strong{Note} that for the remote shell, @value{tramp} invokes
348 @command{/bin/sh}.  The remote host must recognize @samp{exec /bin/sh}
349 and execute the appropriate shell.  This shell must support Bourne
350 shell syntax.
351
352 @item
353 @value{tramp} executes @command{cd} and @command{ls} commands to find
354 which files exist on the remote host.  @value{tramp} sometimes uses
355 @command{echo} with globbing.  @value{tramp} checks if a file or
356 directory is writable with @command{test}.  After each command,
357 @value{tramp} parses the output from the remote host for completing
358 the next operation.
359
360 @item
361 After remote file name completion, @value{tramp} transfers the file
362 contents from the remote host.
363
364 For inline transfers, @value{tramp} sends a command, such as
365 @samp{mimencode -b /path/to/remote/file}, waits until the output has
366 accumulated in the buffer, decodes that output to produce the file's
367 contents.
368
369 For external transfers, @value{tramp} sends a command as follows:
370 @example
371 rcp user@@host:/path/to/remote/file /tmp/tramp.4711
372 @end example
373 @value{tramp} reads the local temporary file @file{/tmp/tramp.4711}
374 into a buffer, and then deletes the temporary file.
375
376 @item
377 Edit, modify, change the buffer contents as normal, and then save the
378 buffer wth @kbd{C-x C-s}.
379
380 @item
381 @value{tramp} transfers the buffer contents to the remote host in
382 a reverse of the process using the appropriate inline or external
383 program.
384 @end itemize
385
386 I hope this has provided you with a basic overview of what happens
387 behind the scenes when you open a file with @value{tramp}.
388
389
390 @c For the end user
391 @node Obtaining Tramp
392 @chapter Obtaining Tramp.
393 @cindex obtaining Tramp
394
395 @value{tramp} is included as part of Emacs (since Emacs version 22.1).
396
397 @value{tramp} is also freely packaged for download on the Internet at
398 @uref{ftp://ftp.gnu.org/gnu/tramp/}.
399
400 @value{tramp} development versions are available on Git servers.
401 Development versions contain new and incomplete features.
402
403 One way to obtain from Git server is to visit the Savannah project
404 page at the following URL and then clicking on the Git link in the
405 navigation bar at the top.
406
407 @noindent
408 @uref{http://savannah.gnu.org/projects/tramp/}
409
410 @noindent
411 Another way is to follow the terminal session below:
412
413 @example
414 ] @strong{cd ~/@value{emacsdir}}
415 ] @strong{git clone git://git.savannah.gnu.org/tramp.git}
416 @end example
417
418 @noindent
419 From behind a firewall:
420
421 @example
422 ] @strong{git config --global http.proxy http://user:pwd@@proxy.server.com:8080}
423 ] @strong{git clone http://git.savannah.gnu.org/r/tramp.git}
424 @end example
425
426 @noindent
427 Tramp developers:
428
429 @example
430 ] @strong{git clone login@@git.sv.gnu.org:/srv/git/tramp.git}
431 @end example
432
433 @noindent
434 After one of the above commands, @file{~/@value{emacsdir}/tramp} will
435 containing the latest version of @value{tramp}.
436
437 @noindent
438 To fetch updates from the repository, use git pull:
439
440 @example
441 ] @strong{cd ~/@value{emacsdir}/tramp}
442 ] @strong{git pull}
443 @end example
444
445 @noindent
446 Run @command{autoconf} as follows to generate an up-to-date
447 @file{configure} script:
448
449 @example
450 ] @strong{cd ~/@value{emacsdir}/tramp}
451 ] @strong{autoconf}
452 @end example
453
454
455 @node History
456 @chapter History of @value{tramp}
457 @cindex history
458 @cindex development history
459
460 @value{tramp} development started at the end of November 1998 as
461 @file{rssh.el}.  It provided only one method of access.  It used
462 @command{ssh} for login and @command{scp} to transfer file contents.
463 The name was changed to @file{rcp.el} before it got its preset name
464 @value{tramp}.  New methods of remote access were added, so was support
465 for version control.
466
467 April 2000 was the first time when multi-hop methods were added.  In
468 July 2002, @value{tramp} unified file names with Ange-FTP@.  In July
469 2004, proxy hosts replaced multi-hop methods.  Running commands on
470 remote hosts was introduced in December 2005.
471 @ifset emacsgw
472 Support for gateways since April 2007.
473 @end ifset
474 @ifset emacsgvfs
475 GVFS integration started in February 2009.
476 @end ifset
477 @ifset emacs
478 Remote commands on Windows hosts since September 2011.
479 @end ifset
480 Ad-hoc multi-hop methods (with a changed syntax) re-enabled in November
481 2011.
482
483 In November 2012, added Juergen Hoetzel's @file{tramp-adb.el}.
484
485 In December 2001, XEmacs package repository adds @value{tramp}.
486
487
488 @c Installation chapter is necessary only in case of standalone
489 @c installation.  Text taken from trampinst.texi.
490 @ifset installchapter
491 @include trampinst.texi
492 @end ifset
493
494
495 @node Configuration
496 @chapter Configuring @value{tramp}
497 @cindex configuration
498 @cindex default configuration
499
500 @value{tramp} is initially configured to use the @command{scp} program
501 to connect to the remote host.  Just type @kbd{C-x C-f} and then enter
502 file name @file{@trampfn{, user, host, /path/to.file}}.  For details,
503 see @xref{Default Method}.
504
505 For problems related to the behavior of remote shell, see @ref{Remote
506 shell setup} for details.
507
508 For changing the connection type and file access method from the
509 defaults to one of several other options, see (@pxref{Connection
510 types}).
511
512 @strong{Note} that some user options and variables described in these
513 examples are not auto loaded by @value{emacsname}.  All examples
514 require @value{tramp} is installed and loaded:
515
516 @lisp
517 (require 'tramp)
518 @end lisp
519
520
521 @menu
522 * Connection types::            Types of connections to remote hosts.
523 * Inline methods::              Inline methods.
524 * External methods::            External methods.
525 @ifset emacsgvfs
526 * GVFS based methods::          GVFS based external methods.
527 @end ifset
528 @ifset emacsgw
529 * Gateway methods::             Gateway methods.
530 @end ifset
531 * Default Method::              Selecting a default method.
532                                   Here we also try to help those who
533                                   don't have the foggiest which method
534                                   is right for them.
535 * Default User::                Selecting a default user.
536 * Default Host::                Selecting a default host.
537 * Multi-hops::                  Connecting to a remote host using multiple hops.
538 * Customizing Methods::         Using Non-Standard Methods.
539 * Customizing Completion::      Selecting config files for user/host name completion.
540 * Password handling::           Reusing passwords for several connections.
541 * Connection caching::          Reusing connection related information.
542 * Predefined connection information::
543                                 Setting own connection related information.
544 * Remote programs::             How @value{tramp} finds and uses programs on the remote host.
545 * Remote shell setup::          Remote shell setup hints.
546 * Android shell setup::         Android shell setup hints.
547 * Auto-save and Backup::        Auto-save and Backup.
548 * Windows setup hints::         Issues with Cygwin ssh.
549 @end menu
550
551
552 @node Connection types
553 @section Types of connections to remote hosts
554 @cindex connection types, overview
555
556 @dfn{Inline method} and @dfn{external method} are the two basic types
557 of access methods.  While they both use the same remote shell access
558 programs, such as @command{rsh}, @command{ssh}, or @command{telnet},
559 they differ in the file access methods.  Choosing the right method
560 becomes important for editing files, transferring large files, or
561 operating on a large number of files.
562
563 @cindex inline methods
564 @cindex external methods
565 @cindex methods, inline
566 @cindex methods, external
567
568 The performance of the external methods is generally better than that
569 of the inline methods, at least for large files.  This is caused by
570 the need to encode and decode the data when transferring inline.
571
572 The one exception to this rule are the @option{scp}-based access
573 methods.  While these methods do see better performance when actually
574 transferring files, the overhead of the cryptographic negotiation at
575 startup may drown out the improvement in file transfer times.
576
577 External methods should be configured such a way that they don't
578 require a password (with @command{ssh-agent}, or such alike).  Modern
579 @command{scp} implementations offer options to reuse existing
580 @command{ssh} connections, which will be enabled by default if
581 available.  If it isn't possible, you should consider @ref{Password
582 handling}, otherwise you will be prompted for a password every copy
583 action.
584
585
586 @node Inline methods
587 @section Inline methods
588 @cindex inline methods
589 @cindex methods, inline
590
591 Inline methods use the same login connection to transfer file
592 contents.  Inline methods are quick and easy for small files.  They
593 depend on the availability of suitable encoding and decoding programs
594 on the remote host.  For local source and destination, @value{tramp}
595 may use built-in equivalents of such programs in @value{emacsname}.
596
597 Inline methods can work in situations where an external transfer
598 program is unavailable.  Inline methods also work when transferring
599 files between different @emph{user identities} on the same host.
600
601 @cindex uuencode
602 @cindex mimencode
603 @cindex base-64 encoding
604
605 @value{tramp} checks the remote host for the availability and
606 usability of @command{mimencode} (part of the @command{metamail}
607 package) or @command{uuencode}.  @value{tramp} uses the first reliable
608 command it finds.  @value{tramp}'s search path can be customized, see
609 @ref{Remote programs}.
610
611 In case both @command{mimencode} and @command{uuencode} are
612 unavailable, @value{tramp} first transfers a small Perl program to the
613 remote host, and then tries that program for encoding and decoding.
614
615 To increase transfer speeds for large text files, use compression
616 before encoding.  The variable @var{tramp-inline-compress-start-size}
617 specifies the file size for such optimization.
618
619 @table @asis
620 @item @option{rsh}
621 @cindex method rsh
622 @cindex rsh method
623
624 @command{rsh} is an option for connecting to hosts within local
625 networks since @command{rsh} is not as secure as other methods.
626
627
628 @item @option{ssh}
629 @cindex method ssh
630 @cindex ssh method
631
632 @command{ssh} is a more secure option than others to connect to a
633 remote host.
634
635 @command{ssh} can also take extra parameters as port numbers.  For
636 example, a host on port 42 is specified as @file{host#42} (the real
637 host name, a hash sign, then a port number).  It is the same as passing
638 @code{-p 42} to the @command{ssh} command.
639
640 @item @option{telnet}
641 @cindex method telnet
642 @cindex telnet method
643
644 Connecting to a remote host with @command{telnet} is as insecure
645 as the @option{rsh} method.
646
647
648 @item @option{su}
649 @cindex method su
650 @cindex su method
651
652 Instead of connecting to a remote host, @command{su} program allows
653 editing as another user.  The host can be either @samp{localhost} or
654 the host returned by the function @command{(system-name)}.  See
655 @ref{Multi-hops} for an exception to this behavior.
656
657 @item @option{sudo}
658 @cindex method sudo
659 @cindex sudo method
660
661 Similar to @option{su} method, @option{sudo} uses @command{sudo}.
662 @command{sudo} must have sufficient rights to start a shell.
663
664 @item @option{sshx}
665 @cindex method sshx
666 @cindex sshx method
667
668 Works like @option{ssh} but without the extra authentication prompts.
669 @option{sshx} uses @samp{ssh -t -t @var{host} -l @var{user} /bin/sh}
670 to open a connection with a ``standard'' login shell.
671
672 @strong{Note} that @option{sshx} does not bypass authentication
673 questions.  For example, if the host key of the remote host is not
674 known, @option{sshx} will still ask ``Are you sure you want to
675 continue connecting?''.  @value{tramp} cannot handle such questions.
676 Connections will have to be setup where logins can proceed without
677 such questions.
678
679 @option{sshx} is useful for Windows users when @command{ssh} triggers
680 an error about allocating a pseudo tty.  This happens due to missing
681 shell prompts that confuses @value{tramp}.
682
683 @option{sshx} supports the @samp{-p} argument.
684
685 @item @option{krlogin}
686 @cindex method krlogin
687 @cindex krlogin method
688 @cindex Kerberos (with krlogin method)
689
690 This method is also similar to @option{ssh}.  It uses the
691 @command{krlogin -x} command only for remote host login.
692
693 @item @option{ksu}
694 @cindex method ksu
695 @cindex ksu method
696 @cindex Kerberos (with ksu method)
697
698 This is another method from the Kerberos suite.  It behaves like @option{su}.
699
700
701 @item @option{plink}
702 @cindex method plink
703 @cindex plink method
704
705 @option{plink} method is for Windows users with the PuTTY
706 implementation of SSH@.  It uses @samp{plink -ssh} to log in to the
707 remote host.
708
709 Check the @samp{Share SSH connections if possible} control for that
710 session.
711
712 @option{plink} method supports the @samp{-P} argument.
713
714
715 @item @option{plinkx}
716 @cindex method plinkx
717 @cindex plinkx method
718
719 Another method using PuTTY on Windows with session names instead of
720 host names.  @option{plinkx} calls @samp{plink -load @var{session} -t}.
721 User names and port numbers must be defined in the session.
722
723 Check the @samp{Share SSH connections if possible} control for that
724 session.
725
726 @end table
727
728
729 @node External methods
730 @section External methods
731 @cindex methods, external
732 @cindex external methods
733
734 External methods operate over multiple channels, using the remote
735 shell connection for some actions while delegating file transfers to
736 an external transfer program.
737
738 External methods save on the overhead of encoding and decoding of
739 inline methods.
740
741 Since external methods have the overhead of opening a new channel,
742 files smaller than @var{tramp-copy-size-limit} still use inline
743 methods.
744
745 @table @asis
746 @item @option{rcp}---@command{rsh} and @command{rcp}
747 @cindex method rcp
748 @cindex rcp method
749 @cindex rcp (with rcp method)
750 @cindex rsh (with rcp method)
751
752 This method uses the @command{rsh} and @command{rcp} commands to
753 connect to the remote host and transfer files.  This is the fastest
754 access method available.
755
756 The alternative method @option{remcp} uses the @command{remsh} and
757 @command{rcp} commands.
758
759 @item @option{scp}---@command{ssh} and @command{scp}
760 @cindex method scp
761 @cindex scp method
762 @cindex scp (with scp method)
763 @cindex ssh (with scp method)
764
765 Using a combination of @command{ssh} to connect and @command{scp} to
766 transfer is the most secure.  While the performance is good, it is
767 slower than the inline methods for smaller files.  Though there is no
768 overhead of encoding and decoding of the inline methods,
769 @command{scp}'s cryptographic handshake negates those speed gains.
770
771 @option{ssh}-based methods support @samp{-p} feature for specifying
772 port numbers.  For example, @file{host#42} passes @samp{-p 42} in the
773 argument list to @command{ssh}, and @samp{-P 42} in the argument list
774 to @command{scp}.
775
776 @item @option{rsync}---@command{ssh} and @command{rsync}
777 @cindex method rsync
778 @cindex rsync method
779 @cindex rsync (with rsync method)
780 @cindex ssh (with rsync method)
781
782 @command{ssh} command to connect in combination with @command{rsync}
783 command to transfer is similar to the @option{scp} method.
784
785 @command{rsync} performs much better than @command{scp} when
786 transferring files that exist on both hosts.  However, this advantage
787 is lost if the file exists only on one side of the connection.
788
789 This method supports the @samp{-p} argument.
790
791
792 @item @option{scpx}---@command{ssh} and @command{scp}
793 @cindex method scpx
794 @cindex scpx method
795 @cindex scp (with scpx method)
796 @cindex ssh (with scpx method)
797
798 @option{scpx} is useful to avoid login shell questions.  It is similar
799 in performance to @option{scp}.  @option{scpx} uses @samp{ssh -t -t
800 @var{host} -l @var{user} /bin/sh} to open a connection.
801
802 @option{sshx} is useful for Windows users when @command{ssh} triggers
803 an error about allocating a pseudo tty.  This happens due to missing
804 shell prompts that confuses @value{tramp}.
805
806 This method supports the @samp{-p} argument.
807
808
809 @item @option{pscp}---@command{plink} and @command{pscp}
810 @item @option{psftp}---@command{plink} and @command{psftp}
811 @cindex method pscp
812 @cindex pscp method
813 @cindex pscp (with pscp method)
814 @cindex plink (with pscp method)
815 @cindex PuTTY (with pscp method)
816 @cindex method psftp
817 @cindex psftp method
818 @cindex pscp (with psftp method)
819 @cindex plink (with psftp method)
820 @cindex PuTTY (with psftp method)
821
822 These methods are similar to @option{scp} or @option{sftp}, but they
823 use the @command{plink} command to connect to the remote host, and
824 they use @command{pscp} or @command{psftp} for transferring the files.
825 These programs are part of PuTTY, an SSH implementation for Windows.
826
827 Check the @samp{Share SSH connections if possible} control for that
828 session.
829
830 These methods support the @samp{-P} argument.
831
832
833 @item @option{fcp}---@command{fsh} and @command{fcp}
834 @cindex method fcp
835 @cindex fcp method
836 @cindex fsh (with fcp method)
837 @cindex fcp (with fcp method)
838
839 This method is similar to @option{scp}, but uses @command{fsh} to
840 connect and @command{fcp} to transfer files.  @command{fsh/fcp}, a
841 front-end for @command{ssh}, reuse @command{ssh} session by
842 submitting several commands.  This avoids the startup overhead due to
843 @command{scp}'s secure connection.  Inline methods have similar
844 benefits.
845
846 The command used for this connection is: @samp{fsh @var{host} -l
847 @var{user} /bin/sh -i}
848
849 @cindex method fsh
850 @cindex fsh method
851
852 @option{fsh} has no inline method since the multiplexing it offers is
853 not useful for @value{tramp}.  @command{fsh} connects to remote host
854 and @value{tramp} keeps that one connection open.
855
856 @item @option{nc}---@command{telnet} and @command{nc}
857 @cindex method nc
858 @cindex nc method
859 @cindex nc (with nc method)
860 @cindex telnet (with nc method)
861
862 Using @command{telnet} to connect and @command{nc} to transfer files
863 is sometimes the only combination suitable for accessing routers or
864 NAS hosts.  These dumb devices have severely restricted local shells,
865 such as the @command{busybox} and do not host any other encode or
866 decode programs.
867
868 @item @option{ftp}
869 @cindex method ftp
870 @cindex ftp method
871
872 When @value{tramp} uses @option{ftp}, it forwards requests to whatever
873 ftp program is specified by @value{ftppackagename}.  This external
874 program must be capable of servicing requests from @value{tramp}.
875
876 @ifset xemacs
877 This method works only for unified file names, see @ref{Issues}.
878 @end ifset
879
880
881 @item @option{smb}---@command{smbclient}
882 @cindex method smb
883 @cindex smb method
884
885 This is another non-native @value{tramp} method.  @command{smbclient}
886 connects to any host with SMB/CIFS protocol, such as MS Windows and
887 Samba Servers running on Unixes.  Tests show this @value{tramp} method
888 works with MS Windows NT, MS Windows 2000, MS Windows XP, MS Windows
889 Vista, and MS Windows 7.
890
891 Using @command{smbclient} requires a few tweaks when working with
892 @value{tramp}:
893
894 The first directory in the localname must be a share name on the
895 remote host.
896
897 Since smb shares end in the @code{$} character, @value{tramp} must use
898 @code{$$} when specifying those shares to avoid environment variable
899 substitutions.
900
901 When @value{tramp} is not specific about the share name or uses the
902 generic remote directory @code{/}, @command{smbclient} returns all
903 available shares.
904
905 Since SMB authentication is based on each SMB share, @value{tramp}
906 prompts for a password even when accessing a different share on the
907 same SMB host.  This prompting can be suppressed by @ref{Password
908 handling}.
909
910 To accommodate user name/domain name syntax required by MS Windows
911 authorization, @value{tramp} provides for an extended syntax in
912 @code{user%domain} format (where user is username, @code{%} is the
913 percent symbol, and domain is the windows domain name).  An example:
914
915 @example
916 @trampfn{smb, daniel%BIZARRE, melancholia, /daniel$$/.emacs}
917 @end example
918
919 where user @code{daniel} connects as a domain user to the SMB host
920 @code{melancholia} in the windows domain @code{BIZARRE} to edit
921 @file{.emacs} located in the home directory (share @code{daniel$}).
922
923 Alternatively, for local WINS users (as opposed to domain users),
924 substitute the domain name with the name of the local host in
925 UPPERCASE as shown here:
926
927 @example
928 @trampfn{smb, daniel%MELANCHOLIA, melancholia, /daniel$$/.emacs}
929 @end example
930
931 where user @code{daniel} connects as local user to the SMB host
932 @code{melancholia} in the local domain @code{MELANCHOLIA} to edit
933 @file{.emacs} located in the home directory (share @code{daniel$}).
934
935 The domain name and user name are optional for @command{smbclient}
936 authentication.  When user name is not specified, @command{smbclient}
937 uses the anonymous user (without prompting for password).  This
938 behavior is unlike other @value{tramp} methods, where local user name
939 is substituted.
940
941 @option{smb} method is unavailable if @value{emacsname} is run under a
942 local user authentication context in MS Windows.  However such users
943 can still access remote files using UNC file names instead of @value{tramp}:
944
945 @example
946 //melancholia/daniel$$/.emacs
947 @end example
948
949 UNC file name specification does not allow to specify a different user
950 name for authentication like the @command{smbclient} can.
951
952
953 @item @option{adb}
954 @cindex method adb
955 @cindex adb method
956
957 This method uses Android Debug Bridge program for accessing Android
958 devices.  The Android Debug Bridge must be installed locally for
959 @value{tramp} to work.  Some GNU/Linux distributions provide Android
960 Debug Bridge as an installation package.  Alternatively, the program is
961 installed as part of the Android SDK@.  @value{tramp} finds the
962 @command{adb} program either via the @env{PATH} environment variable
963 or the absolute path set in the variable @var{tramp-adb-program}.
964
965 @value{tramp} connects to Android devices with @option{adb} only when
966 the custom option @option{tramp-adb-connect-if-not-connected} is not
967 @code{nil}.  Otherwise, the connection must be established outside
968 @value{emacsname}.
969
970 @value{tramp} does not require a host name part of the remote file
971 name when a single Android device is connected to @command{adb}.
972 @value{tramp} instead uses @file{@trampfn{adb, , ,}} as the default
973 name.  @command{adb devices} shows available host names.
974
975 @option{adb} method normally does not need user name to authenticate
976 on the Andriod device because it runs under the @command{adbd}
977 process.  But when a user name is specified, however, @value{tramp}
978 applies an @command{su} in the syntax.  When authentication does not
979 succeed, especially on un-rooted Android devices, @value{tramp}
980 displays login errors.
981
982 For Andriod devices connected through TCP/IP, a port number can be
983 specified using @file{device#42} host name syntax or @value{tramp} can
984 use the default value as declared in @command{adb} command.  Port
985 numbers are not applicable to Android devices connected through USB@.
986
987 @end table
988
989
990 @ifset emacsgvfs
991 @node GVFS based methods
992 @section GVFS based external methods
993 @cindex methods, gvfs
994 @cindex gvfs based methods
995 @cindex dbus
996
997 GVFS is the virtual file system for the Gnome Desktop,
998 @uref{http://en.wikipedia.org/wiki/GVFS}.  Remote files on GVFS are
999 mounted locally through FUSE and @value{tramp} uses this locally
1000 mounted directory internally.
1001
1002 @value{emacsname} uses the D-Bus mechanism to communicate with GVFS@.
1003 @value{emacsname} must have the message bus system, D-Bus integration
1004 active, @pxref{Top, , D-Bus, dbus}.
1005
1006 @table @asis
1007 @item @option{afp}
1008 @cindex method afp
1009 @cindex afp method
1010
1011 This method is for connecting to remote hosts with the Apple Filing
1012 Protocol for accessing files on Mac OS X volumes.  @value{tramp} access
1013 syntax requires a leading volume (share) name, for example:
1014 @file{@trampfn{afp, user, host, /volume}}.
1015
1016 @item @option{dav}
1017 @item @option{davs}
1018 @cindex method dav
1019 @cindex method davs
1020 @cindex dav method
1021 @cindex davs method
1022
1023 @option{dav} method provides access to WebDAV files and directories
1024 based on standard protocols, such as HTTP@.  @option{davs} does the same
1025 but with SSL encryption.  Both methods support the port numbers.
1026
1027 @item @option{obex}
1028 @cindex method obex
1029 @cindex obex method
1030
1031 OBEX is an FTP-like access protocol for cell phones and similar simple
1032 devices.  @value{tramp} supports OBEX over Bluetooth.
1033
1034
1035 @item @option{sftp}
1036 @cindex method sftp
1037 @cindex sftp method
1038
1039 This method uses @command{sftp} in order to securely access remote
1040 hosts.  @command{sftp} is a more secure option for connecting to hosts
1041 that for security reasons refuse @command{ssh} connections.
1042
1043 @item @option{synce}
1044 @cindex method synce
1045 @cindex synce method
1046
1047 @option{synce} method allows connecting to Windows Mobile devices.  It
1048 uses GVFS for mounting remote files and directories via FUSE and
1049 requires the SYNCE-GVFS plugin.
1050
1051 @end table
1052
1053 @defopt tramp-gvfs-methods
1054 @vindex tramp-gvfs-methods
1055 This custom option is a list of external methods for GVFS@.  By
1056 default, this list includes @option{afp}, @option{dav}, @option{davs},
1057 @option{obex}, @option{sftp} and @option{synce}.  Other methods to
1058 include are: @option{ftp} and @option{smb}.
1059 @end defopt
1060 @end ifset
1061
1062
1063 @ifset emacsgw
1064 @node Gateway methods
1065 @section Gateway methods
1066 @cindex methods, gateway
1067 @cindex gateway methods
1068
1069 Gateway methods are for proxy host declarations (@pxref{Multi-hops})
1070 so as to pass through firewalls and proxy servers.  They are not like
1071 the other methods that declare direct connections to a remote host.
1072
1073 A gateway method always comes with a port setting.  @value{tramp}
1074 targets the port number with the gateway method
1075 @file{localhost#random_port} from where the firewall or proxy server
1076 is accessed.
1077
1078 Gateway methods support user name and password declarations for
1079 authenticating the corresponding firewall or proxy server.  Such
1080 authentication can be passed through only if granted access by system
1081 administrators.
1082
1083 @table @asis
1084 @item @option{tunnel}
1085 @cindex method tunnel
1086 @cindex tunnel method
1087
1088 This method implements an HTTP tunnel via the @command{CONNECT}
1089 command (conforming to RFC 2616, 2817 specifications).  Proxy servers
1090 using HTTP version 1.1 or later protocol support this command.
1091
1092 For authentication, this protocol uses only @option{Basic
1093 Authentication} (see RFC 2617).  When no port number is specified, this
1094 protocol defaults to @option{8080}.
1095
1096
1097 @item @option{socks}
1098 @cindex method socks
1099 @cindex socks method
1100
1101 The @option{socks} method connects to SOCKSv5 servers (see RFC 1928)
1102 and supports @option{Username/Password Authentication}.
1103
1104 The default port number for the socks server is @option{1080}, if not
1105 specified otherwise.
1106
1107 @end table
1108 @end ifset
1109
1110
1111 @node Default Method
1112 @section Selecting a default method
1113 @cindex default method
1114 @vindex tramp-default-method
1115 @vindex tramp-default-method-alist
1116
1117 Default method is for transferring files.  The variable
1118 @code{tramp-default-method} sets it.  @value{tramp} uses this variable
1119 to determine the default method for tramp file names that do not have
1120 one specified.
1121
1122 @lisp
1123 (setq tramp-default-method "ssh")
1124 @end lisp
1125
1126 Default methods for transferring files can be customized for specific
1127 user and host combinations through the alist variable
1128 @code{tramp-default-method-alist}.
1129
1130 For example, the following two lines specify to use the @option{ssh}
1131 method for all user names matching @samp{john} and the @option{rsync}
1132 method for all host names matching @samp{lily}.  The third line
1133 specifies to use the @option{su} method for the user @samp{root} on
1134 the host @samp{localhost}.
1135
1136 @lisp
1137 (add-to-list 'tramp-default-method-alist '("" "john" "ssh"))
1138 (add-to-list 'tramp-default-method-alist '("lily" "" "rsync"))
1139 (add-to-list 'tramp-default-method-alist
1140              '("\\`localhost\\'" "\\`root\\'" "su"))
1141 @end lisp
1142
1143 @noindent
1144 See the documentation for the variable
1145 @code{tramp-default-method-alist} for details.
1146
1147 @noindent
1148 External methods performance faster for large files.
1149
1150 @noindent
1151 @xref{Inline methods}.
1152 @xref{External methods}.
1153
1154 Choosing the access method also depends on the security environment.
1155 For example, @option{rsh} and @option{telnet} methods that use clear
1156 text password transfers are inappropriate for over the Internet
1157 connections.  Secure remote connections should use @option{ssh} that
1158 provide encryption.
1159
1160
1161 @subsection Which method to use?
1162 @cindex choosing the right method
1163
1164 @value{tramp} provides maximum number of choices for maximum
1165 flexibility.  Choosing which method depends on the hosts, clients,
1166 network speeds, and the security context.
1167
1168 Start by using an inline method.
1169
1170 External methods might be more efficient for large files, but most
1171 @value{tramp} users edit small files more often than large files.
1172
1173 Enable compression, @var{tramp-inline-compress-start-size}, for a
1174 performance boost for large files.
1175
1176 Since @command{ssh} has become the most common method of remote host
1177 access and it has the most reasonable security protocols, use
1178 @option{ssh} method.  Typical @option{ssh} usage to edit the
1179 @file{/etc/motd} file on the otherhost:
1180
1181 @example
1182 @kbd{C-x C-f @trampfn{ssh, root, otherhost,/etc/motd} @key{RET}}
1183 @end example
1184
1185 If @option{ssh} is unavailable for whatever reason, look for other
1186 obvious options.  For Windows, try the @option{plink} method.  For
1187 Kerberos, try @option{krlogin}.
1188
1189 For editing local files as @option{su} or @option{sudo} methods, try
1190 the shortened syntax of @samp{root}:
1191
1192 @example
1193 @kbd{C-x C-f @trampfn{su, , , /etc/motd} @key{RET}}
1194 @end example
1195
1196 For editing large files, @option{scp} is faster than @option{ssh}.
1197 @option{pscp} is faster than @option{plink}.  But this speed
1198 improvement is not always true.
1199
1200
1201 @node Default User
1202 @section Selecting a default user
1203 @cindex default user
1204 @vindex tramp-default-user
1205 @vindex tramp-default-user-alist
1206
1207 @value{tramp} file name can omit the user name part since
1208 @value{tramp} substitutes the currently logged-in user name.  However
1209 this substitution can be overridden with @code{tramp-default-user}.
1210 For example:
1211
1212 @lisp
1213 (setq tramp-default-user "root")
1214 @end lisp
1215
1216 Instead of a single default user, @code{tramp-default-user-alist}
1217 allows multiple default user values based on access method or host
1218 name combinations.  The alist can hold multiple values.  For example, to
1219 use the @samp{john} as the default user for the domain
1220 @samp{somewhere.else} only:
1221
1222 @lisp
1223 (add-to-list 'tramp-default-user-alist
1224              '("ssh" ".*\\.somewhere\\.else\\'" "john"))
1225 @end lisp
1226
1227 @noindent
1228 See the documentation for the variable @code{tramp-default-user-alist}
1229 for more details.
1230
1231 A Caution: @value{tramp} will override any default user specified in
1232 the configuration files outside @value{emacsname}, such as
1233 @file{~/.ssh/config}.  To stop @value{tramp} from applying the default
1234 value, set the corresponding alist entry to nil:
1235
1236 @lisp
1237 (add-to-list 'tramp-default-user-alist
1238              '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
1239 @end lisp
1240
1241 The last entry in @code{tramp-default-user-alist} should be reserved
1242 for catch-all or most often used login.
1243
1244 @lisp
1245 (add-to-list 'tramp-default-user-alist
1246              '(nil nil "jonas") t)
1247 @end lisp
1248
1249
1250 @node Default Host
1251 @section Selecting a default host
1252 @cindex default host
1253 @vindex tramp-default-host
1254 @vindex tramp-default-host-alist
1255
1256 When host name is omitted, @value{tramp} substitutes the value from
1257 the @code{tramp-default-host} variable.  It is initially populated with
1258 the local hostname where @value{emacsname} is running.  Both the
1259 default user and default host can be overridden as follows:
1260
1261 @lisp
1262 (setq tramp-default-user "john"
1263       tramp-default-host "target")
1264 @end lisp
1265
1266 With both defaults set, @samp{@trampfn{ssh, , ,}} will connect
1267 @value{tramp} to John's home directory on target.
1268
1269 @ifset emacs
1270 @strong{Note} @samp{/::} won't work, because @samp{/:} is the prefix
1271 for quoted file names.
1272 @end ifset
1273
1274 Instead of a single default host, @code{tramp-default-host-alist}
1275 allows multiple default host values based on access method or user
1276 name combinations.  The alist can hold multiple values.  While
1277 @code{tramp-default-host} is sufficient in most cases, some methods,
1278 like @option{adb}, require defaults overwritten.
1279
1280 @noindent
1281 See the documentation for the variable @code{tramp-default-host-alist}
1282 for more details.
1283
1284
1285 @node Multi-hops
1286 @section Connecting to a remote host using multiple hops
1287 @cindex multi-hop
1288 @cindex proxy hosts
1289
1290 Multi-hops are methods to reach hosts behind firewalls or to reach the
1291 outside world from inside a bastion host.  With multi-hops,
1292 @value{tramp} can negotiate these hops with the appropriate user/host
1293 authentication at each hop.  All methods until now have been the single
1294 hop kind, where the start and end points of the connection did not
1295 have intermediate check points.
1296
1297 @defopt tramp-default-proxies-alist
1298 @vindex tramp-default-proxies-alist
1299 @option{tramp-default-proxies-alist} specifies proxy hosts to pass
1300 through.  This variable is list of triples consisting of (@var{host}
1301 @var{user} @var{proxy}).
1302
1303 The first match is the proxy host through which passes the file name
1304 and the target host matching @var{user}@@@var{host}.  @var{host} and
1305 @var{user} are regular expressions or @code{nil}, interpreted as a
1306 regular expression which always matches.
1307
1308 @var{proxy} is a literal @value{tramp} file name whose local name part
1309 is ignored, and the method and user name parts are optional.
1310
1311 @ifset emacsgw
1312 The method must be an inline or gateway method (@pxref{Inline
1313 methods}, @pxref{Gateway methods}).
1314 @end ifset
1315 @ifclear emacsgw
1316 The method must be an inline method (@pxref{Inline methods}).
1317 @end ifclear
1318 If @var{proxy} is @code{nil}, no additional hop is required reaching
1319 @var{user}@@@var{host}.
1320
1321 For example, to pass through the host @samp{bastion.your.domain} as
1322 user @samp{bird} to reach remote hosts outside the local domain:
1323
1324 @lisp
1325 (add-to-list 'tramp-default-proxies-alist
1326              '("\\." nil "@trampfn{ssh, bird, bastion.your.domain,}"))
1327 (add-to-list 'tramp-default-proxies-alist
1328              '("\\.your\\.domain\\'" nil nil))
1329 @end lisp
1330
1331 @strong{Note}: @code{add-to-list} adds elements at the beginning of a
1332 list.  Therefore, most relevant rules must come last in the list.
1333
1334 Proxy hosts can be cascaded in the alist.  If there is another host
1335 called @samp{jump.your.domain}, which is the only host allowed to
1336 connect to @samp{bastion.your.domain}, then:
1337
1338 @lisp
1339 (add-to-list 'tramp-default-proxies-alist
1340              '("\\`bastion\\.your\\.domain\\'"
1341                "\\`bird\\'"
1342                "@trampfn{ssh, , jump.your.domain,}"))
1343 @end lisp
1344
1345 @var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
1346 @var{user} respectively.
1347
1348 To login as @samp{root} on remote hosts in the domain
1349 @samp{your.domain}, but login as @samp{root} is disabled for non-local
1350 access, then use this alist entry:
1351
1352 @lisp
1353 (add-to-list 'tramp-default-proxies-alist
1354              '("\\.your\\.domain\\'" "\\`root\\'" "@trampfn{ssh, , %h,}"))
1355 @end lisp
1356
1357 Opening @file{@trampfn{sudo, , randomhost.your.domain,}} first
1358 connects to @samp{randomhost.your.domain} via @code{ssh} under your
1359 account name, and then perform @code{sudo -u root} on that host.
1360
1361 It is key for the sudo method in the above example to be applied on
1362 the host after reaching it and not on the local host.
1363
1364 @var{host}, @var{user} and @var{proxy} can also take Lisp forms.  These
1365 forms when evaluated must return either a string or @code{nil}.
1366
1367 To generalize (from the previous example): For all hosts, except my
1368 local one, first connect via @command{ssh}, and then apply
1369 @command{sudo -u root}:
1370
1371 @lisp
1372 (add-to-list 'tramp-default-proxies-alist
1373              '(nil "\\`root\\'" "@trampfn{ssh, , %h,}"))
1374 (add-to-list 'tramp-default-proxies-alist
1375              '((regexp-quote (system-name)) nil nil))
1376 @end lisp
1377
1378 The above configuration allows @value{tramp} connection as @samp{root}
1379 to remote Ubuntu hosts.
1380
1381 @ifset emacsgw
1382 @code{tramp-default-proxies-alist} is also used for passing through
1383 firewalls or proxy servers.
1384
1385 For example, the local host @samp{proxy.your.domain} on port 3128
1386 serves as HTTP proxy to the outer world.  User has access rights to
1387 another proxy server on @samp{host.other.domain}.@footnote{HTTP tunnels
1388 are intended for secure SSL/TLS communication.  Therefore, many proxy
1389 servers restrict the tunnels to related target ports.  You might need
1390 to run your ssh server on your target host @samp{host.other.domain} on
1391 such a port, like 443 (https).  See
1392 @uref{http://savannah.gnu.org/maintenance/CvsFromBehindFirewall} for
1393 discussion of ethical issues.}  Then the configuration is:
1394
1395 @lisp
1396 (add-to-list 'tramp-default-proxies-alist
1397              '("\\`host\\.other\\.domain\\'" nil
1398              "@trampfn{tunnel, , proxy.your.domain#3128,}"))
1399 @end lisp
1400
1401 Gateway methods in a multiple hop chain can be declared only as the first hop.
1402 @end ifset
1403 @end defopt
1404
1405 Passing through hops involves dealing with restricted shells, such as
1406 @command{rbash}.  If @value{tramp} is made aware, then it would use
1407 them for proxies only.
1408
1409 @defopt tramp-restricted-shell-hosts-alist
1410 @vindex tramp-restricted-shell-hosts-alist
1411 An alist of regular expressions of hosts running restricted shells,
1412 such as @command{rbash}.  @value{tramp} will then use them only as
1413 proxies.
1414
1415 To specify the bastion host from the example above as running a
1416 restricted shell:
1417
1418 @lisp
1419 (add-to-list 'tramp-restricted-shell-hosts-alist
1420              "\\`bastion\\.your\\.domain\\'")
1421 @end lisp
1422 @end defopt
1423
1424
1425 @node Customizing Methods
1426 @section Using Non-Standard Methods
1427 @cindex customizing methods
1428 @cindex using non-standard methods
1429 @cindex create your own methods
1430
1431 The @code{tramp-methods} variable currently has an exhaustive list of
1432 predefined methods.  Any part of this list can be modified with more
1433 suitable settings.  Refer to the Lisp documentation of that variable,
1434 accessible with @kbd{C-h v tramp-methods @key{RET}}.
1435
1436
1437 @node Customizing Completion
1438 @section Selecting config files for user/host name completion
1439 @cindex customizing completion
1440 @cindex selecting config files
1441 @vindex tramp-completion-function-alist
1442
1443 @code{tramp-completion-function-alist} uses predefined files for user
1444 and host name completion (@pxref{File name completion}).  For each
1445 method, it keeps a set of configuration files and a function that can
1446 parse that file.  Each entry in @code{tramp-completion-function-alist}
1447 is of the form (@var{method} @var{pair1} @var{pair2} @dots{}).
1448
1449 Each @var{pair} is composed of (@var{function} @var{file}).
1450 @var{function} is responsible for extracting user names and host names
1451 from @var{file} for completion.  There are two functions which access
1452 this variable:
1453
1454 @defun tramp-get-completion-function method
1455 This function returns the list of completion functions for @var{method}.
1456
1457 Example:
1458 @example
1459 (tramp-get-completion-function "rsh")
1460
1461      @result{} ((tramp-parse-rhosts "/etc/hosts.equiv")
1462          (tramp-parse-rhosts "~/.rhosts"))
1463 @end example
1464 @end defun
1465
1466 @defun tramp-set-completion-function method function-list
1467 This function sets @var{function-list} as list of completion functions
1468 for @var{method}.
1469
1470 Example:
1471 @example
1472 (tramp-set-completion-function "ssh"
1473  '((tramp-parse-sconfig "/etc/ssh_config")
1474    (tramp-parse-sconfig "~/.ssh/config")))
1475
1476      @result{} ((tramp-parse-sconfig "/etc/ssh_config")
1477          (tramp-parse-sconfig "~/.ssh/config"))
1478 @end example
1479 @end defun
1480
1481 The following predefined functions parsing configuration files exist:
1482
1483 @table @asis
1484 @item @code{tramp-parse-rhosts}
1485 @findex tramp-parse-rhosts
1486
1487 This function parses files which are syntactical equivalent to
1488 @file{~/.rhosts}.  It returns both host names and user names, if
1489 specified.
1490
1491 @item @code{tramp-parse-shosts}
1492 @findex tramp-parse-shosts
1493
1494 This function parses files which are syntactical equivalent to
1495 @file{~/.ssh/known_hosts}.  Since there are no user names specified
1496 in such files, it can return host names only.
1497
1498 @item @code{tramp-parse-sconfig}
1499 @findex tramp-parse-shosts
1500
1501 This function returns the host nicknames defined by @code{Host} entries
1502 in @file{~/.ssh/config} style files.
1503
1504 @item @code{tramp-parse-shostkeys}
1505 @findex tramp-parse-shostkeys
1506
1507 SSH2 parsing of directories @file{/etc/ssh2/hostkeys/*} and
1508 @file{~/ssh2/hostkeys/*}.  Hosts are coded in file names
1509 @file{hostkey_@var{portnumber}_@var{host-name}.pub}.  User names
1510 are always @code{nil}.
1511
1512 @item @code{tramp-parse-sknownhosts}
1513 @findex tramp-parse-shostkeys
1514
1515 Another SSH2 style parsing of directories like
1516 @file{/etc/ssh2/knownhosts/*} and @file{~/ssh2/knownhosts/*}.  This
1517 case, hosts names are coded in file names
1518 @file{@var{host-name}.@var{algorithm}.pub}.  User names are always @code{nil}.
1519
1520 @item @code{tramp-parse-hosts}
1521 @findex tramp-parse-hosts
1522
1523 A function dedicated to @file{/etc/hosts} for host names.
1524
1525 @item @code{tramp-parse-passwd}
1526 @findex tramp-parse-passwd
1527
1528 A function which parses @file{/etc/passwd} files for user names.
1529
1530 @item @code{tramp-parse-netrc}
1531 @findex tramp-parse-netrc
1532
1533 A function which parses @file{~/.netrc} and @file{~/.authinfo}-style files.
1534
1535 @end table
1536
1537 To keep a custom file with custom data in a custom structure, a custom
1538 function has to be provided.  This function must meet the following
1539 conventions:
1540
1541 @defun my-tramp-parse file
1542 @var{file} must be either a file on the host, or @code{nil}.  The
1543 function must return a list of (@var{user} @var{host}), which are
1544 taken as candidates for completion for user and host names.
1545
1546 Example:
1547 @example
1548 (my-tramp-parse "~/.my-tramp-hosts")
1549
1550      @result{} ((nil "toto") ("daniel" "melancholia"))
1551 @end example
1552 @end defun
1553
1554
1555 @node Password handling
1556 @section Reusing passwords for several connections
1557 @cindex passwords
1558
1559 To avoid repeated prompts for passwords, consider native caching
1560 mechanisms, such as @command{ssh-agent} for @option{ssh}-like
1561 methods, or @command{pageant} for @option{plink}-like methods.
1562
1563 @value{tramp} offers alternatives when native solutions cannot meet
1564 the need.
1565
1566
1567 @anchor{Using an authentication file}
1568 @subsection Using an authentication file
1569 @vindex auth-sources
1570
1571 The package @file{auth-source.el}, originally developed for No Gnus,
1572 reads passwords from different sources, @xref{Help for users, ,
1573 auth-source, auth}.  The default authentication file is
1574 @file{~/.authinfo.gpg}, but this can be changed via the variable
1575 @code{auth-sources}.
1576
1577 @noindent
1578 A typical entry in the authentication file:
1579
1580 @example
1581 machine melancholia port scp login daniel password geheim
1582 @end example
1583
1584 The port can take any @value{tramp} method (@pxref{Inline methods},
1585 @pxref{External methods}).  Omitting port values matches all
1586 @value{tramp} methods.
1587
1588 Setting @code{auth-source-debug} to @code{t} to debug messages.
1589
1590
1591 @anchor{Caching passwords}
1592 @subsection Caching passwords
1593
1594 @value{tramp} can cache passwords as entered and reuse when needed for
1595 the same user or host name independent of the access method.
1596
1597 @vindex password-cache-expiry
1598
1599 @code{password-cache-expiry} sets the duration (in seconds) the
1600 passwords are remembered.  Passwords are never saved permanently nor
1601 can they extend beyond the lifetime of the current @value{emacsname}
1602 session.  Set @code{password-cache-expiry} to @code{nil} to disable
1603 expiration.
1604
1605 @vindex password-cache
1606
1607 Set @code{password-cache} to @code{nil} to disable password caching.
1608
1609 @strong{Implementation Note}: password caching depends on
1610 @file{password-cache.el} package.  @value{tramp} activates password
1611 caching only if @value{tramp} can discover, while @value{emacsname} is
1612 loading, the package through @code{load-path}.
1613
1614 @ifset installchapter
1615 @file{password.el} is available from No Gnus or from the @value{tramp}
1616 @file{contrib} directory, see @ref{Installation parameters}.
1617 @end ifset
1618
1619
1620 @node Connection caching
1621 @section Reusing connection related information
1622 @cindex caching
1623 @vindex tramp-persistency-file-name
1624
1625 For faster initial connection times, @value{tramp} stores previous
1626 connection properties in a file specified by the variable
1627 @code{tramp-persistency-file-name}.
1628
1629 The default file name for @code{tramp-persistency-file-name} is:
1630 @ifset emacs
1631 @file{~/.emacs.d/tramp}.
1632 @end ifset
1633 @ifset xemacs
1634 @file{~/.xemacs/tramp}.
1635 @end ifset
1636
1637 @value{tramp} reads this file during @value{emacsname} startup, and
1638 writes to it when exiting @value{emacsname}.  Delete this file for
1639 @value{tramp} to recreate a new one on next @value{emacsname} startup.
1640
1641 Set @code{tramp-persistency-file-name} to @code{nil} to disable
1642 storing connections persistently.
1643
1644 To reuse connection information from the persistent list,
1645 @value{tramp} needs to uniquely identify every host.  However in some
1646 cases, two different connections may result in the same persistent
1647 information.  For example, connecting to a host using @command{ssh} and
1648 connecting to the same host through @code{sshd} on port 3001.  Both
1649 access methods result in nearly identical persistent specifications
1650 @file{@trampfn{ssh, , localhost,}} and @file{@trampfn{ssh, ,
1651 localhost#3001,}}.
1652
1653 Changing host names could avoid duplicates.  One way is to add a
1654 @option{Host} section in @file{~/.ssh/config} (@pxref{Frequently Asked
1655 Questions}).  Another way is to apply multiple hops (@pxref{Multi-hops}).
1656
1657 When @value{tramp} detects a change in the operating system version in
1658 a remote host (via the command @command{uname -sr}), it flushes all
1659 connection related information for that host and creates a new entry.
1660
1661
1662 @node Predefined connection information
1663 @section Setting own connection related information
1664 @vindex tramp-connection-properties
1665
1666 For more precise customization, parameters specified by
1667 @code{tramp-methods} can be overwritten manually.
1668
1669 Set @code{tramp-connection-properties} to manually override
1670 @code{tramp-methods}.  Properties in this list are in the form
1671 @code{(@var{regexp} @var{property} @var{value})}.  @var{regexp} matches
1672 remote file names.  Use @code{nil} to match all.  @var{property} is the
1673 property's name, and @var{value} is the property's value.
1674
1675 @var{property} is any method specific parameter contained in
1676 @code{tramp-methods}.  The parameter key in @code{tramp-methods} is a
1677 symbol name @code{tramp-<foo>}.  To overwrite that property, use the
1678 string @samp{<foo>} for @var{property}.  For example, this changes the
1679 remote shell:
1680
1681 @lisp
1682 (add-to-list 'tramp-connection-properties
1683              (list (regexp-quote "@trampfn{ssh, user, randomhost.your.domain,}")
1684                    "remote-shell" "/bin/ksh"))
1685 (add-to-list 'tramp-connection-properties
1686              (list (regexp-quote "@trampfn{ssh, user, randomhost.your.domain,}")
1687                    "remote-shell-login" '("-")))
1688 @end lisp
1689
1690 The parameters @code{tramp-remote-shell} and
1691 @code{tramp-remote-shell-login} in @code{tramp-methods} now have new
1692 values for the remote host.
1693
1694 @var{property} could also be any property found in
1695 @code{tramp-persistency-file-name}.
1696
1697 To get around how restricted shells randomly drop connections, set the
1698 special property @samp{busybox}.  For example:
1699
1700 @lisp
1701 (add-to-list 'tramp-connection-properties
1702              (list (regexp-quote "@trampfn{ssh, user, randomhost.your.domain,}")
1703                    "busybox" t))
1704 @end lisp
1705
1706
1707 @node Remote programs
1708 @section How @value{tramp} finds and uses programs on the remote host
1709
1710 @value{tramp} requires access to and rights to several commands on
1711 remote hosts: @command{ls}, @command{test}, @command{find} and
1712 @command{cat}.
1713
1714 Besides there are other required programs for @ref{Inline methods} and
1715 @ref{External methods} of connection.
1716
1717 To improve performance and accuracy of remote file access,
1718 @value{tramp} uses @command{perl} (or @command{perl5}) and
1719 @command{grep} when available.
1720
1721 @defopt tramp-remote-path
1722 @vindex tramp-remote-path
1723 @vindex tramp-default-remote-path
1724 @vindex tramp-own-remote-path
1725 @option{tramp-remote-path} specifies which remote directory paths
1726 @value{tramp} can search for @ref{Remote programs}.
1727
1728 @value{tramp} uses standard defaults, such as @file{/bin} and
1729 @file{/usr/bin}, which are reasonable for most hosts.  To accommodate
1730 differences in hosts and paths, for example, @file{/bin:/usr/bin} on
1731 Debian GNU/Linux or
1732 @file{/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin} on
1733 Solaris, @value{tramp} queries the remote host with @command{getconf
1734 PATH} and updates the symbol @code{tramp-default-remote-path}.
1735
1736 For instances where hosts keep obscure locations for paths for
1737 security reasons, manually add such paths to local @file{.emacs} as
1738 shown below for @value{tramp} to use when connecting.
1739
1740 @lisp
1741 (add-to-list 'tramp-remote-path "/usr/local/perl/bin")
1742 @end lisp
1743
1744 Another way to find the remote path is to use the path assigned to the
1745 remote user by the remote host.  @value{tramp} does not normally retain
1746 this remote path after logging.  However, @code{tramp-own-remote-path}
1747 preserves the path value, which can be used to update
1748 @code{tramp-remote-path}.
1749
1750 @lisp
1751 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1752 @end lisp
1753 @end defopt
1754
1755 When remote search paths are changed, local @value{tramp} caches must
1756 be recomputed.  To force @value{tramp} to recompute afresh, exit
1757 @value{emacsname}, remove the persistent file (@pxref{Connection
1758 caching}), and restart @value{emacsname}.
1759
1760
1761 @node Remote shell setup
1762 @section Remote shell setup hints
1763 @cindex remote shell setup
1764 @cindex @file{.profile} file
1765 @cindex @file{.login} file
1766 @cindex shell init files
1767
1768 @value{tramp} checks for the availability of standard programs in the
1769 usual locations.  Common tactics include successively trying
1770 @command{test -e}, @command{/usr/bin/test -e}, and @command{/bin/test
1771 -e}.  @command{ls -d} is another approach.  But these approaches do not
1772 help with these new login patterns.
1773
1774 When @value{tramp} encounters two-factor logins or additional challenge
1775 questions, such as entering birth date or security code or passphrase,
1776 @value{tramp} needs a few more configuration steps to accommodate
1777 them.
1778
1779 The difference between a password prompt and a passphrase prompt is
1780 that the password for completing the login while the passphrase is
1781 for authorizing access to local authentication information, such as
1782 the ssh key.
1783
1784 There is no one configuration to accommodate all the variations in
1785 login security, especially not the exotic ones.  However, @value{tramp}
1786 provides a few tweaks to address the most common ones.
1787
1788 @table @asis
1789 @item @var{tramp-shell-prompt-pattern}
1790 @vindex tramp-shell-prompt-pattern
1791
1792 @code{tramp-shell-prompt-pattern} is for remote login shell prompt,
1793 which may not be the same as the local login shell prompt,
1794 @code{shell-prompt-pattern}.  Since most hosts use identical prompts,
1795 @value{tramp} sets a similar default value for both prompts.
1796
1797 @item @var{tramp-password-prompt-regexp}
1798 @item @var{tramp-wrong-passwd-regexp}
1799 @vindex tramp-password-prompt-regexp
1800 @vindex tramp-wrong-passwd-regexp
1801
1802 @value{tramp} uses @var{tramp-password-prompt-regexp} to distinguish
1803 between prompts for passwords and prompts for passphrases.  By default,
1804 @var{tramp-password-prompt-regexp} handles the detection in English
1805 language environments.  See a localization example below:
1806
1807 @lisp
1808 (setq
1809   tramp-password-prompt-regexp
1810     (concat
1811       "^.*"
1812       (regexp-opt
1813         '("passphrase" "Passphrase"
1814           ;; English
1815           "password" "Password"
1816           ;; Deutsch
1817           "passwort" "Passwort"
1818           ;; Français
1819           "mot de passe" "Mot de passe") t)
1820       ".*:\0? *"))
1821 @end lisp
1822
1823 Similar localization may be necessary for handling wrong password
1824 prompts, for which @value{tramp} uses @var{tramp-wrong-passwd-regexp}.
1825
1826 @item @command{tset} and other questions
1827 @cindex Unix command tset
1828 @cindex tset Unix command
1829 @vindex tramp-terminal-type
1830
1831 To suppress inappropriate prompts for terminal type, @value{tramp}
1832 sets the @env{TERM} to @code{dumb} before the remote login process
1833 begins via the variable @code{tramp-terminal-type}.  This will silence
1834 common @command{tset} related prompts.
1835
1836 @value{tramp}'s strategy for handling such prompts (commonly triggered
1837 from login scripts on remote hosts) is to set the environment
1838 variables so that no prompts interrupt the shell initialization
1839 process.
1840
1841 @vindex tramp-actions-before-shell
1842
1843 An alternative approach is to configure @value{tramp} with strings
1844 that can identify such questions using
1845 @code{tramp-actions-before-shell}.  Example:
1846
1847 @lisp
1848 (defconst my-tramp-prompt-regexp
1849   (concat (regexp-opt '("Enter the birth date of your mother:") t)
1850           "\\s-*")
1851   "Regular expression matching my login prompt question.")
1852
1853 (defun my-tramp-action (proc vec)
1854   "Enter \"19000101\" in order to give a correct answer."
1855   (save-window-excursion
1856     (with-current-buffer (tramp-get-connection-buffer vec)
1857       (tramp-message vec 6 "\n%s" (buffer-string))
1858       (tramp-send-string vec "19000101"))))
1859
1860 (add-to-list 'tramp-actions-before-shell
1861              '(my-tramp-prompt-regexp my-tramp-action))
1862 @end lisp
1863
1864
1865 @item Conflicting names for users and variables in @file{.profile}
1866
1867 When a user name is the same as a variable name in a local file, such
1868 as @file{.profile}, then @value{tramp} may send incorrect values for
1869 environment variables.  To avoid incorrect values, change the local
1870 variable name to something different from the user name.  For example,
1871 if the user name is @env{FRUMPLE}, then change the variable name to
1872 @env{FRUMPLE_DIR}.
1873
1874
1875 @item Non-Bourne commands in @file{.profile}
1876
1877 When the remote host's @file{.profile} is also used for shells other
1878 than Bourne shell, then some incompatible syntaxes for commands in
1879 @file{.profile} may trigger errors in Bourne shell on the host and may
1880 not complete client's @value{tramp} connections.
1881
1882 One example of a Bourne shell incompatible syntax in @file{.profile}:
1883 using @command{export FOO=bar} instead of @command{FOO=bar; export
1884 FOO}.  After remote login, @value{tramp} will trigger an error during
1885 its execution of @command{/bin/sh} on the remote host because Bourne
1886 shell does not recognize the export command as entered in
1887 @file{.profile}.
1888
1889 Likewise, (@code{~}) character in paths will cause errors because
1890 Bourne shell does not do (@code{~}) character expansions.
1891
1892 One approach to avoiding these incompatibilities is to make all
1893 commands in @file{~/.shrc} and @file{~/.profile} Bourne shell
1894 compatible so @value{tramp} can complete connections to that remote.
1895 To accommodate using non-Bourne shells on that remote, use other
1896 shell-specific config files.  For example, bash can use
1897 @file{~/.bash_profile} and ignore @file{.profile}.
1898
1899
1900 @item Interactive shell prompt
1901
1902 @value{tramp} redefines the remote shell prompt internally for robust
1903 parsing.  This redefinition affects the looks of a prompt in an
1904 interactive remote shell through commands, such as @kbd{M-x
1905 shell}.  Such prompts, however, can be reset to something more readable
1906 and recognizable using these @value{tramp} variables.
1907
1908 @value{tramp} sets the @env{INSIDE_EMACS} variable in the startup
1909 script file @file{~/.emacs_SHELLNAME}.
1910
1911 @env{SHELLNAME} is @code{bash} or equivalent shell names.  Change it by
1912 setting the environment variable @env{ESHELL} in the @file{.emacs} as
1913 follows:
1914
1915 @lisp
1916 (setenv "ESHELL" "bash")
1917 @end lisp
1918
1919 Then re-set the prompt string in @file{~/.emacs_SHELLNAME} as follows:
1920
1921 @example
1922 # Reset the prompt for remote Tramp shells.
1923 if [ "$@{INSIDE_EMACS/*tramp*/tramp@}" == "tramp" ] ; then
1924    PS1="[\u@@\h \w]$ "
1925 fi
1926 @end example
1927
1928 @ifinfo
1929 @ifset emacs
1930 @xref{Interactive Shell, , , @value{emacsdir}}.
1931 @end ifset
1932 @end ifinfo
1933
1934 @item @command{busybox} / @command{nc}
1935 @cindex Unix command nc
1936 @cindex nc Unix command
1937
1938 @value{tramp}'s @option{nc} method uses the @command{nc} command to
1939 install and execute a listener as follows (see @code{tramp-methods}):
1940
1941 @example
1942 # nc -l -p 42
1943 @end example
1944
1945 The above command-line syntax has changed with @command{busybox}
1946 versions.  If @command{nc} refuses the @command{-p} parameter, then
1947 overwrite as follows:
1948
1949 @lisp
1950 (add-to-list
1951  'tramp-connection-properties
1952  `(,(regexp-quote "192.168.0.1") "remote-copy-args" (("-l") ("%r"))))
1953 @end lisp
1954
1955 @noindent
1956 where @samp{192.168.0.1} is the remote host IP address
1957 (@pxref{Predefined connection information}).
1958
1959 @end table
1960
1961
1962 @node Android shell setup
1963 @section Android shell setup hints
1964 @cindex android shell setup
1965
1966 @value{tramp} uses the @option{adb} method to access Android
1967 devices.  Android devices provide a restricted shell access through an
1968 USB connection.  The local host must have Andriod SDK installed.
1969
1970 Applications such as @code{SSHDroid} that run @command{sshd} process
1971 on the Android device can accept any @option{ssh}-based methods
1972 provided these settings are adjusted:
1973
1974 @code{sh} must be specified for remote shell since Android devices do
1975 not provide @code{/bin/sh}.  @code{sh} will then invoke whatever shell is
1976 installed on the device with this setting:
1977
1978 @lisp
1979 (add-to-list 'tramp-connection-properties
1980              (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))
1981 @end lisp
1982
1983 @noindent
1984 where @samp{192.168.0.26} is the Android device's IP address.
1985 (@pxref{Predefined connection information}).
1986
1987 @value{tramp} requires preserving @env{PATH} environment variable from
1988 user settings.  Android devices prefer @file{/system/xbin} path over
1989 @file{/system/bin}.  Both of these are set as follows:
1990
1991 @lisp
1992 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1993 (add-to-list 'tramp-remote-path "/system/xbin")
1994 @end lisp
1995
1996 @noindent
1997 When the Android device is not @samp{rooted}, specify a writable
1998 directory for temporary files:
1999
2000 @lisp
2001 (add-to-list 'tramp-remote-process-environment "TMPDIR=$HOME")
2002 @end lisp
2003
2004 @noindent
2005 Open a remote connection with the command @kbd{C-x C-f @trampfn{ssh, ,
2006 192.168.0.26#2222, }}, where @command{sshd} is listening on port
2007 @samp{2222}.
2008
2009 To add a corresponding entry to the @file{~/.ssh/config} file
2010 (recommended), use this:
2011
2012 @example
2013 Host android
2014      HostName 192.168.0.26
2015      User root
2016      Port 2222
2017 @end example
2018
2019 @noindent
2020 To use the host name @samp{android} instead of the IP address shown in
2021 the previous example, fix the connection properties as follows:
2022
2023 @lisp
2024 (add-to-list 'tramp-connection-properties
2025              (list (regexp-quote "android") "remote-shell" "sh"))
2026 @end lisp
2027
2028 @noindent
2029 Open a remote connection with a more concise command @kbd{C-x C-f
2030 @trampfn{ssh, , android, }}.
2031
2032
2033 @node Auto-save and Backup
2034 @section Auto-save and Backup configuration
2035 @cindex auto-save
2036 @cindex backup
2037 @ifset emacs
2038 @vindex backup-directory-alist
2039 @end ifset
2040 @ifset xemacs
2041 @vindex bkup-backup-directory-info
2042 @end ifset
2043
2044 To avoid @value{tramp} from saving backup files owned by root to
2045 locations accessible to others, default backup settings in
2046 @ifset emacs
2047 @code{backup-directory-alist}
2048 @end ifset
2049 @ifset xemacs
2050 @code{bkup-backup-directory-info}
2051 @end ifset
2052 have to be altered.
2053
2054 Here's a scenario where files could be inadvertently
2055 exposed.  @value{emacsname} by default writes backup files to the same
2056 directory as the original files unless changed to another location,
2057 such as @file{~/.emacs.d/backups/}.  Such a directory will also be used
2058 by default by @value{tramp} when using, say, a restricted file
2059 @file{@trampfn{su, root, localhost, /etc/secretfile}}.  The backup file
2060 of the secretfile is now owned by the user logged in from tramp and
2061 not root.
2062
2063 When
2064 @ifset emacs
2065 @code{backup-directory-alist}
2066 @end ifset
2067 @ifset xemacs
2068 @code{bkup-backup-directory-info}
2069 @end ifset
2070 is @code{nil} (the default), such problems do not occur.
2071
2072 To ``turns off'' the backup feature for @value{tramp} files and stop
2073 @value{tramp} from saving to the backup directory, use this:
2074
2075 @ifset emacs
2076 @lisp
2077 (add-to-list 'backup-directory-alist
2078              (cons tramp-file-name-regexp nil))
2079 @end lisp
2080 @end ifset
2081 @ifset xemacs
2082 @lisp
2083 (require 'backup-dir)
2084 (add-to-list 'bkup-backup-directory-info
2085              (list tramp-file-name-regexp ""))
2086 @end lisp
2087 @end ifset
2088
2089 @ifset emacs
2090 @noindent
2091 Disabling backups can be targetted to just @option{su} and
2092 @option{sudo} methods:
2093
2094 @lisp
2095 (setq backup-enable-predicate
2096       (lambda (name)
2097         (and (normal-backup-enable-predicate name)
2098              (not
2099               (let ((method (file-remote-p name 'method)))
2100                 (when (stringp method)
2101                   (member method '("su" "sudo"))))))))
2102 @end lisp
2103 @end ifset
2104
2105 Another option is to create better backup file naming with user and
2106 host names prefixed to the file name.  For example, transforming
2107 @file{/etc/secretfile} to
2108 @file{~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile}, set the
2109 @value{tramp} variable
2110 @ifset emacs
2111 @code{tramp-backup-directory-alist}
2112 @end ifset
2113 @ifset xemacs
2114 @code{tramp-bkup-backup-directory-info}
2115 @end ifset
2116 from the existing variable
2117 @ifset emacs
2118 @code{backup-directory-alist}.
2119 @end ifset
2120 @ifset xemacs
2121 @code{bkup-backup-directory-info}.
2122 @end ifset
2123
2124 Then @value{tramp} backs up to a file name that is transformed with a
2125 prefix consisting of the DIRECTORY name.  This file name prefixing
2126 happens only when the DIRECTORY is an absolute local file name.
2127
2128 @noindent
2129 Example:
2130
2131 @ifset emacs
2132 @lisp
2133 (add-to-list 'backup-directory-alist
2134              (cons "." "~/.emacs.d/backups/"))
2135 (setq tramp-backup-directory-alist backup-directory-alist)
2136 @end lisp
2137 @end ifset
2138 @ifset xemacs
2139 @lisp
2140 (require 'backup-dir)
2141 (add-to-list 'bkup-backup-directory-info
2142              (list "." "~/.emacs.d/backups/" 'full-path))
2143 (setq tramp-bkup-backup-directory-info bkup-backup-directory-info)
2144 @end lisp
2145 @end ifset
2146
2147 @noindent
2148 The backup file name of @file{@trampfn{su, root, localhost,
2149 /etc/secretfile}} would be
2150 @ifset emacs
2151 @file{@trampfn{su, root, localhost,
2152 ~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile~}}
2153 @end ifset
2154 @ifset xemacs
2155 @file{@trampfn{su, root, localhost,
2156 ~/.emacs.d/backups/![su!root@@localhost]!etc!secretfile~}}
2157 @end ifset
2158
2159 Just as for backup files, similar issues of file naming affect
2160 auto-saving @value{tramp} files.
2161 @ifset emacs
2162 Auto-saved files are saved in the directory specified by the variable
2163 @code{auto-save-file-name-transforms}.  By default this is set to the
2164 local temporary directory.  But in some versions of Debian GNU/Linux,
2165 this points to the source directory where the @value{emacsname} was
2166 compiled.   Reset such values to a valid directory.
2167
2168 Set @code{auto-save-file-name-transforms} to @code{nil} to save
2169 auto-saved files to the same directory as the original file.
2170
2171 Alternatively, set the variable @code{tramp-auto-save-directory} to
2172 direct all auto saves to that location.
2173 @end ifset
2174 @ifset xemacs
2175 @code{auto-save-directory} can also be used here instead of other
2176 locations specfied above.
2177 @end ifset
2178
2179 @node Windows setup hints
2180 @section Issues with Cygwin ssh
2181 @cindex Cygwin, issues
2182
2183 This section is incomplete.  Please share your solutions.
2184
2185 @cindex method sshx with Cygwin
2186 @cindex sshx method with Cygwin
2187
2188 Cygwin's @command{ssh} works only with a Cygwin version of
2189 @value{emacsname}.  To check for compatibility: type @kbd{M-x eshell}, and
2190 start @kbd{ssh test.host}.  Incompatbilities trigger this message:
2191
2192 @example
2193 Pseudo-terminal will not be allocated because stdin is not a terminal.
2194 @end example
2195
2196 Some older versions of Cygwin's @command{ssh} work with the
2197 @option{sshx} access method.  Consult Cygwin's FAQ at
2198 @uref{http://cygwin.com/faq/} for details.
2199
2200
2201 @cindex method scpx with Cygwin
2202 @cindex scpx method with Cygwin
2203
2204 When using the @option{scpx} access method, @value{emacsname} may call
2205 @command{scp} with Windows file naming, such as @code{c:/foo}.  But
2206 the version of @command{scp} that is installed with Cygwin does not
2207 know about Windows file naming, which causes it to incorrectly look
2208 for a host named @code{c}.
2209
2210 A workaround: write a wrapper script for @option{scp} to convert
2211 Windows file names to Cygwin file names.
2212
2213 @cindex Cygwin and ssh-agent
2214 @cindex SSH_AUTH_SOCK and @value{emacsname} on Windows
2215
2216 When using the @command{ssh-agent} on Windows for password-less
2217 interaction, @option{ssh} methods depend on the environment variable
2218 @env{SSH_AUTH_SOCK}.  But this variable is not set when
2219 @value{emacsname} is started from a Desktop shortcut and
2220 authentication fails.
2221
2222 One workaround is to use a Windows based SSH Agent, such as
2223 Pageant.  It is part of the Putty Suite of tools.
2224
2225 The fallback is to start @value{emacsname} from a shell.
2226
2227
2228 @node Usage
2229 @chapter Using @value{tramp}
2230 @cindex using @value{tramp}
2231
2232 @value{tramp} operates transparently, accessing remote files as if
2233 they are local.  However, @value{tramp} employs a formalized remote
2234 file naming syntax to perform its functions transparently.  This
2235 syntax consists of many parts specifying access methods,
2236 authentication, host names, and file names.
2237 @ifset emacs
2238 @value{ftppackagename} uses a similar syntax.
2239 @end ifset
2240
2241 @cindex type-ahead
2242
2243 Unlike opening local files in @value{emacsname}, which are
2244 instantaneous, opening remote files in @value{tramp} is slower at
2245 first.  Sometimes there is a noticable delay before the prompts for
2246 passwords or authentication appear in the minibuffer.  Hitting
2247 @kbd{@key{RET}} or other keys during this gap will be processed by
2248 @value{emacsname}.  This type-ahead facility is a feature of
2249 @value{emacsname} that may cause missed prompts when using
2250 @value{tramp}.
2251
2252 @menu
2253 * File name Syntax::            @value{tramp} file name conventions.
2254 * File name completion::        File name completion.
2255 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
2256 * Remote processes::            Integration with other @value{emacsname} packages.
2257 * Cleanup remote connections::  Cleanup remote connections.
2258 @end menu
2259
2260
2261 @node File name Syntax
2262 @section @value{tramp} file name conventions
2263 @cindex file name syntax
2264 @cindex file name examples
2265
2266 @file{@trampfn{, , host, localfilename}}
2267 opens file @var{localfilename} on the remote host @var{host}, using
2268 the default method.  @xref{Default Method}.
2269
2270 @table @file
2271 @item @value{prefix}melancholia@value{postfix}.emacs
2272 For the file @file{.emacs} located in the home directory, on the host
2273 @code{melancholia}.
2274
2275 @item @value{prefix}melancholia.danann.net@value{postfix}.emacs
2276 For the file @file{.emacs} specified using the fully qualified domain name of
2277 the host.
2278
2279 @item @value{prefix}melancholia@value{postfix}~/.emacs
2280 For the file @file{.emacs} specified using the @file{~}, which is expanded.
2281
2282 @item @value{prefix}melancholia@value{postfix}~daniel/.emacs
2283 For the file @file{.emacs} located in @code{daniel}'s home directory
2284 on the host, @code{melancholia}.  The @file{~<user>} construct is
2285 expanded to the home directory of that user on the remote host.
2286
2287 @item @value{prefix}melancholia@value{postfix}/etc/squid.conf
2288 For the file @file{/etc/squid.conf} on the host @code{melancholia}.
2289
2290 @end table
2291
2292 @var{host} can take IPv4 or IPv6 address, as in @file{@trampfn{, ,
2293 127.0.0.1, .emacs}} or @file{@trampfn{, ,
2294 @value{ipv6prefix}::1@value{ipv6postfix}, .emacs}}.
2295 @ifset emacs
2296 For syntactical reasons, IPv6 addresses must be embedded in square
2297 brackets @file{@value{ipv6prefix}} and @file{@value{ipv6postfix}}.
2298 @end ifset
2299
2300 By default, @value{tramp} will use the current local user name as the
2301 remote user name for log in to the remote host.  Specifying a different
2302 name using the proper syntax will override this default behavior:
2303
2304 @example
2305 @trampfn{, user, host, path/to.file}
2306 @end example
2307
2308 @file{@trampfn{, daniel, melancholia, .emacs}} is for file
2309 @file{.emacs} in @code{daniel}'s home directory on the host,
2310 @code{melancholia}.
2311
2312 Specify other file access methods (@pxref{Inline methods},
2313 @pxref{External methods}) as part of the file name.
2314
2315 @ifset emacs
2316 Method name comes before user name, as in
2317 @file{@value{prefix}@var{method}@value{postfixhop}} (Note the trailing
2318 colon).
2319 @end ifset
2320 @ifset xemacs
2321 This is done by replacing the initial @file{@value{prefix}} with
2322 @file{@value{prefix}@var{method}@value{postfixhop}} (Note the trailing
2323 slash!).
2324 @end ifset
2325 The syntax specificaton for user, host, and file do not change.
2326
2327 To connect to the host @code{melancholia} as @code{daniel}, using
2328 @option{ssh} method for @file{.emacs} in @code{daniel}'s home
2329 directory, the full specification is: @file{@trampfn{ssh, daniel,
2330 melancholia, .emacs}}.
2331
2332 A remote file name containing a host name, which is the same string as
2333 a method name, is not allowed.
2334
2335 For specifying port numbers, affix @file{#<port>} to the host
2336 name.  For example: @file{@trampfn{ssh, daniel, melancholia#42,
2337 .emacs}}.
2338
2339
2340 @node File name completion
2341 @section File name completion
2342 @cindex file name completion
2343
2344 @value{tramp} can complete the following @value{tramp} file name
2345 components: method names, user names, host names, and file names
2346 located on remote hosts.
2347 @ifset emacs
2348 Enable this by activating partial completion in @file{.emacs}.
2349 @ifinfo
2350 @xref{Completion Options, , , @value{emacsdir}}.
2351 @end ifinfo
2352 @end ifset
2353
2354 For example, type @kbd{C-x C-f @value{prefix}t @key{TAB}},
2355 @value{tramp} completion choices show up as
2356
2357 @example
2358 @c @multitable {@trampfn{telnet, , melancholia.danann.net,}} {@trampfn{telnet, , 192.168.0.1,}}
2359 @multitable @columnfractions .5 .5
2360 @ifset emacs
2361 @item @value{prefixhop}telnet@value{postfixhop} @tab tmp/
2362 @item @value{prefixhop}toto@value{postfix} @tab
2363 @end ifset
2364 @ifset xemacs
2365 @item @value{prefixhop}telnet@value{postfixhop} @tab @value{prefixhop}toto@value{postfix}
2366 @end ifset
2367 @end multitable
2368 @end example
2369
2370 @samp{@value{prefixhop}telnet@value{postfixhop}}
2371 is a possible completion for the respective method,
2372 @ifset emacs
2373 @samp{tmp/} stands for the directory @file{/tmp} on your local host,
2374 @end ifset
2375 and @samp{@value{prefixhop}toto@value{postfix}}
2376 might be a host @value{tramp} has detected in your @file{~/.ssh/known_hosts}
2377 file (when using @option{ssh} as default method).
2378
2379 Type @kbd{e @key{TAB}} for the minibuffer completion to
2380 @samp{@value{prefix}telnet@value{postfixhop}}.  Typing @kbd{@key{TAB}}
2381 shows host names @value{tramp} from @file{/etc/hosts} file, for example.
2382
2383 @example
2384 @multitable @columnfractions .5 .5
2385 @c @multitable {@trampfn{telnet, , melancholia.danann.net,}} {@trampfn{telnet, , 192.168.0.1,}}
2386 @item @trampfn{telnet, , 127.0.0.1,} @tab @trampfn{telnet, , 192.168.0.1,}
2387 @item @trampfn{telnet, , @value{ipv6prefix}::1@value{ipv6postfix},} @tab @trampfn{telnet, , localhost,}
2388 @item @trampfn{telnet, , melancholia.danann.net,} @tab @trampfn{telnet, , melancholia,}
2389 @end multitable
2390 @end example
2391
2392 Choose a host from the above list and then continue to complete file
2393 names on that host.
2394
2395 When the configuration (@pxref{Customizing Completion}) includes user
2396 names, then the completion lists will account for the user names as well.
2397
2398 Remote hosts previously visited or hosts whose connections are kept
2399 persistently (@pxref{Connection caching}) will be included in the
2400 completion lists.
2401
2402 After remote host name completion comes completion of file names on
2403 the remote host.  It works the same as on loal host file completion
2404 except when killing with double-slash @file{//} kills only the file
2405 name part of the @value{tramp} file name syntax.
2406 @ifset emacs
2407 A triple-slash stands for the default behavior.
2408 @end ifset
2409 @ifinfo
2410 @xref{Minibuffer File, , , @value{emacsdir}}.
2411 @end ifinfo
2412
2413 @noindent
2414 Example:
2415
2416 @example
2417 @ifset emacs
2418 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin//etc} @key{TAB}}
2419      @print{} @trampfn{telnet, , melancholia, /etc}
2420
2421 @kbd{C-x C-f @trampfn{telnet, , melancholia, //etc} @key{TAB}}
2422      @print{} /etc
2423
2424 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin///etc} @key{TAB}}
2425      @print{} /etc
2426 @end ifset
2427
2428 @ifset xemacs
2429 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin//}}
2430      @print{} @trampfn{telnet, , melancholia, /}
2431
2432 @kbd{C-x C-f @trampfn{telnet, , melancholia, //}}
2433      @print{} /
2434 @end ifset
2435 @end example
2436
2437 During file name completion, remote directory contents are re-read
2438 regularly to account for any changes in the filesystem that may affect
2439 the completion candidates.  Such re-reads can account for changes to
2440 the file system by applications outside @value{emacsname}
2441 (@pxref{Connection caching}).
2442
2443 @defopt tramp-completion-reread-directory-timeout
2444 @vindex tramp-completion-reread-directory-timeout
2445 The timeout is number of seconds since last remote command for
2446 rereading remote directory contents.  0 re-reads immediately during
2447 file name completion, @code{nil} uses cached directory contents.
2448 @end defopt
2449
2450
2451 @node Ad-hoc multi-hops
2452 @section Declaring multiple hops in the file name
2453 @cindex multi-hop, ad-hoc
2454 @cindex proxy hosts, ad-hoc
2455
2456 @value{tramp} file name syntax can accommodate ad hoc specification of
2457 multiple proxies without using @code{tramp-default-proxies-alist}
2458 configuration setup(@pxref{Multi-hops}).
2459
2460 Each proxy is specified using the same syntax as the remote host
2461 specification minus the file name part.  Each hop is separated by a
2462 @samp{|}.  Chain the proxies from the starting host to the destination
2463 remote host name and file name.  For example, hopping over a single
2464 proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}:
2465
2466 @example
2467 @c @kbd{C-x C-f @trampfn{ssh@value{postfixhop}bird@@bastion|ssh, you,
2468 @c remotehost, /path}}
2469 @kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path}
2470 @end example
2471
2472 Proxies can take patterns @code{%h} or @code{%u}.
2473
2474 @value{tramp} adds the ad-hoc definitions on the fly to
2475 @code{tramp-default-proxies-alist} and is available for re-use during
2476 that @value{emacsname} session.  Subsequent @value{tramp} connections
2477 to the same remote host can then use the shortcut form:
2478 @samp{@trampfn{ssh, you, remotehost, /path}}.
2479
2480 @defopt tramp-save-ad-hoc-proxies
2481 @vindex tramp-save-ad-hoc-proxies
2482 For ad-hoc definitions to be saved automatically in
2483 @option{tramp-default-proxies-alist} for future @value{emacsname}
2484 sessions, set @option{tramp-save-ad-hoc-proxies}.
2485
2486 @lisp
2487 (setq tramp-save-ad-hoc-proxies t)
2488 @end lisp
2489 @end defopt
2490
2491
2492 @node Remote processes
2493 @section Integration with other @value{emacsname} packages
2494 @cindex compile
2495 @cindex recompile
2496
2497 @value{tramp} supports starting new running processes on the remote
2498 host for discovering remote file names.  @value{emacsname} packages on
2499 the remote host need no specific modifications for @value{tramp}'s
2500 use.
2501
2502 This type of integration does not work with the @option{ftp} method,
2503 and does not support the pty association as specified in
2504 @code{start-file-process}.
2505
2506 @code{process-file} and @code{start-file-process} work on the remote
2507 host when the variable @code{default-directory} is remote:
2508
2509 @lisp
2510 (let ((default-directory "/ssh:remote.host:"))
2511   (start-file-process "grep" (get-buffer-create "*grep*")
2512                       "/bin/sh" "-c" "grep -e tramp *"))
2513 @end lisp
2514
2515
2516 @ifset emacsgvfs
2517 Remote processes do not apply to GVFS (see @ref{GVFS based methods})
2518 because the remote file system is mounted on the local host and
2519 @value{tramp} just accesses by changing the @code{default-directory}.
2520 @end ifset
2521
2522 @value{tramp} starts a remote process when a command is executed in a
2523 remote file or directory buffer.  As of now, these packages have been
2524 integrated to work with @value{tramp}: @file{compile.el} (commands
2525 like @code{compile} and @code{grep}) and @file{gud.el} (@code{gdb} or
2526 @code{perldb}).
2527
2528 For @value{tramp} to find the command on the remote, it must be
2529 accessible through the default search path as setup by @value{tramp}
2530 upon first connection.  Alternatively, use an absolute path or extend
2531 @code{tramp-remote-path} (see @ref{Remote programs}):
2532
2533 @lisp
2534 (add-to-list 'tramp-remote-path "~/bin")
2535 (add-to-list 'tramp-remote-path "/appli/pub/bin")
2536 @end lisp
2537
2538 Customize @code{tramp-remote-process-environment} to suit the remote
2539 program's environment for the remote host.
2540 @code{tramp-remote-process-environment} is a list of strings
2541 structured similar to @code{process-environment}, where each element
2542 is a string of the form @samp{ENVVARNAME=VALUE}.
2543
2544 To avoid any conflicts with local host variables set through local
2545 configuration files, such as @file{~/.profile}, use @samp{ENVVARNAME=}
2546 to unset them for the remote environment.
2547
2548 @noindent
2549 Use @code{add-to-list} to add entries:
2550
2551 @lisp
2552 (add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java")
2553 @end lisp
2554
2555 Modifying or deleting already existing values in the
2556 @code{tramp-remote-process-environment} list may not be feasible on
2557 restricted remote hosts.  For example, some system administrators
2558 disallow changing @env{HISTORY} variable.  To accommodate such
2559 restrictions when using @value{tramp}, fix the
2560 @code{tramp-remote-process-environment} by the following code in the
2561 local @file{.emacs} file:
2562
2563 @lisp
2564 (let ((process-environment tramp-remote-process-environment))
2565   (setenv "HISTORY" nil)
2566   (setq tramp-remote-process-environment process-environment))
2567 @end lisp
2568
2569 @value{tramp} does not use the defaults specified in
2570 @code{process-environment} for running @code{process-file} or
2571 @code{start-file-process} on remote hosts.  When values from
2572 @code{process-environment} are needed for remote processes, then set
2573 them as follows:
2574
2575 @lisp
2576 (let ((process-environment (cons "HGPLAIN=1" process-environment)))
2577   (process-file @dots{}))
2578 @end lisp
2579
2580 This works only for environment variables not already set in the
2581 @code{process-environment}.
2582
2583 For integrating other @value{emacsname} packages so @value{tramp} can
2584 execute remotely, please file a bug report.  @xref{Bug Reports}.
2585
2586
2587 @subsection Running remote programs that create local X11 windows
2588
2589 To allow a remote program to create an X11 window on the local host,
2590 set the @env{DISPLAY} environment variable for the remote host as
2591 follows in the local @file{.emacs} file:
2592
2593 @lisp
2594 (add-to-list 'tramp-remote-process-environment
2595              (format "DISPLAY=%s" (getenv "DISPLAY")))
2596 @end lisp
2597
2598 @noindent
2599 @code{(getenv "DISPLAY")} should return a recognizable name for the
2600 local host that the remote host can redirect X11 window
2601 interactions.  If querying for a recognizable name is not possible for
2602 whatever reason, then replace @code{(getenv "DISPLAY")} with a
2603 hard-coded, fixed name.  Note that using @code{:0} for X11 display name
2604 here will not work as expected.
2605
2606 An alternate approach is specify @code{ForwardX11 yes} or
2607 @code{ForwardX11Trusted yes} in the file @file{~/.ssh/config} on the
2608 local host.
2609
2610
2611 @subsection Running @code{shell} on a remote host
2612 @cindex shell
2613
2614 Set @option{explicit-shell-file-name} to the appropriate shell name
2615 when using @value{tramp} between two hosts with different operating
2616 systems, such as @samp{windows-nt} and @samp{gnu/linux}.  This option
2617 ensures the correct name of the remote shell program.
2618
2619 @ifset emacs
2620 Starting with Emacs 24, when @option{explicit-shell-file-name} is
2621 equal to @code{nil}, calling @code{shell} interactively will prompt
2622 for a shell name.
2623 @end ifset
2624
2625
2626 @subsection Running @code{shell-command} on a remote host
2627 @cindex shell-command
2628
2629 @code{shell-command} executes commands synchronously or asynchronously
2630 on remote hosts and displays output in buffers on the local
2631 host.  Example:
2632
2633 @example
2634 @kbd{C-x C-f @trampfn{sudo, , , } @key{RET}}
2635 @kbd{M-! tail -f /var/log/syslog.log & @key{RET}}
2636 @end example
2637
2638 @command{tail} command outputs continuously to the local buffer,
2639 @file{*Async Shell Command*}
2640
2641 @ifset emacs
2642 @kbd{M-x auto-revert-tail-mode} runs similarly showing continuous output.
2643 @end ifset
2644
2645
2646 @subsection Running @code{eshell} on a remote host
2647 @cindex eshell
2648
2649 @value{tramp} is integrated into @file{eshell.el}, which enables
2650 interactive eshell sessions on remote hosts at the command prompt.
2651 You must add the module @code{eshell-tramp} to
2652 @code{eshell-modules-list}.  Here's a sample interaction after opening
2653 @kbd{M-x eshell} on a remote host:
2654
2655 @example
2656 @b{~ $} cd @trampfn{sudo, , , /etc} @key{RET}
2657 @b{@trampfn{sudo, root, host, /etc} $} hostname @key{RET}
2658 host
2659 @b{@trampfn{sudo, root, host, /etc} $} id @key{RET}
2660 uid=0(root) gid=0(root) groups=0(root)
2661 @b{@trampfn{sudo, root, host, /etc} $} find-file shadow @key{RET}
2662 #<buffer shadow>
2663 @b{@trampfn{sudo, root, host, /etc} $}
2664 @end example
2665
2666 @ifset emacs
2667 @code{eshell} in @value{emacsname} 23.2 added custom @code{su} and
2668 @code{sudo} commands that set the default directory correctly for the
2669 @file{*eshell*} buffer.  @value{tramp} silently updates
2670 @code{tramp-default-proxies-alist} with an entry for this directory
2671 (@pxref{Multi-hops}):
2672
2673 @example
2674 @b{~ $} cd @trampfn{ssh, user, remotehost, /etc} @key{RET}
2675 @b{@trampfn{ssh, user, remotehost, /etc} $} find-file shadow @key{RET}
2676 File is not readable: @trampfn{ssh, user, remotehost, /etc/shadow}
2677 @b{@trampfn{ssh, user, remotehost, /etc} $} sudo find-file shadow @key{RET}
2678 #<buffer shadow>
2679
2680 @b{@trampfn{ssh, user, remotehost, /etc} $} su - @key{RET}
2681 @b{@trampfn{su, root, remotehost, /root} $} id @key{RET}
2682 uid=0(root) gid=0(root) groups=0(root)
2683 @b{@trampfn{su, root, remotehost, /root} $}
2684 @end example
2685 @end ifset
2686
2687
2688 @anchor{Running a debugger on a remote host}
2689 @subsection Running a debugger on a remote host
2690 @cindex gud
2691 @cindex gdb
2692 @cindex perldb
2693
2694 @file{gud.el} provides a unified interface to symbolic debuggers
2695 @ifset emacs
2696 @ifinfo
2697 (@ref{Debuggers, , , @value{emacsdir}}).
2698 @end ifinfo
2699 @end ifset
2700 @value{tramp} can run debug on remote hosts by calling @code{gdb}
2701 with a remote file name:
2702
2703 @example
2704 @kbd{M-x gdb @key{RET}}
2705 @b{Run gdb (like this):} gdb --annotate=3 @trampfn{ssh, , host, ~/myprog} @key{RET}
2706 @end example
2707
2708 Relative file names are based on the remote default directory.  When
2709 @file{myprog.pl} exists in @file{@trampfn{ssh, , host, /home/user}},
2710 valid calls include:
2711
2712 @example
2713 @kbd{M-x perldb @key{RET}}
2714 @b{Run perldb (like this):} perl -d myprog.pl @key{RET}
2715 @end example
2716
2717 Just the local part of a remote file name, such as @kbd{perl -d
2718 /home/user/myprog.pl}, is not possible.
2719
2720 Arguments of the program to be debugged must be literal, can take
2721 relative or absolute paths, but not remote paths.
2722
2723
2724 @subsection Running remote processes on Windows hosts
2725 @cindex winexe
2726 @cindex powershell
2727
2728 @command{winexe} runs processes on a remote Windows host, and
2729 @value{tramp} can use it for @code{process-file} and
2730 @code{start-file-process}.
2731
2732 @code{tramp-smb-winexe-program} specifies the local @command{winexe}
2733 command.  Powershell V2.0 on the remote host is required to run
2734 processes triggered from @value{tramp}.
2735
2736 @option{explicit-shell-file-name} and @option{explicit-*-args} have to
2737 be set properly so @kbd{M-x shell} can open a proper remote shell on a
2738 Windows host.  To open @command{cmd}, set it as follows:
2739
2740 @lisp
2741 (setq explicit-shell-file-name "cmd"
2742       explicit-cmd-args '("/q"))
2743 @end lisp
2744
2745 @noindent
2746 To open @command{powershell} as a remote shell, use this:
2747
2748 @lisp
2749 (setq explicit-shell-file-name "powershell"
2750       explicit-powershell-args '("-file" "-"))
2751 @end lisp
2752
2753
2754 @node Cleanup remote connections
2755 @section Cleanup remote connections
2756 @cindex cleanup
2757
2758 @value{tramp} provides several ways to flush remote connections.
2759
2760 @deffn Command tramp-cleanup-connection vec
2761 This command flushes all connection related objects.  @option{vec} is
2762 the internal representation of a remote connection.  When called
2763 interactively, this command lists active remote connections in the
2764 minibuffer.  Each connection is of the format @file{@trampfn{method,
2765 user, host, }}.  Flushing remote connections also cleans the password
2766 cache (@pxref{Password handling}), file cache, connection cache
2767 (@pxref{Connection caching}), and connection buffers.
2768 @end deffn
2769
2770 @deffn Command tramp-cleanup-this-connection
2771 Flushes only the current buffer's remote connection objects, the same
2772 as in @code{tramp-cleanup-connection}.
2773 @end deffn
2774
2775 @deffn Command tramp-cleanup-all-connections
2776 Flushes all active remote connection objects, the same as in
2777 @code{tramp-cleanup-connection}.
2778 @end deffn
2779
2780 @deffn Command tramp-cleanup-all-buffers
2781 Just as for @code{tramp-cleanup-all-connections}, all remote
2782 connections are cleaned up in addition to killing buffers related to
2783 that remote connection.
2784 @end deffn
2785
2786
2787 @node Bug Reports
2788 @chapter Reporting Bugs and Problems
2789 @cindex bug reports
2790
2791 @value{tramp}'s development team is actively engaged in solving bugs
2792 and problems and looks to feature requests and suggestions.
2793
2794 @value{tramp}'s mailing list is the place for more advice and
2795 information on working with @value{tramp}, solving problems,
2796 discussing, and general discussions about @value{tramp}.
2797
2798 @value{tramp}'s mailing list is moderated but even non-subscribers can
2799 post for moderator approval.  Sometimes this approval step may take as
2800 long as 48 hours due to public holidays.
2801
2802 @email{tramp-devel@@gnu.org} is the mailing list.  Messages sent to
2803 this address go to all the subscribers.  This is @emph{not} the
2804 address to send subscription requests to.
2805
2806 To subscribe to the mailing list, visit:
2807 @uref{http://lists.gnu.org/mailman/listinfo/tramp-devel/, the
2808 @value{tramp} Mail Subscription Page}.
2809
2810 @ifset emacs
2811 @ifset installchapter
2812 Before sending a bug report, run the test suite first @ref{Testing}.
2813 @end ifset
2814 @end ifset
2815
2816 @findex tramp-bug
2817 Check if the bug or problem is already addressed in @xref{Frequently
2818 Asked Questions}.
2819
2820 Run @kbd{M-x tramp-bug} to generate a buffer with details of the
2821 system along with the details of the @value{tramp}
2822 installation.  Please include these details with the bug report.
2823
2824 The bug report must describe in as excruciating detail as possible the
2825 steps required to reproduce the problem.  These details must include
2826 the setup of the remote host and any special or unique conditions that
2827 exist.
2828
2829 Include a minimal test case that reproduces the problem.  This will
2830 help the development team find the best solution and avoid unrelated
2831 detours.
2832
2833 To exclude cache-related problems, flush all caches before running the
2834 test, @ref{Cleanup remote connections}.
2835
2836 When including @value{tramp}'s messages in the bug report, increase
2837 the verbosity level to 6 (@pxref{Traces and Profiles, Traces}) in the
2838 @file{~/.emacs} file before repeating steps to the bug.  Include the
2839 contents of the @file{*tramp/foo*} and @file{*debug tramp/foo*}
2840 buffers with the bug report.
2841
2842 @strong{Note} that a verbosity level greater than 6 is not necessary
2843 at this stage.  Also note that a verbosity level of 6 or greater, the
2844 contents of files and directories will be included in the debug
2845 buffer.  Passwords typed in @value{tramp} will never be included
2846 there.
2847
2848
2849 @node Frequently Asked Questions
2850 @chapter Frequently Asked Questions
2851 @cindex frequently asked questions
2852 @cindex FAQ
2853
2854 @itemize @bullet
2855 @item
2856 Where is the latest @value{tramp}?
2857
2858 @value{tramp} is available at the GNU URL:
2859
2860 @noindent
2861 @uref{ftp://ftp.gnu.org/gnu/tramp/}
2862
2863 @noindent
2864 @value{tramp}'s GNU project page is located here:
2865
2866 @noindent
2867 @uref{http://savannah.gnu.org/projects/tramp/}
2868
2869
2870 @item
2871 Which systems does it work on?
2872
2873 The package works successfully on Emacs 22, Emacs 23, Emacs 24, Emacs
2874 25, XEmacs 21 (starting with 21.4), and SXEmacs 22.
2875
2876 While Unix and Unix-like systems are the primary remote targets,
2877 @value{tramp} has equal success connecting to other platforms, such as
2878 MS Windows XP/Vista/7.
2879
2880
2881 @item
2882 How to speed up @value{tramp}?
2883
2884 @value{tramp} does many things in the background, some of which
2885 depends on network speeds, response speeds of remote hosts, and
2886 authentication delays.  During these operations, @value{tramp}'s
2887 responsiveness slows down.  Some suggestions within the scope of
2888 @value{tramp}'s settings include:
2889
2890 Use an external method, such as @option{scp}, which are faster than
2891 internal methods.
2892
2893 Keep the file @code{tramp-persistency-file-name}, which is where
2894 @value{tramp} caches remote information about hosts and files.  Caching
2895 is enabled by default.  Don't disable it.
2896
2897 Set @code{remote-file-name-inhibit-cache} to @code{nil} if remote
2898 files are not independently updated outside @value{tramp}'s control.
2899 That cache cleanup will be necessary if the remote directories or
2900 files are updated independent of @value{tramp}.
2901
2902 Set @code{tramp-completion-reread-directory-timeout} to @code{nil} to
2903 speed up completions, @ref{File name completion}.
2904
2905 Disable version control to avoid delays:
2906
2907 @lisp
2908 (setq vc-ignore-dir-regexp
2909       (format "\\(%s\\)\\|\\(%s\\)"
2910               vc-ignore-dir-regexp
2911               tramp-file-name-regexp))
2912 @end lisp
2913
2914 Disable excessive traces.  Set @code{tramp-verbose} to 3 or lower,
2915 default being 3.  Increase trace levels temporarily when hunting for
2916 bugs.
2917
2918 @item
2919 @value{tramp} does not connect to the remote host
2920
2921 Three main reasons for why @value{tramp} does not connect to the remote host:
2922
2923 @itemize @minus
2924 @item
2925 Unknown characters in the prompt
2926
2927 @value{tramp} needs a clean recognizable prompt on the remote host for
2928 accurate parsing.  Shell prompts that contain escape sequences for
2929 coloring cause parsing problems.  @ref{Remote shell setup} for
2930 customizing prompt detection using regular expressions.
2931
2932 To check if the remote host's prompt is being recognized, use this
2933 test: switch to @value{tramp} connection buffer @file{*tramp/foo*},
2934 put the cursor at the top of the buffer, and then apply the following
2935 expression:
2936
2937 @example
2938 @kbd{M-: (re-search-forward (concat tramp-shell-prompt-pattern "$"))}
2939 @end example
2940
2941 If the cursor has not moved to the prompt at the bottom of the buffer,
2942 then @value{tramp} has failed to recognize the prompt.
2943
2944 When using zsh on remote hosts, disable zsh line editor because zsh
2945 uses left-hand side and right-hand side prompts in parallel.  Add the
2946 following line to @file{~/.zshrc}:
2947
2948 @example
2949 [ $TERM = "dumb" ] && unsetopt zle && PS1='$ '
2950 @end example
2951
2952 When using fish shell on remote hosts, disable fancy formatting by
2953 adding the following to @file{~/.config/fish/config.fish}:
2954
2955 @example
2956 function fish_prompt
2957   if test $TERM = "dumb"
2958      echo "\$ "
2959   else
2960      @dots{}
2961   end
2962 end
2963 @end example
2964
2965 When using WinSSHD on remote hosts, @value{tramp} do not recognize the
2966 strange prompt settings.
2967
2968 @item
2969 Echoed characters after login
2970
2971 @value{tramp} suppresses echos from remote hosts with the
2972 @command{stty -echo} command.  But sometimes it is too late to suppress
2973 welcome messages from the remote host containing harmful control
2974 characters.  Using @option{sshx} or @option{scpx} methods can avoid
2975 this problem because they allocate a pseudo tty.  @xref{Inline
2976 methods}.
2977
2978 @item
2979 @value{tramp} stops transferring strings longer than 500 characters
2980
2981 Set @code{tramp-chunksize} to 500 to get around this problem, which is
2982 related to faulty implementation of @code{process-send-string} on
2983 HP-UX, FreeBSD and Tru64 Unix systems.  Consult the documentation for
2984 @code{tramp-chunksize} to see when this is necessary.
2985
2986 Set @code{file-precious-flag} to @code{t} for files accessed by
2987 @value{tramp} so the file contents are checked using checksum by
2988 first saving to a temporary file.
2989 @ifinfo
2990 @pxref{Saving Buffers, , , elisp}
2991 @end ifinfo
2992
2993 @lisp
2994 (add-hook
2995  'find-file-hook
2996  (lambda ()
2997    (when (file-remote-p default-directory)
2998      (set (make-local-variable 'file-precious-flag) t))))
2999 @end lisp
3000 @end itemize
3001
3002
3003 @item
3004 @value{tramp} does not recognize if a @command{ssh} session hangs
3005
3006 @command{ssh} sessions on the local host hang when the network is
3007 down.  @value{tramp} cannot safely detect such hangs.  The network
3008 configuration for @command{ssh} can be configured to kill such hangs
3009 with the following command in the @file{~/.ssh/config}:
3010
3011 @example
3012 Host *
3013      ServerAliveInterval 5
3014 @end example
3015
3016
3017 @item
3018 @value{tramp} does not use default @command{ssh} @code{ControlPath}
3019
3020 @value{tramp} overwrites @code{ControlPath} settings when initiating
3021 @command{ssh} sessions.  @value{tramp} does this to fend off a stall
3022 if a master session opened outside the @value{emacsname} session is no
3023 longer open.  That is why @value{tramp} prompts for the password again
3024 even if there is an @command{ssh} already open.
3025
3026 Some @command{ssh} versions support a @code{ControlPersist} option,
3027 which allows to set the @code{ControlPath} provided the variable
3028 @code{tramp-ssh-controlmaster-options} is customized as follows:
3029
3030 @lisp
3031 (setq tramp-ssh-controlmaster-options
3032       (concat
3033         "-o ControlPath=/tmp/ssh-ControlPath-%%r@@%%h:%%p "
3034         "-o ControlMaster=auto -o ControlPersist=yes"))
3035 @end lisp
3036
3037 Note how "%r", "%h" and "%p" must be encoded as "%%r", "%%h" and
3038 "%%p".
3039
3040 If the @file{~/.ssh/config} is configured appropriately for the above
3041 behavior, then any changes to @command{ssh} can be suppressed with
3042 this @code{nil} setting:
3043
3044 @lisp
3045 (setq tramp-use-ssh-controlmaster-options nil)
3046 @end lisp
3047
3048
3049 @item
3050 File name completion does not work with @value{tramp}
3051
3052 @acronym{ANSI} escape sequences from the remote shell may cause errors
3053 in @value{tramp}'s parsing of remote buffers.
3054
3055 To test if this is the case, open a remote shell and check if the output
3056 of @command{ls} is in color.
3057
3058 To disable @acronym{ANSI} escape sequences from the remote hosts,
3059 disable @option{--color=yes} or @option{--color=auto} in the remote
3060 host's @file{.bashrc} or @file{.profile}.  Turn this alias on and off
3061 to see if file name completion works.
3062
3063 @item
3064 File name completion does not work in directories with large number of
3065 files
3066
3067 This may be related to globbing, which is the use of shell's ability
3068 to expand wild card specifications, such as @samp{*.c}.  For
3069 directories with large number of files, globbing might exceed the
3070 shell's limit on length of command lines and hang.  @value{tramp} uses
3071 globbing.
3072
3073 To test if globbing hangs, open a shell on the remote host and then
3074 run @samp{ls -d * ..?* > /dev/null}.
3075
3076 When testing, ensure the remote shell is the same shell
3077 (@command{/bin/sh}, @command{ksh} or @command{bash}), that
3078 @value{tramp} uses when connecting to that host.
3079
3080
3081 @item
3082 How to get notified after @value{tramp} completes file transfers?
3083
3084 Make @value{emacsname} beep after reading from or writing to the
3085 remote host with the following code in @file{~/.emacs} file.
3086
3087 @lisp
3088 (defadvice tramp-handle-write-region
3089   (after tramp-write-beep-advice activate)
3090   "Make tramp beep after writing a file."
3091   (interactive)
3092   (beep))
3093
3094 (defadvice tramp-handle-do-copy-or-rename-file
3095   (after tramp-copy-beep-advice activate)
3096   "Make tramp beep after copying a file."
3097   (interactive)
3098   (beep))
3099
3100 (defadvice tramp-handle-insert-file-contents
3101   (after tramp-insert-beep-advice activate)
3102   "Make tramp beep after inserting a file."
3103   (interactive)
3104   (beep))
3105 @end lisp
3106
3107
3108 @ifset emacs
3109 @item
3110 How to get a Visual Warning when working with @samp{root} privileges
3111
3112 Get a modeline indication when working with @samp{root} privileges
3113 with the following code (tested with @value{emacsname} 22.1) in
3114 @file{~/.emacs} file:
3115
3116 @lisp
3117 (defun my-mode-line-function ()
3118   (when (string-match "^/su\\(do\\)?:" default-directory)
3119     (setq mode-line-format
3120           (format-mode-line mode-line-format 'font-lock-warning-face))))
3121
3122 (add-hook 'find-file-hook 'my-mode-line-function)
3123 (add-hook 'dired-mode-hook 'my-mode-line-function)
3124 @end lisp
3125 @end ifset
3126
3127
3128 @ifset emacs
3129 @item
3130 How to get host indication in the mode line?
3131
3132 The following code (tested with @value{emacsname} 22.1) in
3133 @file{~/.emacs} file shows it:
3134
3135 @lisp
3136 (defconst my-mode-line-buffer-identification
3137   (list
3138    '(:eval
3139      (let ((host-name
3140             (if (file-remote-p default-directory)
3141                 (tramp-file-name-host
3142                  (tramp-dissect-file-name default-directory))
3143               (system-name))))
3144        (if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
3145            (substring host-name 0 (match-beginning 1))
3146          host-name)))
3147    ": %12b"))
3148
3149 (setq-default
3150  mode-line-buffer-identification
3151  my-mode-line-buffer-identification)
3152
3153 (add-hook
3154  'dired-mode-hook
3155  (lambda ()
3156    (setq
3157     mode-line-buffer-identification
3158     my-mode-line-buffer-identification)))
3159 @end lisp
3160
3161 The mode line in @value{emacsname} 23.1 and later versions now
3162 contains an indication if @code{default-directory} for the current
3163 buffer is on a remote host.  Moreover, the corresponding tool-tip
3164 shows the remote host name.  The above @code{:eval} clause can also be
3165 simplified to show the host name in the mode line:
3166
3167 @lisp
3168    '(:eval
3169      (let ((host-name
3170             (or (file-remote-p default-directory 'host)
3171                 (system-name))))
3172        (if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
3173            (substring host-name 0 (match-beginning 1))
3174          host-name)))
3175 @end lisp
3176 @end ifset
3177
3178
3179 @ifset emacs
3180 @item
3181 Remote host does not understand default options for directory listing
3182
3183 @value{emacsname} computes the @command{dired} options based on the
3184 local host but if the remote host cannot understand the same
3185 @command{ls} command, then set them with a hook as follows:
3186
3187 @lisp
3188 (add-hook
3189  'dired-before-readin-hook
3190  (lambda ()
3191    (when (file-remote-p default-directory)
3192      (setq dired-actual-switches "-al"))))
3193 @end lisp
3194 @end ifset
3195
3196
3197 @item
3198 Why is @file{~/.sh_history} file on the remote host growing?
3199
3200 Due to @command{ksh} saving tilde expansions triggered by
3201 @value{tramp}, the history file is probably growing rapidly.  To fix,
3202 turn off saving history by putting this shell code in the
3203 @file{.kshrc} file:
3204
3205 @example
3206 if [ -f $HOME/.sh_history ] ; then
3207    /bin/rm $HOME/.sh_history
3208 fi
3209 if [ "$@{HISTFILE-unset@}" != "unset" ] ; then
3210    unset HISTFILE
3211 fi
3212 if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then
3213    unset HISTSIZE
3214 fi
3215 @end example
3216
3217 For @option{ssh}-based method, add the following line to your
3218 @file{~/.ssh/environment} file:
3219
3220 @example
3221 HISTFILE=/dev/null
3222 @end example
3223
3224
3225 @item
3226 How to shorten long file names when typing in @value{tramp}?
3227
3228 Adapt several of these approaches to reduce typing.  If the full name
3229 is @file{@trampfn{ssh, news, news.my.domain, /opt/news/etc}}, then:
3230
3231 @enumerate
3232
3233 @item
3234 Use default values for method name and user name:
3235
3236 You can define default methods and user names for hosts,
3237 (@pxref{Default Method}, @pxref{Default User}):
3238
3239 @lisp
3240 (setq tramp-default-method "ssh"
3241       tramp-default-user "news")
3242 @end lisp
3243
3244 The reduced typing: @kbd{C-x C-f @trampfn{, , news.my.domain, /opt/news/etc}}.
3245
3246 @strong{Note} that there are some useful shortcuts already.  Accessing
3247 your local host as @samp{root} user, is possible just by @kbd{C-x C-f
3248 @trampfn{su, , ,}}.
3249
3250 @item
3251 Use configuration options of the access method:
3252
3253 Programs used for access methods already offer powerful configurations
3254 (@pxref{Customizing Completion}).  For @option{ssh}, configure the
3255 file @file{~/.ssh/config}:
3256
3257 @example
3258 Host xy
3259      HostName news.my.domain
3260      User news
3261 @end example
3262
3263 The reduced typing: @kbd{C-x C-f @trampfn{ssh, , xy, /opt/news/etc}}.
3264
3265 Depending on the number of files in the directories, host names
3266 completion can further reduce key strokes: @kbd{C-x C-f
3267 @value{prefix}ssh@value{postfixhop}x @key{TAB}}.
3268
3269 @item
3270 Use environment variables to expand long strings
3271
3272 For long file names, set up environment variables that are expanded in
3273 the minibuffer.  Environment variables are set either outside
3274 @value{emacsname} or inside @value{emacsname} with Lisp:
3275
3276 @lisp
3277 (setenv "xy" "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}")
3278 @end lisp
3279
3280 The reduced typing: @kbd{C-x C-f $xy @key{RET}}.
3281
3282 @strong{Note} that file name cannot be edited here because the
3283 environment variables are not expanded during editing in the
3284 minibuffer.
3285
3286 @item Define own keys:
3287
3288 Redefine another key sequence in @value{emacsname} for @kbd{C-x C-f}:
3289
3290 @lisp
3291 (global-set-key
3292  [(control x) (control y)]
3293  (lambda ()
3294    (interactive)
3295    (find-file
3296     (read-file-name
3297      "Find Tramp file: "
3298      "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))))
3299 @end lisp
3300
3301 Simply typing @kbd{C-x C-y} would prepare minibuffer editing of file
3302 name.
3303
3304 See @uref{http://www.emacswiki.org/cgi-bin/wiki/TrampMode, the Emacs
3305 Wiki} for a more comprehensive example.
3306
3307 @item
3308 Define own abbreviation (1):
3309
3310 Abbreviation list expansion can be used to reduce typing long file names:
3311
3312 @lisp
3313 (add-to-list
3314  'directory-abbrev-alist
3315  '("^/xy" . "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))
3316 @end lisp
3317
3318 The reduced typing: @kbd{C-x C-f /xy @key{RET}}.
3319
3320 @strong{Note} that file name cannot be edited here because the
3321 environment variables are not expanded during editing in the
3322 minibuffer.
3323
3324 @item
3325 Define own abbreviation (2):
3326
3327 The @code{abbrev-mode} gives additional flexibility for editing in the
3328 minibuffer:
3329
3330 @lisp
3331 (define-abbrev-table 'my-tramp-abbrev-table
3332   '(("xy" "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}")))
3333
3334 (add-hook
3335  'minibuffer-setup-hook
3336  (lambda ()
3337    (abbrev-mode 1)
3338    (setq local-abbrev-table my-tramp-abbrev-table)))
3339
3340 (defadvice minibuffer-complete
3341   (before my-minibuffer-complete activate)
3342   (expand-abbrev))
3343
3344 ;; If you use partial-completion-mode
3345 (defadvice PC-do-completion
3346   (before my-PC-do-completion activate)
3347   (expand-abbrev))
3348 @end lisp
3349
3350 The reduced typing: @kbd{C-x C-f xy @key{TAB}}.
3351
3352 The minibuffer expands for further editing.
3353
3354 @item Use bookmarks:
3355
3356 Use bookmarks to save Tramp file names.
3357 @ifinfo
3358 @pxref{Bookmarks, , , @value{emacsdir}}.
3359 @end ifinfo
3360
3361 Upon visiting a location with @value{tramp}, save it as a bookmark with
3362 @ifset emacs
3363 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{set}}.
3364 @end ifset
3365 @ifset xemacs
3366 @kbd{@key{menu-bar} @key{view} @key{bookmarks} @key{set}}.
3367 @end ifset
3368
3369 To revisit that bookmark:
3370 @ifset emacs
3371 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{jump}}.
3372 @end ifset
3373 @ifset xemacs
3374 @kbd{@key{menu-bar} @key{view} @key{bookmarks} @key{jump}}.
3375 @end ifset
3376
3377 @item Use recent files:
3378
3379 @ifset emacs
3380 @file{recentf}
3381 @end ifset
3382 @ifset xemacs
3383 @file{recent-files}
3384 @end ifset
3385 remembers visited places.
3386 @ifinfo
3387 @ifset emacs
3388 @pxref{File Conveniences, , , @value{emacsdir}}.
3389 @end ifset
3390 @ifset xemacs
3391 @pxref{recent-files, , , edit-utils}.
3392 @end ifset
3393 @end ifinfo
3394
3395 Keep remote file names in the recent list without have to check for
3396 their accessibility through remote access:
3397
3398 @lisp
3399 @ifset emacs
3400 (recentf-mode 1)
3401 @end ifset
3402 @ifset xemacs
3403 (recent-files-initialize)
3404 (add-hook
3405  'find-file-hook
3406  (lambda ()
3407    (when (file-remote-p (buffer-file-name))
3408      (recent-files-make-permanent)))
3409  'append)
3410 @end ifset
3411 @end lisp
3412
3413 Reaching recently opened files:
3414 @ifset emacs
3415 @kbd{@key{menu-bar} @key{file} @key{Open Recent}}.
3416 @end ifset
3417 @ifset xemacs
3418 @kbd{@key{menu-bar} @key{Recent Files}}.
3419 @end ifset
3420
3421 @ifset emacs
3422 @item Use filecache:
3423
3424 Since @file{filecache} remembers visited places, add the remote
3425 directory to the cache:
3426
3427 @lisp
3428 (eval-after-load "filecache"
3429   '(file-cache-add-directory
3430     "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))
3431 @end lisp
3432
3433 Then use directory completion in the minibuffer with @kbd{C-x C-f
3434 C-@key{TAB}}.
3435 @end ifset
3436
3437 @ifset emacs
3438 @item Use bbdb:
3439
3440 @file{bbdb} has a built-in feature for @value{ftppackagename} files,
3441 which also works for @value{tramp} file names.
3442 @ifinfo
3443 @pxref{bbdb-ftp, Storing FTP sites in the BBDB, , bbdb}.
3444 @end ifinfo
3445
3446 Load @file{bbdb} in @value{emacs}:
3447
3448 @lisp
3449 (require 'bbdb)
3450 (bbdb-initialize)
3451 @end lisp
3452
3453 Create a BBDB entry with @kbd{M-x bbdb-create-ftp-site}.  Then specify
3454 a method and user name where needed.  Examples:
3455
3456 @example
3457 @kbd{M-x bbdb-create-ftp-site @key{RET}}
3458 @b{Ftp Site:} news.my.domain @key{RET}
3459 @b{Ftp Directory:} /opt/news/etc/ @key{RET}
3460 @b{Ftp Username:} ssh@value{postfixhop}news @key{RET}
3461 @b{Company:} @key{RET}
3462 @b{Additional Comments:} @key{RET}
3463 @end example
3464
3465 In BBDB buffer, access an entry by pressing the key @key{F}.
3466 @end ifset
3467
3468 @end enumerate
3469
3470 Thanks to @value{tramp} users for contributing to these recipes.
3471
3472 @item
3473 Why saved multi-hop file names do not work in a new @value{emacsname}
3474 session?
3475
3476 When saving ad-hoc multi-hop @value{tramp} file names (@pxref{Ad-hoc
3477 multi-hops}) via bookmarks, recent files,
3478 @ifset emacs
3479 filecache, bbdb,
3480 @end ifset
3481 or another package, use the full ad-hoc file name including all hops,
3482 like @file{@trampfn{ssh, bird,
3483 bastion|ssh@value{postfixhop}news.my.domain, /opt/news/etc}}.
3484
3485 Alternatively, when saving abbreviated multi-hop file names
3486 @file{@trampfn{ssh, news, news.my.domain, /opt/news/etc}}, the custom
3487 option @code{tramp-save-ad-hoc-proxies} must be set non-@code{nil}
3488 value.
3489
3490
3491 @ifset emacs
3492 @item
3493 How to connect to a remote @value{emacsname} session using @value{tramp}?
3494
3495 Configure Emacs Client
3496 @ifinfo
3497 (@pxref{Emacs Server, , , @value{emacsdir}}).
3498 @end ifinfo
3499
3500 Then on the remote host, start the Emacs Server:
3501
3502 @lisp
3503 (require 'server)
3504 (setq server-host (system-name)
3505       server-use-tcp t)
3506 (server-start)
3507 @end lisp
3508
3509 If @code{(system-name)} of the remote host cannot be resolved on the
3510 local host, use IP address instead.
3511
3512 Copy from the remote host the resulting file
3513 @file{~/.emacs.d/server/server} to the local host, to the same
3514 location.
3515
3516 Then start Emacs Client from the command line:
3517
3518 @example
3519 emacsclient @trampfn{ssh, user, host, /file/to/edit}
3520 @end example
3521
3522 @code{user} and @code{host} refer to the local host.
3523
3524 To make Emacs Client an editor for other programs, use a wrapper
3525 script @file{emacsclient.sh}:
3526
3527 @example
3528 #!/bin/sh
3529 emacsclient @trampfn{ssh, $(whoami), $(hostname --fqdn), $1}
3530 @end example
3531
3532 Then change the environment variable @env{EDITOR} to point to the
3533 wrapper script:
3534
3535 @example
3536 export EDITOR=/path/to/emacsclient.sh
3537 @end example
3538 @end ifset
3539
3540
3541 @item
3542 How to disable other packages from calling @value{tramp}?
3543
3544 There are packages that call @value{tramp} without the user ever
3545 entering a remote file name.  Even without applying a remote file
3546 syntax, some packages enable @value{tramp} on their own.  How can users
3547 disable such features.
3548
3549 @itemize @minus
3550 @item
3551 @file{ido.el}
3552
3553 Disable @value{tramp} file name completion:
3554
3555 @lisp
3556 (custom-set-variables
3557  '(ido-enable-tramp-completion nil))
3558 @end lisp
3559
3560 @item
3561 @file{rlogin.el}
3562
3563 Disable remote directory tracking mode:
3564
3565 @lisp
3566 (rlogin-directory-tracking-mode -1)
3567 @end lisp
3568 @end itemize
3569
3570
3571 @item
3572 How to disable @value{tramp}?
3573
3574 @itemize @minus
3575 @ifset emacs
3576 @item
3577 To keep @value{ftppackagename} as default the remote files access
3578 package, set this in @file{.emacs}:
3579
3580 @lisp
3581 (setq tramp-default-method "ftp")
3582 @end lisp
3583 @end ifset
3584
3585 @item
3586 To disable both
3587 @ifset emacs
3588 @value{tramp} (and @value{ftppackagename}),
3589 @end ifset
3590 @ifset xemacs
3591 @value{tramp},
3592 @end ifset
3593 set @code{tramp-mode} to @code{nil} in @file{.emacs}.
3594
3595 @lisp
3596 (setq tramp-mode nil)
3597 @end lisp
3598
3599 @item
3600 To unload @value{tramp}, type @kbd{M-x tramp-unload-tramp}.
3601 @ifset emacs
3602 Unloading @value{tramp} resets @value{ftppackagename} plugins also.
3603 @end ifset
3604 @end itemize
3605 @end itemize
3606
3607
3608 @c For the developer
3609 @node Files directories and localnames
3610 @chapter How file names, directories and localnames are mangled and managed.
3611
3612 @menu
3613 * Localname deconstruction::    Splitting a localname into its component parts.
3614 @ifset emacs
3615 * External packages::           Integrating with external Lisp packages.
3616 @end ifset
3617 @end menu
3618
3619
3620 @node Localname deconstruction
3621 @section Splitting a localname into its component parts
3622
3623 @value{tramp} package redefines lisp functions
3624 @code{file-name-directory} and @code{file-name-nondirectory} to
3625 accommodate the unique file naming syntax that @value{tramp} requires.
3626
3627 The replacements dissect the file name, use the original handler for
3628 the localname, take that result, and then re-build the @value{tramp}
3629 file name.  By relying on the original handlers for localnames,
3630 @value{tramp} benefits from platform specific hacks to the original
3631 handlers.
3632
3633
3634 @ifset emacs
3635 @node External packages
3636 @section Integrating with external Lisp packages
3637 @subsection File name completion.
3638
3639 For name completions in the minibuffer, @value{tramp} depends on the
3640 last input character to decide whether to look for method name
3641 completion or host name completion.  For example, @kbd{C-x C-f
3642 @value{prefix}ssh@value{postfixhop} @key{TAB}} is not entirely clear
3643 if @option{ssh} is a method or a host name.  But if the last input
3644 character was either @key{TAB}, @key{SPACE} or @kbd{?}, then
3645 @value{tramp} favors file name completion over host name completion.
3646
3647 What about external packages using other characters to trigger file
3648 name completions? They must somehow signal this to @value{tramp}.  Use
3649 the variable @code{non-essential} temporarily and bind it to
3650 non-@code{nil} value.
3651
3652 @lisp
3653 (let ((non-essential t))
3654   @dots{})
3655 @end lisp
3656
3657
3658 @subsection File attributes cache.
3659
3660 Keeping a local cache of remote file attributes in sync with the
3661 remote host is a time-consuming operation.  Flushing and re-querying
3662 these attributes can tax @value{tramp} to a grinding halt on busy
3663 remote servers.
3664
3665 To get around these types of slow-downs in @value{tramp}'s
3666 responsiveness, set the @code{process-file-side-effects} to @code{nil}
3667 to stop @value{tramp} from flushing the cache.  This is helpful in
3668 situations where callers to @code{process-file} know there are no file
3669 attribute changes.  The let-bind form to accomplish this:
3670
3671 @lisp
3672 (let (process-file-side-effects)
3673   @dots{})
3674 @end lisp
3675
3676 For asynchronous processes, @value{tramp} uses a process sentinel to
3677 flush file attributes cache.  When callers to @code{start-file-process}
3678 know beforehand no file attribute changes are expected, then the
3679 process sentinel should be set to the default state.  In cases where
3680 the caller defines its own process sentinel, @value{tramp}'s process
3681 sentinel is overwritten.  The caller can still flush the file
3682 attributes cache in its process sentinel with this code:
3683
3684 @lisp
3685 (unless (memq (process-status proc) '(run open))
3686   (dired-uncache remote-directory))
3687 @end lisp
3688
3689 Since @value{tramp} traverses subdirectories starting with the
3690 root-directory, it is most likely sufficient to make the
3691 @code{default-directory} of the process buffer as the root directory.
3692 @end ifset
3693
3694
3695 @node Traces and Profiles
3696 @chapter How to Customize Traces
3697
3698 @value{tramp} messages are raised with verbosity levels ranging from 0
3699 to 10.  @value{tramp} does not display all messages; only those with a
3700 verbosity level less than or equal to @code{tramp-verbose}.
3701
3702 The verbosity levels are
3703
3704           @w{ 0}  silent (no @value{tramp} messages at all)
3705 @*@indent @w{ 1}  errors
3706 @*@indent @w{ 2}  warnings
3707 @*@indent @w{ 3}  connection to remote hosts (default verbosity)
3708 @*@indent @w{ 4}  activities
3709 @*@indent @w{ 5}  internal
3710 @*@indent @w{ 6}  sent and received strings
3711 @*@indent @w{ 7}  file caching
3712 @*@indent @w{ 8}  connection properties
3713 @*@indent @w{ 9}  test commands
3714 @*@indent @w{10}  traces (huge)
3715
3716 With @code{tramp-verbose} greater than or equal to 4, messages are
3717 also written to a @value{tramp} debug buffer.  Such debug buffers are
3718 essential to bug and problem analyses.  For @value{tramp} bug reports,
3719 set the @code{tramp-verbose} level to 6 (@pxref{Bug Reports}).
3720
3721 The debug buffer is in
3722 @ifinfo
3723 @ref{Outline Mode, , , @value{emacsdir}}.
3724 @end ifinfo
3725 @ifnotinfo
3726 Outline Mode.
3727 @end ifnotinfo
3728 In this buffer, messages can be filtered by their level.  To see
3729 messages up to verbosity level 5, enter @kbd{C-u 6 C-c C-q}.
3730 @ifinfo
3731 Other navigation keys are described in
3732 @ref{Outline Visibility, , , @value{emacsdir}}.
3733 @end ifinfo
3734
3735 @value{tramp} handles errors internally.  But to get a Lisp backtrace,
3736 both the error and the signal have to be set as follows:
3737
3738 @lisp
3739 (setq debug-on-error t
3740       debug-on-signal t)
3741 @end lisp
3742
3743 To enable stepping through @value{tramp} function call traces, they
3744 have to be specifically enabled as shown in this code:
3745
3746 @lisp
3747 (require 'trace)
3748 (dolist (elt (all-completions "tramp-" obarray 'functionp))
3749   (trace-function-background (intern elt)))
3750 (untrace-function 'tramp-read-passwd)
3751 (untrace-function 'tramp-gw-basic-authentication)
3752 @end lisp
3753
3754 The buffer @file{*trace-output*} contains the output from the function
3755 call traces.  Disable @code{tramp-read-passwd} and
3756 @code{tramp-gw-basic-authentication} to stop password strings from
3757 being written to @file{*trace-output*}.
3758
3759
3760 @node Issues
3761 @chapter Debatable Issues and What Was Decided
3762
3763 @itemize @bullet
3764 @item The uuencode method does not always work.
3765
3766 @command{uudecode} on some systems cannot write to stdout, but
3767 @value{tramp} depends on encoding and decoding programs to be able to
3768 read from stdin and write to stdout.
3769
3770 We can find ways to circumvent @command{uudecode}'s ability to write
3771 to stdout, such as writing to a temporary file and then piping that to
3772 stdout.
3773
3774 But I have decided not to implement workarounds as they are too
3775 fragile to work reliably.  Some on systems, @value{tramp} will not have
3776 uuencode method.
3777
3778 @item The @value{tramp} file name syntax differs between Emacs and XEmacs.
3779
3780 The Emacs maintainers wish to use a unified file name syntax for
3781 Ange-FTP and @value{tramp} so that users don't have to learn yet
3782 another syntax though it is okay to learn new extensions.
3783
3784 For the XEmacs maintainers, the disruption from a unified file name
3785 syntax are not worth the gains.  Firstly, the XEmacs package system
3786 relies on EFS for downloading new packages and therefore is already
3787 installed.  On the other hand, @value{tramp} is not installed by
3788 default in XEmacs.  Unifying will require @value{tramp} installed from
3789 the start.
3790
3791 @ifset xemacs
3792 @strong{Note:} To make the syntax similar to @value{ftppackagename},
3793 make this change to the init file:
3794
3795 @lisp
3796 (setq tramp-unified-filenames t)
3797 (require 'tramp)
3798 @end lisp
3799
3800 To disable auto loading @value{emacsname} @value{tramp} package, set
3801 file permissions of
3802 @file{@dots{}/xemacs-packages/lisp/tramp/auto-autoloads.el*} to
3803 @code{000}.
3804
3805 When using unified file names, @value{emacsname} download sites are
3806 added to @code{tramp-default-method-alist} with default method of
3807 @option{ftp} @xref{Default Method} for proper working of the
3808 @value{emacsname} package system.
3809
3810 The syntax for unified file names is described in the @value{tramp} manual
3811 for @value{emacsothername}.
3812 @end ifset
3813 @end itemize
3814
3815
3816 @node GNU Free Documentation License
3817 @appendix GNU Free Documentation License
3818 @include doclicense.texi
3819
3820
3821 @node Function Index
3822 @unnumbered Function Index
3823 @printindex fn
3824
3825
3826 @node Variable Index
3827 @unnumbered Variable Index
3828 @printindex vr
3829
3830
3831 @node Concept Index
3832 @unnumbered Concept Index
3833 @printindex cp
3834
3835 @bye
3836
3837 @c TODO
3838 @c
3839 @c * Say something about the .login and .profile files of the remote
3840 @c   shells.
3841 @c * Explain how tramp.el works in principle: open a shell on a remote
3842 @c   host and then send commands to it.
3843 @c * Consistent small or capitalized words especially in menus.
3844 @c * Make a unique declaration of @trampfn.