Merge from emacs-24; up to 2012-12-23T02:41:17Z!rgm@gnu.org
[emacs.git] / doc / misc / tramp.texi
blob20598f2d9e52f25bdab51c266d69430b067a74dd
1 \input texinfo   @c -*-texinfo-*-
2 @setfilename ../../info/tramp
3 @c %**start of header
4 @settitle TRAMP User Manual
5 @c %**end of header
7 @c This is *so* much nicer :)
8 @footnotestyle end
10 @c In the Tramp repository, the version number is auto-frobbed from
11 @c configure.ac, so you should edit that file and run
12 @c "autoconf && ./configure" to change the version number.
14 @c Additionally, flags are set with respect to the Emacs flavor; and
15 @c depending whether Tramp is packaged into (X)Emacs, or standalone.
17 @include trampver.texi
19 @c Macro for formatting a filename according to the respective syntax.
20 @c xxx and yyy are auxiliary macros in order to omit leading and
21 @c trailing whitespace.  Not very elegant, but I don't know it better.
23 @c There are subtle differences between texinfo 4.13 and 5.0.  We must
24 @c declare two versions of the macro.  This will be improved, hopefully.
26 @c Texinfo 5.0.
27 @ifset txicommandconditionals
28 @macro xxx {one}
29 @set \one\
30 @end macro
32 @macro yyy {one, two}
33 @xxx{x\one\}@c
34 @ifclear x
35 \one\@w{}\two\@c
36 @end ifclear
37 @clear x\one\
38 @end macro
40 @macro trampfn {method, user, host, localname}
41 @value{prefix}@c
42 @yyy{\method\,@value{postfixhop}}@c
43 @yyy{\user\,@@}@c
44 \host\@value{postfix}\localname\
45 @end macro
46 @end ifset
48 @c Texinfo 4.13.
49 @ifclear txicommandconditionals
50 @macro xxx {one}@c
51 @set \one\@c
52 @end macro
54 @macro yyy {one, two}@c
55 @xxx{x\one\}@c
56 @ifclear x@c
57 \one\@w{}\two\@c
58 @end ifclear
59 @clear x\one\@c
60 @end macro
62 @macro trampfn {method, user, host, localname}@c
63 @value{prefix}@yyy{\method\,@value{postfixhop}}@yyy{\user\,@@}\host\@value{postfix}\localname\@c
64 @end macro
65 @end ifclear
67 @copying
68 Copyright @copyright{} 1999--2013 Free Software Foundation, Inc.
70 @quotation
71 Permission is granted to copy, distribute and/or modify this document
72 under the terms of the GNU Free Documentation License, Version 1.3 or
73 any later version published by the Free Software Foundation; with no
74 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
75 and with the Back-Cover Texts as in (a) below.  A copy of the license
76 is included in the section entitled ``GNU Free Documentation License''.
78 (a) The FSF's Back-Cover Text is: ``You have the freedom to
79 copy and modify this GNU manual.''
80 @end quotation
81 @end copying
83 @c Entries for @command{install-info} to use
84 @dircategory @value{emacsname} network features
85 @direntry
86 * TRAMP: (tramp).               Transparent Remote Access, Multiple Protocol
87                                 @value{emacsname} remote file access via rsh and rcp.
88 @end direntry
90 @titlepage
91 @title @value{tramp} version @value{trampver} User Manual
92 @author by Daniel Pittman
93 @author based on documentation by Kai Gro@ss{}johann
94 @page
95 @insertcopying
96 @end titlepage
98 @contents
100 @ifnottex
101 @node Top, Overview, (dir), (dir)
102 @top @value{tramp} version @value{trampver} User Manual
104 This file documents @value{tramp} version @value{trampver}, a remote file
105 editing package for @value{emacsname}.
107 @value{tramp} stands for `Transparent Remote (file) Access, Multiple
108 Protocol'.  This package provides remote file editing, similar to
109 @value{ftppackagename}.
111 The difference is that @value{ftppackagename} uses FTP to transfer
112 files between the local and the remote host, whereas @value{tramp} uses a
113 combination of @command{rsh} and @command{rcp} or other work-alike
114 programs, such as @command{ssh}/@command{scp}.
116 You can find the latest version of this document on the web at
117 @uref{http://www.gnu.org/software/tramp/}.
119 @c Pointer to the other Emacs flavor is necessary only in case of
120 @c standalone installation.
121 @ifset installchapter
122 The manual has been generated for @value{emacsname}.
123 @ifinfo
124 If you want to read the info pages for @value{emacsothername}, you
125 should read in @ref{Installation} how to create them.
126 @end ifinfo
127 @ifhtml
128 If you're using the other Emacs flavor, you should read the
129 @uref{@value{emacsotherfilename}, @value{emacsothername}} pages.
130 @end ifhtml
131 @end ifset
133 @ifhtml
134 The latest release of @value{tramp} is available for
135 @uref{ftp://ftp.gnu.org/gnu/tramp/, download}, or you may see
136 @ref{Obtaining Tramp} for more details, including the Git server
137 details.
139 @value{tramp} also has a @uref{http://savannah.gnu.org/projects/tramp/,
140 Savannah Project Page}.
141 @end ifhtml
143 There is a mailing list for @value{tramp}, available at
144 @email{tramp-devel@@gnu.org}, and archived at
145 @uref{http://lists.gnu.org/archive/html/tramp-devel/, the
146 @value{tramp} Mail Archive}.
147 @ifhtml
148 Older archives are located at
149 @uref{http://sourceforge.net/mailarchive/forum.php?forum=tramp-devel,
150 SourceForge Mail Archive} and
151 @uref{http://www.mail-archive.com/emacs-rcp@@ls6.cs.uni-dortmund.de/,
152 The Mail Archive}.
153 @c in HTML output, there's no new paragraph.
154 @*@*
155 @end ifhtml
157 @insertcopying
159 @end ifnottex
161 @menu
162 * Overview::                    What @value{tramp} can and cannot do.
164 For the end user:
166 * Obtaining Tramp::             How to obtain @value{tramp}.
167 * History::                     History of @value{tramp}.
168 @ifset installchapter
169 * Installation::                Installing @value{tramp} with your @value{emacsname}.
170 @end ifset
171 * Configuration::               Configuring @value{tramp} for use.
172 * Usage::                       An overview of the operation of @value{tramp}.
173 * Bug Reports::                 Reporting Bugs and Problems.
174 * Frequently Asked Questions::  Questions and answers from the mailing list.
176 For the developer:
178 * Files directories and localnames::  How file names, directories and localnames are mangled and managed.
179 * Traces and Profiles::         How to Customize Traces.
180 * Issues::                      Debatable Issues and What Was Decided.
182 * GNU Free Documentation License:: The license for this documentation.
183 * Function Index::              @value{tramp} functions.
184 * Variable Index::              User options and variables.
185 * Concept Index::               An item for each concept.
187 @detailmenu
188  --- The Detailed Node Listing ---
190 @ifset installchapter
191 Installing @value{tramp} with your @value{emacsname}
193 * Installation parameters::     Parameters in order to control installation.
194 * Load paths::                  How to plug-in @value{tramp} into your environment.
196 @end ifset
198 Configuring @value{tramp} for use
200 * Connection types::            Types of connections made to remote machines.
201 * Inline methods::              Inline methods.
202 * External methods::            External methods.
203 @ifset emacsgvfs
204 * GVFS based methods::          GVFS based external methods.
205 @end ifset
206 @ifset emacsgw
207 * Gateway methods::             Gateway methods.
208 @end ifset
209 * Default Method::              Selecting a default method.
210 * Default User::                Selecting a default user.
211 * Default Host::                Selecting a default host.
212 * Multi-hops::                  Connecting to a remote host using multiple hops.
213 * Customizing Methods::         Using Non-Standard Methods.
214 * Customizing Completion::      Selecting config files for user/host name completion.
215 * Password handling::           Reusing passwords for several connections.
216 * Connection caching::          Reusing connection related information.
217 * Remote Programs::             How @value{tramp} finds and uses programs on the remote machine.
218 * Remote shell setup::          Remote shell setup hints.
219 * Android shell setup::         Android shell setup hints.
220 * Auto-save and Backup::        Auto-save and Backup.
221 * Windows setup hints::         Issues with Cygwin ssh.
223 Using @value{tramp}
225 * Filename Syntax::             @value{tramp} filename conventions.
226 * Alternative Syntax::          URL-like filename syntax.
227 * Filename completion::         Filename completion.
228 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
229 * Remote processes::            Integration with other @value{emacsname} packages.
230 * Cleanup remote connections::  Cleanup remote connections.
232 How file names, directories and localnames are mangled and managed
234 * Localname deconstruction::    Breaking a localname into its components.
235 @ifset emacs
236 * External packages::           Integration with external Lisp packages.
237 @end ifset
239 @end detailmenu
240 @end menu
242 @node Overview
243 @chapter An overview of @value{tramp}
244 @cindex overview
246 After the installation of @value{tramp} into your @value{emacsname}, you
247 will be able to access files on remote machines as though they were
248 local.  Access to the remote file system for editing files, version
249 control, and @code{dired} are transparently enabled.
251 Your access to the remote machine can be with the @command{rsh},
252 @command{rlogin}, @command{telnet} programs or with any similar
253 connection method.  This connection must pass @acronym{ASCII}
254 successfully to be usable but need not be 8-bit clean.
256 The package provides support for @command{ssh} connections out of the
257 box, one of the more common uses of the package.  This allows
258 relatively secure access to machines, especially if @command{ftp}
259 access is disabled.
261 Under Windows, @value{tramp} is integrated with the PuTTY package,
262 using the @command{plink} program.
264 The majority of activity carried out by @value{tramp} requires only that
265 the remote login is possible and is carried out at the terminal.  In
266 order to access remote files @value{tramp} needs to transfer their content
267 to the local machine temporarily.
269 @value{tramp} can transfer files between the machines in a variety of ways.
270 The details are easy to select, depending on your needs and the
271 machines in question.
273 The fastest transfer methods for large files rely on a remote file
274 transfer package such as @command{rcp}, @command{scp}, @command{rsync}
275 or (under Windows) @command{pscp}.
277 If the remote copy methods are not suitable for you, @value{tramp} also
278 supports the use of encoded transfers directly through the shell.
279 This requires that the @command{mimencode} or @command{uuencode} tools
280 are available on the remote machine.  These methods are generally
281 faster for small files.
283 @value{tramp} is still under active development and any problems you encounter,
284 trivial or major, should be reported to the @value{tramp} developers.
285 @xref{Bug Reports}.
288 @subsubheading Behind the scenes
289 @cindex behind the scenes
290 @cindex details of operation
291 @cindex how it works
293 This section tries to explain what goes on behind the scenes when you
294 access a remote file through @value{tramp}.
296 Suppose you type @kbd{C-x C-f} and enter part of an @value{tramp} file name,
297 then hit @kbd{@key{TAB}} for completion.  Suppose further that this is
298 the first time that @value{tramp} is invoked for the host in question.  Here's
299 what happens:
301 @itemize
302 @item
303 @value{tramp} discovers that it needs a connection to the host.  So it
304 invokes @samp{telnet @var{host}} or @samp{rsh @var{host} -l
305 @var{user}} or a similar tool to connect to the remote host.
306 Communication with this process happens through an
307 @value{emacsname} buffer, that is, the output from the remote end
308 goes into a buffer.
310 @item
311 The remote host may prompt for a login name (for @command{telnet}).
312 The login name is given in the file name, so @value{tramp} sends the
313 login name and a newline.
315 @item
316 The remote host may prompt for a password or pass phrase (for
317 @command{rsh} or for @command{telnet} after sending the login name).
318 @value{tramp} displays the prompt in the minibuffer, asking you for the
319 password or pass phrase.
321 You enter the password or pass phrase.  @value{tramp} sends it to the remote
322 host, followed by a newline.
324 @item
325 @value{tramp} now waits for the shell prompt or for a message that the login
326 failed.
328 If @value{tramp} sees neither of them after a certain period of time
329 (a minute, say), then it issues an error message saying that it
330 couldn't find the remote shell prompt and shows you what the remote
331 host has sent.
333 If @value{tramp} sees a @samp{login failed} message, it tells you so,
334 aborts the login attempt and allows you to try again.
336 @item
337 Suppose that the login was successful and @value{tramp} sees the shell prompt
338 from the remote host.  Now @value{tramp} invokes @command{/bin/sh} because
339 Bourne shells and C shells have different command
340 syntaxes.@footnote{Invoking @command{/bin/sh} will fail if your login
341 shell doesn't recognize @samp{exec /bin/sh} as a valid command.
342 Maybe you use the Scheme shell @command{scsh}@dots{}}
344 After the Bourne shell has come up, @value{tramp} sends a few commands to
345 ensure a good working environment.  It turns off echoing, it sets the
346 shell prompt, and a few other things.
348 @item
349 Now the remote shell is up and it good working order.  Remember, what
350 was supposed to happen is that @value{tramp} tries to find out what files exist
351 on the remote host so that it can do filename completion.
353 So, @value{tramp} basically issues @command{cd} and @command{ls} commands and
354 also sometimes @command{echo} with globbing.  Another command that is
355 often used is @command{test} to find out whether a file is writable or a
356 directory or the like.  The output of each command is parsed for the
357 necessary operation.
359 @item
360 Suppose you are finished with filename completion, have entered @kbd{C-x
361 C-f}, a full file name and hit @kbd{@key{RET}}.  Now comes the time to
362 transfer the file contents from the remote host to the local host so
363 that you can edit them.
365 See above for an explanation of how @value{tramp} transfers the file contents.
367 For inline transfers, @value{tramp} issues a command like @samp{mimencode -b
368 /path/to/remote/file}, waits until the output has accumulated in the
369 buffer that's used for communication, then decodes that output to
370 produce the file contents.
372 For external transfers, @value{tramp} issues a command like the
373 following:
374 @example
375 rcp user@@host:/path/to/remote/file /tmp/tramp.4711
376 @end example
377 It then reads the local temporary file @file{/tmp/tramp.4711} into a
378 buffer and deletes the temporary file.
380 @item
381 You now edit the buffer contents, blithely unaware of what has happened
382 behind the scenes.  (Unless you have read this section, that is.)  When
383 you are finished, you type @kbd{C-x C-s} to save the buffer.
385 @item
386 Again, @value{tramp} transfers the file contents to the remote host
387 either inline or external.  This is the reverse of what happens when
388 reading the file.
389 @end itemize
391 I hope this has provided you with a basic overview of what happens
392 behind the scenes when you open a file with @value{tramp}.
395 @c For the end user
396 @node Obtaining Tramp
397 @chapter Obtaining Tramp.
398 @cindex obtaining Tramp
400 @value{tramp} is freely available on the Internet and the latest
401 release may be downloaded from @uref{ftp://ftp.gnu.org/gnu/tramp/}.
402 This release includes the full documentation and code for
403 @value{tramp}, suitable for installation.  But Emacs (22 or later)
404 includes @value{tramp} already, and there is a @value{tramp} package
405 for XEmacs, as well.  So maybe it is easier to just use those.  But if
406 you want the bleeding edge, read on@dots{}
408 For the especially brave, @value{tramp} is available from Git.  The Git
409 version is the latest version of the code and may contain incomplete
410 features or new issues.  Use these versions at your own risk.
412 Instructions for obtaining the latest development version of @value{tramp}
413 from Git can be found by going to the Savannah project page at the
414 following URL and then clicking on the Git link in the navigation bar
415 at the top.
417 @noindent
418 @uref{http://savannah.gnu.org/projects/tramp/}
420 @noindent
421 Or follow the example session below:
423 @example
424 ] @strong{cd ~/@value{emacsdir}}
425 ] @strong{git clone git://git.savannah.gnu.org/tramp.git}
426 @end example
428 @noindent
429 Tramp developers use instead
431 @example
432 ] @strong{git clone login@@git.sv.gnu.org:/srv/git/tramp.git}
433 @end example
435 @noindent
436 You should now have a directory @file{~/@value{emacsdir}/tramp}
437 containing the latest version of @value{tramp}.  You can fetch the latest
438 updates from the repository by issuing the command:
440 @example
441 ] @strong{cd ~/@value{emacsdir}/tramp}
442 ] @strong{git pull}
443 @end example
445 @noindent
446 Once you've got updated files from the Git repository, you need to run
447 @command{autoconf} in order to get an up-to-date @file{configure}
448 script:
450 @example
451 ] @strong{cd ~/@value{emacsdir}/tramp}
452 ] @strong{autoconf}
453 @end example
456 @node History
457 @chapter History of @value{tramp}
458 @cindex history
459 @cindex development history
461 Development was started end of November 1998.  The package was called
462 @file{rssh.el}, back then.  It only provided one method to access a
463 file, using @command{ssh} to log in to a remote host and using
464 @command{scp} to transfer the file contents.  After a while, the name
465 was changed to @file{rcp.el}, and now it's @value{tramp}.  Along the way,
466 many more methods for getting a remote shell and for transferring the
467 file contents were added.  Support for VC was added.
469 After that, there were added the multi-hop methods in April 2000 and
470 the unification of @value{tramp} and Ange-FTP filenames in July 2002.
471 In July 2004, multi-hop methods have been replaced by proxy hosts.
472 Running commands on remote hosts was introduced in December 2005.
473 @ifset emacsgw
474 Support of gateways exists since April 2007.
475 @end ifset
476 @ifset emacsgvfs
477 GVFS integration started in February 2009.
478 @end ifset
479 @ifset emacs
480 Remote commands on Windows hosts are available since September 2011.
481 @end ifset
482 Ad-hoc multi-hop methods (with a changed syntax) have been reenabled
483 in November 2011.  In November 2012, Juergen Hoetzel's
484 @file{tramp-adb.el} has been added.
486 In December 2001, @value{tramp} has been added to the XEmacs package
487 repository.  Being part of the Emacs repository happened in June 2002,
488 the first release including @value{tramp} was Emacs 22.1.
490 @value{tramp} is also a Debian GNU/Linux package since February 2001.
493 @c Installation chapter is necessary only in case of standalone
494 @c installation.  Text taken from trampinst.texi.
495 @ifset installchapter
496 @include trampinst.texi
497 @end ifset
499 @node Configuration
500 @chapter Configuring @value{tramp} for use
501 @cindex configuration
503 @cindex default configuration
504 @value{tramp} is (normally) fully functional when it is initially
505 installed.  It is initially configured to use the @command{scp}
506 program to connect to the remote host.  So in the easiest case, you
507 just type @kbd{C-x C-f} and then enter the filename
508 @file{@trampfn{, user, machine, /path/to.file}}.
510 On some hosts, there are problems with opening a connection.  These are
511 related to the behavior of the remote shell.  See @xref{Remote shell
512 setup}, for details on this.
514 If you do not wish to use these commands to connect to the remote
515 host, you should change the default connection and transfer method
516 that @value{tramp} uses.  There are several different methods that @value{tramp}
517 can use to connect to remote machines and transfer files
518 (@pxref{Connection types}).
520 If you don't know which method is right for you, see @xref{Default
521 Method}.
524 @menu
525 * Connection types::            Types of connections made to remote machines.
526 * Inline methods::              Inline methods.
527 * External methods::            External methods.
528 @ifset emacsgvfs
529 * GVFS based methods::          GVFS based external methods.
530 @end ifset
531 @ifset emacsgw
532 * Gateway methods::             Gateway methods.
533 @end ifset
534 * Default Method::              Selecting a default method.
535                                   Here we also try to help those who
536                                   don't have the foggiest which method
537                                   is right for them.
538 * Default User::                Selecting a default user.
539 * Default Host::                Selecting a default host.
540 * Multi-hops::                  Connecting to a remote host using multiple hops.
541 * Customizing Methods::         Using Non-Standard Methods.
542 * Customizing Completion::      Selecting config files for user/host name completion.
543 * Password handling::           Reusing passwords for several connections.
544 * Connection caching::          Reusing connection related information.
545 * Remote Programs::             How @value{tramp} finds and uses programs on the remote machine.
546 * Remote shell setup::          Remote shell setup hints.
547 * Android shell setup::         Android shell setup hints.
548 * Auto-save and Backup::        Auto-save and Backup.
549 * Windows setup hints::         Issues with Cygwin ssh.
550 @end menu
553 @node Connection types
554 @section Types of connections made to remote machines
555 @cindex connection types, overview
557 There are two basic types of transfer methods, each with its own
558 advantages and limitations.  Both types of connection make use of a
559 remote shell access program such as @command{rsh}, @command{ssh} or
560 @command{telnet} to connect to the remote machine.
562 This connection is used to perform many of the operations that @value{tramp}
563 requires to make the remote file system transparently accessible from
564 the local machine.  It is only when visiting files that the methods
565 differ.
567 @cindex inline methods
568 @cindex external methods
569 @cindex methods, inline
570 @cindex methods, external
571 Loading or saving a remote file requires that the content of the file
572 be transferred between the two machines.  The content of the file can
573 be transferred using one of two methods: the @dfn{inline method} over
574 the same connection used to log in to the remote machine, or the
575 @dfn{external method} through another connection using a remote copy
576 program such as @command{rcp}, @command{scp} or @command{rsync}.
578 The performance of the external methods is generally better than that
579 of the inline methods, at least for large files.  This is caused by
580 the need to encode and decode the data when transferring inline.
582 The one exception to this rule are the @command{scp} based transfer
583 methods.  While these methods do see better performance when actually
584 transferring files, the overhead of the cryptographic negotiation at
585 startup may drown out the improvement in file transfer times.
587 External methods should be configured such a way that they don't
588 require a password (with @command{ssh-agent}, or such alike).  Modern
589 @command{scp} implementations offer options to reuse existing
590 @command{ssh} connections, which will be enabled by default if
591 available.  If it isn't possible, you should consider @ref{Password
592 handling}, otherwise you will be prompted for a password every copy
593 action.
596 @node Inline methods
597 @section Inline methods
598 @cindex inline methods
599 @cindex methods, inline
601 The inline methods in @value{tramp} are quite powerful and can work in
602 situations where you cannot use an external transfer program to connect.
603 Inline methods are the only methods that work when connecting to the
604 remote machine via telnet.  (There are also strange inline methods which
605 allow you to transfer files between @emph{user identities} rather than
606 hosts, see below.)
608 These methods depend on the existence of a suitable encoding and
609 decoding command on remote machine.  Locally, @value{tramp} may be able to
610 use features of @value{emacsname} to decode and encode the files or
611 it may require access to external commands to perform that task.
613 @cindex uuencode
614 @cindex mimencode
615 @cindex base-64 encoding
616 @value{tramp} checks the availability and usability of commands like
617 @command{mimencode} (part of the @command{metamail} package) or
618 @command{uuencode} on the remote host.  The first reliable command
619 will be used.  The search path can be customized, see @ref{Remote
620 Programs}.
622 If both commands aren't available on the remote host, @value{tramp}
623 transfers a small piece of Perl code to the remote host, and tries to
624 apply it for encoding and decoding.
626 The variable @var{tramp-inline-compress-start-size} controls, whether
627 a file shall be compressed before encoding.  This could increase
628 transfer speed for large text files.
631 @table @asis
632 @item @option{rsh}
633 @cindex method rsh
634 @cindex rsh method
636 Connect to the remote host with @command{rsh}.  Due to the unsecure
637 connection it is recommended for very local host topology only.
639 On operating systems which provide the command @command{remsh} instead
640 of @command{rsh}, you can use the method @option{remsh}.  This is true
641 for HP-UX or Cray UNICOS, for example.
644 @item @option{ssh}
645 @cindex method ssh
646 @cindex ssh method
648 Connect to the remote host with @command{ssh}.  This is identical to
649 the previous option except that the @command{ssh} package is used,
650 making the connection more secure.
652 There are also two variants, @option{ssh1} and @option{ssh2}, that
653 call @samp{ssh -1} and @samp{ssh -2}, respectively.  This way, you can
654 explicitly select whether you want to use the SSH protocol version 1
655 or 2 to connect to the remote host.  (You can also specify in
656 @file{~/.ssh/config}, the SSH configuration file, which protocol
657 should be used, and use the regular @option{ssh} method.)
659 All the methods based on @command{ssh} have an additional feature: you
660 can specify a host name which looks like @file{host#42} (the real host
661 name, then a hash sign, then a port number).  This means to connect to
662 the given host but to also pass @code{-p 42} as arguments to the
663 @command{ssh} command.
666 @item @option{telnet}
667 @cindex method telnet
668 @cindex telnet method
670 Connect to the remote host with @command{telnet}.  This is as unsecure
671 as the @option{rsh} method.
674 @item @option{su}
675 @cindex method su
676 @cindex su method
678 This method does not connect to a remote host at all, rather it uses
679 the @command{su} program to allow you to edit files as another user.
680 That means, the specified host name in the file name must be either
681 @samp{localhost} or the host name as returned by the function
682 @command{(system-name)}.  For an exception of this rule see
683 @ref{Multi-hops}.
686 @item @option{sudo}
687 @cindex method sudo
688 @cindex sudo method
690 This is similar to the @option{su} method, but it uses @command{sudo}
691 rather than @command{su} to become a different user.
693 Note that @command{sudo} must be configured to allow you to start a
694 shell as the user.  It would be nice if it was sufficient if
695 @command{ls} and @command{mimencode} were allowed, but that is not
696 easy to implement, so I haven't got around to it, yet.
699 @item @option{sshx}
700 @cindex method sshx
701 @cindex sshx method
703 As you would expect, this is similar to @option{ssh}, only a little
704 different.  Whereas @option{ssh} opens a normal interactive shell on
705 the remote host, this option uses @samp{ssh -t -t @var{host} -l
706 @var{user} /bin/sh} to open a connection.  This is useful for users
707 where the normal login shell is set up to ask them a number of
708 questions when logging in.  This procedure avoids these questions, and
709 just gives @value{tramp} a more-or-less `standard' login shell to work
710 with.
712 Note that this procedure does not eliminate questions asked by
713 @command{ssh} itself.  For example, @command{ssh} might ask ``Are you
714 sure you want to continue connecting?'' if the host key of the remote
715 host is not known.  @value{tramp} does not know how to deal with such a
716 question (yet), therefore you will need to make sure that you can log
717 in without such questions.
719 This is also useful for Windows users where @command{ssh}, when
720 invoked from an @value{emacsname} buffer, tells them that it is not
721 allocating a pseudo tty.  When this happens, the login shell is wont
722 to not print any shell prompt, which confuses @value{tramp} mightily.
724 This supports the @samp{-p} argument.
727 @item @option{krlogin}
728 @cindex method krlogin
729 @cindex krlogin method
730 @cindex Kerberos (with krlogin method)
732 This method is also similar to @option{ssh}.  It only uses the
733 @command{krlogin -x} command to log in to the remote host.
736 @item @option{ksu}
737 @cindex method ksu
738 @cindex ksu method
739 @cindex Kerberos (with ksu method)
741 This is another method from the Kerberos suite.  It behaves like @option{su}.
744 @item @option{plink}
745 @cindex method plink
746 @cindex plink method
748 This method is mostly interesting for Windows users using the PuTTY
749 implementation of SSH@.  It uses @samp{plink -ssh} to log in to the
750 remote host.
752 This supports the @samp{-P} argument.
754 Additionally, the methods @option{plink1} and @option{plink2} are
755 provided, which call @samp{plink -1 -ssh} or @samp{plink -2 -ssh} in
756 order to use SSH protocol version 1 or 2 explicitly.
758 CCC: Do we have to connect to the remote host once from the command
759 line to accept the SSH key?  Maybe this can be made automatic?
761 CCC: Say something about the first shell command failing.  This might
762 be due to a wrong setting of @code{tramp-rsh-end-of-line}.
765 @item @option{plinkx}
766 @cindex method plinkx
767 @cindex plinkx method
769 Another method using PuTTY on Windows.  Instead of host names, it
770 expects PuTTY session names, calling @samp{plink -load @var{session}
771 -t"}.  User names are relevant only in case the corresponding session
772 hasn't defined a user name.  Different port numbers must be defined in
773 the session.
775 @end table
778 @node External methods
779 @section External methods
780 @cindex methods, external
781 @cindex external methods
783 The external methods operate through multiple channels, using the
784 remote shell connection for many actions while delegating file
785 transfers to an external transfer utility.
787 This saves the overhead of encoding and decoding that multiplexing the
788 transfer through the one connection has with the inline methods.
790 Since external methods need their own overhead opening a new channel,
791 all files which are smaller than @var{tramp-copy-size-limit} are still
792 transferred with the corresponding inline method.  It should provide a
793 fair trade-off between both approaches.
795 @table @asis
796 @item @option{rcp}---@command{rsh} and @command{rcp}
797 @cindex method rcp
798 @cindex rcp method
799 @cindex rcp (with rcp method)
800 @cindex rsh (with rcp method)
802 This method uses the @command{rsh} and @command{rcp} commands to connect
803 to the remote machine and transfer files.  This is probably the fastest
804 connection method available.
806 The alternative method @option{remcp} uses the @command{remsh} and
807 @command{rcp} commands.  It should be applied on machines where
808 @command{remsh} is used instead of @command{rsh}.
811 @item @option{scp}---@command{ssh} and @command{scp}
812 @cindex method scp
813 @cindex scp method
814 @cindex scp (with scp method)
815 @cindex ssh (with scp method)
817 Using @command{ssh} to connect to the remote host and @command{scp} to
818 transfer files between the machines is the best method for securely
819 connecting to a remote machine and accessing files.
821 The performance of this option is also quite good.  It may be slower than
822 the inline methods when you often open and close small files however.
823 The cost of the cryptographic handshake at the start of an @command{scp}
824 session can begin to absorb the advantage that the lack of encoding and
825 decoding presents.
827 There are also two variants, @option{scp1} and @option{scp2}, that
828 call @samp{ssh -1} and @samp{ssh -2}, respectively.  This way, you can
829 explicitly select whether you want to use the SSH protocol version 1
830 or 2 to connect to the remote host.  (You can also specify in
831 @file{~/.ssh/config}, the SSH configuration file, which protocol
832 should be used, and use the regular @option{scp} method.)
834 All the @command{ssh} based methods support the @samp{-p} feature
835 where you can specify a port number to connect to in the host name.
836 For example, the host name @file{host#42} tells @value{tramp} to
837 specify @samp{-p 42} in the argument list for @command{ssh}, and to
838 specify @samp{-P 42} in the argument list for @command{scp}.
841 @item @option{sftp}---@command{ssh} and @command{sftp}
842 @cindex method sftp
843 @cindex sftp method
844 @cindex sftp (with sftp method)
845 @cindex ssh (with sftp method)
847 That is mostly the same method as @option{scp}, but using
848 @command{sftp} as transfer command.  So the same remarks are valid.
850 This command does not work like @value{ftppackagename}, where
851 @command{ftp} is called interactively, and all commands are send from
852 within this session.  Instead of, @command{ssh} is used for login.
854 This method supports the @samp{-p} argument.
857 @item @option{rsync}---@command{ssh} and @command{rsync}
858 @cindex method rsync
859 @cindex rsync method
860 @cindex rsync (with rsync method)
861 @cindex ssh (with rsync method)
863 Using the @command{ssh} command to connect securely to the remote
864 machine and the @command{rsync} command to transfer files is almost
865 identical to the @option{scp} method.
867 While @command{rsync} performs much better than @command{scp} when
868 transferring files that exist on both hosts, this advantage is lost if
869 the file exists only on one side of the connection.  A file can exists
870 on both the remote and local host, when you copy a file from/to a
871 remote host.  When you just open a file from the remote host (or write
872 a file there), a temporary file on the local side is kept as long as
873 the corresponding buffer, visiting this file, is alive.
875 This method supports the @samp{-p} argument.
878 @item @option{scpx}---@command{ssh} and @command{scp}
879 @cindex method scpx
880 @cindex scpx method
881 @cindex scp (with scpx method)
882 @cindex ssh (with scpx method)
884 As you would expect, this is similar to @option{scp}, only a little
885 different.  Whereas @option{scp} opens a normal interactive shell on
886 the remote host, this option uses @samp{ssh -t -t @var{host} -l
887 @var{user} /bin/sh} to open a connection.  This is useful for users
888 where the normal login shell is set up to ask them a number of
889 questions when logging in.  This procedure avoids these questions, and
890 just gives @value{tramp} a more-or-less `standard' login shell to work
891 with.
893 This is also useful for Windows users where @command{ssh}, when
894 invoked from an @value{emacsname} buffer, tells them that it is not
895 allocating a pseudo tty.  When this happens, the login shell is wont
896 to not print any shell prompt, which confuses @value{tramp} mightily.
898 This method supports the @samp{-p} argument.
901 @item @option{pscp}---@command{plink} and @command{pscp}
902 @cindex method pscp
903 @cindex pscp method
904 @cindex pscp (with pscp method)
905 @cindex plink (with pscp method)
906 @cindex PuTTY (with pscp method)
908 This method is similar to @option{scp}, but it uses the
909 @command{plink} command to connect to the remote host, and it uses
910 @command{pscp} for transferring the files.  These programs are part
911 of PuTTY, an SSH implementation for Windows.
913 This method supports the @samp{-P} argument.
916 @item @option{psftp}---@command{plink} and @command{psftp}
917 @cindex method psftp
918 @cindex psftp method
919 @cindex psftp (with psftp method)
920 @cindex plink (with psftp method)
921 @cindex PuTTY (with psftp method)
923 As you would expect, this method is similar to @option{sftp}, but it
924 uses the @command{plink} command to connect to the remote host, and it
925 uses @command{psftp} for transferring the files.  These programs are
926 part of PuTTY, an SSH implementation for Windows.
928 This method supports the @samp{-P} argument.
931 @item @option{fcp}---@command{fsh} and @command{fcp}
932 @cindex method fcp
933 @cindex fcp method
934 @cindex fsh (with fcp method)
935 @cindex fcp (with fcp method)
937 This method is similar to @option{scp}, but it uses the @command{fsh}
938 command to connect to the remote host, and it uses @command{fcp} for
939 transferring the files.  @command{fsh/fcp} are a front-end for
940 @command{ssh} which allow for reusing the same @command{ssh} session
941 for submitting several commands.  This avoids the startup overhead of
942 @command{scp} (which has to establish a secure connection whenever it
943 is called).  Note, however, that you can also use one of the inline
944 methods to achieve a similar effect.
946 This method uses the command @samp{fsh @var{host} -l @var{user}
947 /bin/sh -i} to establish the connection, it does not work to just say
948 @command{fsh @var{host} -l @var{user}}.
950 @cindex method fsh
951 @cindex fsh method
953 There is no inline method using @command{fsh} as the multiplexing
954 provided by the program is not very useful in our context.  @value{tramp}
955 opens just one connection to the remote host and then keeps it open,
956 anyway.
959 @item @option{ftp}
960 @cindex method ftp
961 @cindex ftp method
963 This is not a native @value{tramp} method.  Instead, it forwards all
964 requests to @value{ftppackagename}.
965 @ifset xemacs
966 This works only for unified filenames, see @ref{Issues}.
967 @end ifset
970 @item @option{smb}---@command{smbclient}
971 @cindex method smb
972 @cindex smb method
974 This is another not native @value{tramp} method.  It uses the
975 @command{smbclient} command on different Unices in order to connect to
976 an SMB server.  An SMB server might be a Samba (or CIFS) server on
977 another UNIX host or, more interesting, a host running MS Windows.  So
978 far, it is tested against MS Windows NT, MS Windows 2000, MS Windows
979 XP, MS Windows Vista, and MS Windows 7.
981 The first directory in the localname must be a share name on the remote
982 host.  Remember that the @code{$} character, in which default shares
983 usually end, must be written @code{$$} due to environment variable
984 substitution in file names.  If no share name is given (i.e., remote
985 directory @code{/}), all available shares are listed.
987 Since authorization is done on share level, you will always be
988 prompted for a password if you access another share on the same host.
989 This can be suppressed by @ref{Password handling}.
991 For authorization, MS Windows uses both a user name and a domain name.
992 Because of this, the @value{tramp} syntax has been extended: you can
993 specify a user name which looks like @code{user%domain} (the real user
994 name, then a percent sign, then the domain name).  So, to connect to
995 the machine @code{melancholia} as user @code{daniel} of the domain
996 @code{BIZARRE}, and edit @file{.emacs} in the home directory (share
997 @code{daniel$}) I would specify the filename @file{@trampfn{smb,
998 daniel%BIZARRE, melancholia, /daniel$$/.emacs}}.
1000 Depending on the Windows domain configuration, a Windows user might be
1001 considered as domain user per default.  In order to connect as local
1002 user, the WINS name of that machine must be given as domain name.
1003 Usually, it is the machine name in capital letters.  In the example
1004 above, the local user @code{daniel} would be specified as
1005 @file{@trampfn{smb, daniel%MELANCHOLIA, melancholia, /daniel$$/.emacs}}.
1007 The domain name as well as the user name are optional.  If no user
1008 name is specified at all, the anonymous user (without password
1009 prompting) is assumed.  This is different from all other @value{tramp}
1010 methods, where in such a case the local user name is taken.
1012 The @option{smb} method supports the @samp{-p} argument.
1014 @strong{Please note:} If @value{emacsname} runs locally under MS
1015 Windows, this method isn't available.  Instead, you can use UNC
1016 file names like @file{//melancholia/daniel$$/.emacs}.  The only
1017 disadvantage is that there's no possibility to specify another user
1018 name.
1021 @item @option{adb}
1022 @cindex method adb
1023 @cindex adb method
1025 This special method uses the Android Debug Bridge for connecting
1026 Android devices.  The Android Debug Bridge, part of the Android SDK,
1027 must be installed locally.  The variable @var{tramp-adb-sdk-dir} must
1028 be set to its installation directory.
1030 @end table
1033 @ifset emacsgvfs
1034 @node GVFS based methods
1035 @section GVFS based external methods
1036 @cindex methods, gvfs
1037 @cindex gvfs based methods
1038 @cindex dbus
1040 The connection methods described in this section are based on GVFS
1041 @uref{http://en.wikipedia.org/wiki/GVFS}.  Via GVFS, the remote
1042 filesystem is mounted locally through FUSE@.  @value{tramp} uses
1043 this local mounted directory internally.
1045 The communication with GVFS is implemented via D-Bus messages.
1046 Therefore, your @value{emacsname} must have D-Bus integration,
1047 @pxref{Top, , D-Bus, dbus}.
1049 @table @asis
1050 @item @option{dav}
1051 @cindex method dav
1052 @cindex method davs
1053 @cindex dav method
1054 @cindex davs method
1056 This method provides access to WebDAV files and directories.  There
1057 exists also the external method @option{davs}, which uses SSL
1058 encryption for the access.
1060 Both methods support the port number specification as discussed above.
1063 @item @option{obex}
1064 @cindex method obex
1065 @cindex obex method
1067 OBEX is an FTP-like access protocol for simple devices, like cell
1068 phones.  For the time being, @value{tramp} only supports OBEX over Bluetooth.
1071 @item @option{synce}
1072 @cindex method synce
1073 @cindex synce method
1075 The @option{synce} method allows communication with Windows Mobile
1076 devices.  Beside GVFS for mounting remote files and directories via
1077 FUSE, it also needs the SYNCE-GVFS plugin.
1079 @end table
1081 @defopt tramp-gvfs-methods
1082 This customer option, a list, defines the external methods which
1083 shall be used with GVFS@.  Per default, these are @option{dav},
1084 @option{davs}, @option{obex} and @option{synce}.  Other possible
1085 values are @option{ftp}, @option{sftp} and @option{smb}.
1086 @end defopt
1087 @end ifset
1090 @ifset emacsgw
1091 @node Gateway methods
1092 @section Gateway methods
1093 @cindex methods, gateway
1094 @cindex gateway methods
1096 Gateway methods are not methods to access a remote host directly.
1097 These methods are intended to pass firewalls or proxy servers.
1098 Therefore, they can be used for proxy host declarations
1099 (@pxref{Multi-hops}) only.
1101 A gateway method must always come along with a method which supports
1102 port setting.  This is because @value{tramp} targets the accompanied
1103 method to @file{localhost#random_port}, from where the firewall or
1104 proxy server is accessed.
1106 Gateway methods support user name and password declarations.  These
1107 are used to authenticate towards the corresponding firewall or proxy
1108 server.  They can be passed only if your friendly administrator has
1109 granted your access.
1111 @table @asis
1112 @item @option{tunnel}
1113 @cindex method tunnel
1114 @cindex tunnel method
1116 This method implements an HTTP tunnel via the @command{CONNECT}
1117 command (see RFC 2616, 2817).  Any HTTP 1.1 compliant (proxy) server
1118 shall support this command.
1120 As authentication method, only @option{Basic Authentication} (see RFC
1121 2617) is implemented so far.  If no port number is given in the
1122 declaration, port @option{8080} is used for the proxy server.
1125 @item @option{socks}
1126 @cindex method socks
1127 @cindex socks method
1129 The @command{socks} method provides access to SOCKSv5 servers (see
1130 RFC 1928).  @option{Username/Password Authentication} according to RFC
1131 1929 is supported.
1133 The default port number of the socks server is @option{1080}, if not
1134 specified otherwise.
1136 @end table
1137 @end ifset
1140 @node Default Method
1141 @section Selecting a default method
1142 @cindex default method
1144 @vindex tramp-default-method
1145 When you select an appropriate transfer method for your typical usage
1146 you should set the variable @code{tramp-default-method} to reflect that
1147 choice.  This variable controls which method will be used when a method
1148 is not specified in the @value{tramp} file name.  For example:
1150 @lisp
1151 (setq tramp-default-method "ssh")
1152 @end lisp
1154 @vindex tramp-default-method-alist
1155 You can also specify different methods for certain user/host
1156 combinations, via the variable @code{tramp-default-method-alist}.  For
1157 example, the following two lines specify to use the @option{ssh}
1158 method for all user names matching @samp{john} and the @option{rsync}
1159 method for all host names matching @samp{lily}.  The third line
1160 specifies to use the @option{su} method for the user @samp{root} on
1161 the machine @samp{localhost}.
1163 @lisp
1164 (add-to-list 'tramp-default-method-alist '("" "john" "ssh"))
1165 (add-to-list 'tramp-default-method-alist '("lily" "" "rsync"))
1166 (add-to-list 'tramp-default-method-alist
1167              '("\\`localhost\\'" "\\`root\\'" "su"))
1168 @end lisp
1170 @noindent
1171 See the documentation for the variable
1172 @code{tramp-default-method-alist} for more details.
1174 External methods are normally preferable to inline methods, giving
1175 better performance.
1177 @xref{Inline methods}.
1178 @xref{External methods}.
1180 Another consideration with the selection of transfer methods is the
1181 environment you will use them in and, especially when used over the
1182 Internet, the security implications of your preferred method.
1184 The @option{rsh} and @option{telnet} methods send your password as
1185 plain text as you log in to the remote machine, as well as
1186 transferring the files in such a way that the content can easily be
1187 read from other machines.
1189 If you need to connect to remote systems that are accessible from the
1190 Internet, you should give serious thought to using @option{ssh} based
1191 methods to connect.  These provide a much higher level of security,
1192 making it a non-trivial exercise for someone to obtain your password
1193 or read the content of the files you are editing.
1196 @subsection Which method is the right one for me?
1197 @cindex choosing the right method
1199 Given all of the above, you are probably thinking that this is all fine
1200 and good, but it's not helping you to choose a method!  Right you are.
1201 As a developer, we don't want to boss our users around but give them
1202 maximum freedom instead.  However, the reality is that some users would
1203 like to have some guidance, so here I'll try to give you this guidance
1204 without bossing you around.  You tell me whether it works @dots{}
1206 My suggestion is to use an inline method.  For large files, external
1207 methods might be more efficient, but I guess that most people will
1208 want to edit mostly small files.  And if you access large text files,
1209 compression (driven by @var{tramp-inline-compress-start-size}) shall
1210 still result in good performance.
1212 I guess that these days, most people can access a remote machine by
1213 using @command{ssh}.  So I suggest that you use the @option{ssh}
1214 method.  So, type @kbd{C-x C-f @trampfn{ssh, root, otherhost,
1215 /etc/motd} @key{RET}} to edit the @file{/etc/motd} file on the other
1216 host.
1218 If you can't use @option{ssh} to log in to the remote host, then
1219 select a method that uses a program that works.  For instance, Windows
1220 users might like the @option{plink} method which uses the PuTTY
1221 implementation of @command{ssh}.  Or you use Kerberos and thus like
1222 @option{krlogin}.
1224 For the special case of editing files on the local host as another
1225 user, see the @option{su} or @option{sudo} methods.  They offer
1226 shortened syntax for the @samp{root} account, like
1227 @file{@trampfn{su, , , /etc/motd}}.
1229 People who edit large files may want to consider @option{scp} instead
1230 of @option{ssh}, or @option{pscp} instead of @option{plink}.  These
1231 external methods are faster than inline methods for large files.
1232 Note, however, that external methods suffer from some limitations.
1233 Please try first whether you really get a noticeable speed advantage
1234 from using an external method!  Maybe even for large files, inline
1235 methods are fast enough.
1238 @node Default User
1239 @section Selecting a default user
1240 @cindex default user
1242 The user part of a @value{tramp} file name can be omitted.  Usually,
1243 it is replaced by the user name you are logged in.  Often, this is not
1244 what you want.  A typical use of @value{tramp} might be to edit some
1245 files with root permissions on the local host.  This case, you should
1246 set the variable @code{tramp-default-user} to reflect that choice.
1247 For example:
1249 @lisp
1250 (setq tramp-default-user "root")
1251 @end lisp
1253 @code{tramp-default-user} is regarded as obsolete, and will be removed
1254 soon.
1256 @vindex tramp-default-user-alist
1257 You can also specify different users for certain method/host
1258 combinations, via the variable @code{tramp-default-user-alist}.  For
1259 example, if you always have to use the user @samp{john} in the domain
1260 @samp{somewhere.else}, you can specify the following:
1262 @lisp
1263 (add-to-list 'tramp-default-user-alist
1264              '("ssh" ".*\\.somewhere\\.else\\'" "john"))
1265 @end lisp
1267 @noindent
1268 See the documentation for the variable @code{tramp-default-user-alist}
1269 for more details.
1271 One trap to fall in must be known.  If @value{tramp} finds a default
1272 user, this user will be passed always to the connection command as
1273 parameter (for example @command{ssh here.somewhere.else -l john}.  If
1274 you have specified another user for your command in its configuration
1275 files, @value{tramp} cannot know it, and the remote access will fail.
1276 If you have specified in the given example in @file{~/.ssh/config} the
1277 lines
1279 @example
1280 Host here.somewhere.else
1281      User lily
1282 @end example
1284 @noindent
1285 than you must discard selecting a default user by @value{tramp}.  This
1286 will be done by setting it to @code{nil} (or @samp{lily}, likewise):
1288 @lisp
1289 (add-to-list 'tramp-default-user-alist
1290              '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
1291 @end lisp
1293 The last entry in @code{tramp-default-user-alist} could be your
1294 default user you'll apply predominantly.  You shall @emph{append} it
1295 to that list at the end:
1297 @lisp
1298 (add-to-list 'tramp-default-user-alist '(nil nil "jonas") t)
1299 @end lisp
1302 @node Default Host
1303 @section Selecting a default host
1304 @cindex default host
1306 @vindex tramp-default-host
1307 Finally, it is even possible to omit the host name part of a
1308 @value{tramp} file name.  This case, the value of the variable
1309 @code{tramp-default-host} is used.  Per default, it is initialized
1310 with the host name your local @value{emacsname} is running.
1312 If you, for example, use @value{tramp} mainly to contact the host
1313 @samp{target} as user @samp{john}, you can specify:
1315 @lisp
1316 (setq tramp-default-user "john"
1317       tramp-default-host "target")
1318 @end lisp
1320 Then the simple file name @samp{@trampfn{ssh, , ,}} will connect you
1321 to John's home directory on target.
1322 @ifset emacs
1323 Note, however, that the most simplification @samp{/::} won't work,
1324 because @samp{/:} is the prefix for quoted file names.
1325 @end ifset
1327 @vindex tramp-default-host-alist
1328 Like with methods and users, you can also specify different default
1329 hosts for certain method/user combinations via the variable
1330 @code{tramp-default-host-alist}.  Usually, this isn't necessary,
1331 because @code{tramp-default-host} should be sufficient.  For some
1332 methods, like @option{adb}, that default value must be overwritten,
1333 which is already the initial value of @code{tramp-default-host-alist}.
1335 @noindent
1336 See the documentation for the variable @code{tramp-default-host-alist}
1337 for more details.
1340 @node Multi-hops
1341 @section Connecting to a remote host using multiple hops
1342 @cindex multi-hop
1343 @cindex proxy hosts
1345 Sometimes, the methods described before are not sufficient.
1346 Sometimes, it is not possible to connect to a remote host using a
1347 simple command.  For example, if you are in a secured network, you
1348 might have to log in to a bastion host first before you can connect to
1349 the outside world.  Of course, the target host may also require a
1350 bastion host.
1352 @vindex tramp-default-proxies-alist
1353 @defopt tramp-default-proxies-alist
1354 In order to specify multiple hops, it is possible to define a proxy
1355 host to pass through, via the variable
1356 @code{tramp-default-proxies-alist}.  This variable keeps a list of
1357 triples (@var{host} @var{user} @var{proxy}).
1359 The first matching item specifies the proxy host to be passed for a
1360 file name located on a remote target matching @var{user}@@@var{host}.
1361 @var{host} and @var{user} are regular expressions or @code{nil}, which
1362 is interpreted as a regular expression which always matches.
1364 @var{proxy} must be a Tramp filename which localname part is ignored.
1365 Method and user name on @var{proxy} are optional, which is interpreted
1366 with the default values.
1367 @ifset emacsgw
1368 The method must be an inline or gateway method (@pxref{Inline
1369 methods}, @pxref{Gateway methods}).
1370 @end ifset
1371 @ifclear emacsgw
1372 The method must be an inline method (@pxref{Inline methods}).
1373 @end ifclear
1374 If @var{proxy} is @code{nil}, no additional hop is required reaching
1375 @var{user}@@@var{host}.
1377 If you, for example, must pass the host @samp{bastion.your.domain} as
1378 user @samp{bird} for any remote host which is not located in your local
1379 domain, you can set
1381 @lisp
1382 (add-to-list 'tramp-default-proxies-alist
1383              '("\\." nil "@trampfn{ssh, bird, bastion.your.domain,}"))
1384 (add-to-list 'tramp-default-proxies-alist
1385              '("\\.your\\.domain\\'" nil nil))
1386 @end lisp
1388 Please note the order of the code.  @code{add-to-list} adds elements at the
1389 beginning of a list.  Therefore, most relevant rules must be added last.
1391 Proxy hosts can be cascaded.  If there is another host called
1392 @samp{jump.your.domain}, which is the only one in your local domain who
1393 is allowed connecting @samp{bastion.your.domain}, you can add another
1394 rule:
1396 @lisp
1397 (add-to-list 'tramp-default-proxies-alist
1398              '("\\`bastion\\.your\\.domain\\'"
1399                "\\`bird\\'"
1400                "@trampfn{ssh, , jump.your.domain,}"))
1401 @end lisp
1403 @var{proxy} can contain the patterns @code{%h} or @code{%u}.  These
1404 patterns are replaced by the strings matching @var{host} or
1405 @var{user}, respectively.
1407 If you, for example, wants to work as @samp{root} on hosts in the
1408 domain @samp{your.domain}, but login as @samp{root} is disabled for
1409 non-local access, you might add the following rule:
1411 @lisp
1412 (add-to-list 'tramp-default-proxies-alist
1413              '("\\.your\\.domain\\'" "\\`root\\'" "@trampfn{ssh, , %h,}"))
1414 @end lisp
1416 Opening @file{@trampfn{sudo, , randomhost.your.domain,}} would connect
1417 first @samp{randomhost.your.domain} via @code{ssh} under your account
1418 name, and perform @code{sudo -u root} on that host afterwards.  It is
1419 important to know that the given method is applied on the host which
1420 has been reached so far.  @code{sudo -u root}, applied on your local
1421 host, wouldn't be useful here.
1423 @var{host}, @var{user} and @var{proxy} can also be Lisp forms.  These
1424 forms are evaluated, and must return a string, or @code{nil}.  The
1425 previous example could be generalized then: For all hosts except my
1426 local one connect via @command{ssh} first, and apply @command{sudo -u
1427 root} afterwards:
1429 @lisp
1430 (add-to-list 'tramp-default-proxies-alist
1431              '(nil "\\`root\\'" "@trampfn{ssh, , %h,}"))
1432 (add-to-list 'tramp-default-proxies-alist
1433              '((regexp-quote (system-name)) nil nil))
1434 @end lisp
1436 This is the recommended configuration to work as @samp{root} on remote
1437 Ubuntu hosts.
1439 @ifset emacsgw
1440 Finally, @code{tramp-default-proxies-alist} can be used to pass
1441 firewalls or proxy servers.  Imagine your local network has a host
1442 @samp{proxy.your.domain} which is used on port 3128 as HTTP proxy to
1443 the outer world.  Your friendly administrator has granted you access
1444 under your user name to @samp{host.other.domain} on that proxy
1445 server.@footnote{HTTP tunnels are intended for secure SSL/TLS
1446 communication.  Therefore, many proxy server restrict the tunnels to
1447 related target ports.  You might need to run your ssh server on your
1448 target host @samp{host.other.domain} on such a port, like 443 (https).
1449 See @uref{http://savannah.gnu.org/maintenance/CvsFromBehindFirewall}
1450 for discussion of ethical issues.}  You would need to add the
1451 following rule:
1453 @lisp
1454 (add-to-list 'tramp-default-proxies-alist
1455              '("\\`host\\.other\\.domain\\'" nil
1456                "@trampfn{tunnel, , proxy.your.domain#3128,}"))
1457 @end lisp
1459 Gateway methods can be declared as first hop only in a multiple hop
1460 chain.
1461 @end ifset
1462 @end defopt
1464 Hops to be passed tend to be restricted firewalls and alike.
1465 Sometimes they offer limited features only, like running @command{rbash}
1466 (restricted bash).  This must be told to @value{tramp}.
1468 @vindex tramp-restricted-shell-hosts-alist
1469 @defopt tramp-restricted-shell-hosts-alist
1470 This variable keeps a list of regular expressions, which denote hosts
1471 running a registered shell like "rbash".  Those hosts can be used as
1472 proxies only.
1474 If the bastion host from the example above runs a restricted shell,
1475 you shall apply
1477 @lisp
1478 (add-to-list 'tramp-restricted-shell-hosts-alist
1479              "\\`bastion\\.your\\.domain\\'")
1480 @end lisp
1481 @end defopt
1484 @node Customizing Methods
1485 @section Using Non-Standard Methods
1486 @cindex customizing methods
1487 @cindex using non-standard methods
1488 @cindex create your own methods
1490 There is a variable @code{tramp-methods} which you can change if the
1491 predefined methods don't seem right.
1493 For the time being, I'll refer you to the Lisp documentation of that
1494 variable, accessible with @kbd{C-h v tramp-methods @key{RET}}.
1497 @node Customizing Completion
1498 @section Selecting config files for user/host name completion
1499 @cindex customizing completion
1500 @cindex selecting config files
1501 @vindex tramp-completion-function-alist
1503 The variable @code{tramp-completion-function-alist} is intended to
1504 customize which files are taken into account for user and host name
1505 completion (@pxref{Filename completion}).  For every method, it keeps
1506 a set of configuration files, accompanied by a Lisp function able to
1507 parse that file.  Entries in @code{tramp-completion-function-alist}
1508 have the form (@var{method} @var{pair1} @var{pair2} ...).
1510 Each @var{pair} is composed of (@var{function} @var{file}).
1511 @var{function} is responsible to extract user names and host names
1512 from @var{file} for completion.  There are two functions which access
1513 this variable:
1515 @defun tramp-get-completion-function method
1516 This function returns the list of completion functions for @var{method}.
1518 Example:
1519 @example
1520 (tramp-get-completion-function "rsh")
1522      @result{} ((tramp-parse-rhosts "/etc/hosts.equiv")
1523          (tramp-parse-rhosts "~/.rhosts"))
1524 @end example
1525 @end defun
1527 @defun tramp-set-completion-function method function-list
1528 This function sets @var{function-list} as list of completion functions
1529 for @var{method}.
1531 Example:
1532 @example
1533 (tramp-set-completion-function "ssh"
1534  '((tramp-parse-sconfig "/etc/ssh_config")
1535    (tramp-parse-sconfig "~/.ssh/config")))
1537      @result{} ((tramp-parse-sconfig "/etc/ssh_config")
1538          (tramp-parse-sconfig "~/.ssh/config"))
1539 @end example
1540 @end defun
1542 The following predefined functions parsing configuration files exist:
1544 @table @asis
1545 @item @code{tramp-parse-rhosts}
1546 @findex tramp-parse-rhosts
1548 This function parses files which are syntactical equivalent to
1549 @file{~/.rhosts}.  It returns both host names and user names, if
1550 specified.
1552 @item @code{tramp-parse-shosts}
1553 @findex tramp-parse-shosts
1555 This function parses files which are syntactical equivalent to
1556 @file{~/.ssh/known_hosts}.  Since there are no user names specified
1557 in such files, it can return host names only.
1559 @item @code{tramp-parse-sconfig}
1560 @findex tramp-parse-shosts
1562 This function returns the host nicknames defined by @code{Host} entries
1563 in @file{~/.ssh/config} style files.
1565 @item @code{tramp-parse-shostkeys}
1566 @findex tramp-parse-shostkeys
1568 SSH2 parsing of directories @file{/etc/ssh2/hostkeys/*} and
1569 @file{~/ssh2/hostkeys/*}.  Hosts are coded in file names
1570 @file{hostkey_@var{portnumber}_@var{host-name}.pub}.  User names
1571 are always @code{nil}.
1573 @item @code{tramp-parse-sknownhosts}
1574 @findex tramp-parse-shostkeys
1576 Another SSH2 style parsing of directories like
1577 @file{/etc/ssh2/knownhosts/*} and @file{~/ssh2/knownhosts/*}.  This
1578 case, hosts names are coded in file names
1579 @file{@var{host-name}.@var{algorithm}.pub}.  User names are always @code{nil}.
1581 @item @code{tramp-parse-hosts}
1582 @findex tramp-parse-hosts
1584 A function dedicated to @file{/etc/hosts} style files.  It returns
1585 host names only.
1587 @item @code{tramp-parse-passwd}
1588 @findex tramp-parse-passwd
1590 A function which parses @file{/etc/passwd} like files.  Obviously, it
1591 can return user names only.
1593 @item @code{tramp-parse-netrc}
1594 @findex tramp-parse-netrc
1596 Finally, a function which parses @file{~/.netrc} like files.  This
1597 includes also @file{~/.authinfo}-style files.
1599 @end table
1601 If you want to keep your own data in a file, with your own structure,
1602 you might provide such a function as well.  This function must meet
1603 the following conventions:
1605 @defun my-tramp-parse file
1606 @var{file} must be either a file name on your host, or @code{nil}.
1607 The function must return a list of (@var{user} @var{host}), which are
1608 taken as candidates for user and host name completion.
1610 Example:
1611 @example
1612 (my-tramp-parse "~/.my-tramp-hosts")
1614      @result{} ((nil "toto") ("daniel" "melancholia"))
1615 @end example
1616 @end defun
1619 @node Password handling
1620 @section Reusing passwords for several connections
1621 @cindex passwords
1623 Sometimes it is necessary to connect to the same remote host several
1624 times.  Reentering passwords again and again would be annoying, when
1625 the chosen method does not support access without password prompt
1626 through own configuration.
1628 The best recommendation is to use the method's own mechanism for
1629 password handling. Consider @command{ssh-agent} for @option{ssh}-like
1630 methods, or @command{pageant} for @option{plink}-like methods.
1632 However, if you cannot apply such native password handling,
1633 @value{tramp} offers alternatives.
1636 @anchor{Using an authentication file}
1637 @subsection Using an authentication file
1639 @vindex auth-sources
1640 The package @file{auth-source.el}, originally developed in No Gnus,
1641 offers the possibility to read passwords from a file, like FTP does it
1642 from @file{~/.netrc}.  The default authentication file is
1643 @file{~/.authinfo.gpg}, this can be changed via the variable
1644 @code{auth-sources}.
1646 @noindent
1647 A typical entry in the authentication file would be
1649 @example
1650 machine melancholia port scp login daniel password geheim
1651 @end example
1653 The port can be any @value{tramp} method (@pxref{Inline methods},
1654 @pxref{External methods}), to match only this method.  When you omit
1655 the port, you match all @value{tramp} methods.
1657 In case of problems, setting @code{auth-source-debug} to @code{t}
1658 gives useful debug messages.
1661 @anchor{Caching passwords}
1662 @subsection Caching passwords
1664 If there is no authentication file, @value{tramp} caches the passwords
1665 entered by you.  They will be reused next time if a connection needs
1666 them for the same user name and host name, independently of the
1667 connection method.
1669 @vindex password-cache-expiry
1670 Passwords are not saved permanently, that means the password caching
1671 is limited to the lifetime of your @value{emacsname} session.  You
1672 can influence the lifetime of password caching by customizing the
1673 variable @code{password-cache-expiry}.  The value is the number of
1674 seconds how long passwords are cached.  Setting it to @code{nil}
1675 disables the expiration.
1677 @vindex password-cache
1678 If you don't like this feature for security reasons, password caching
1679 can be disabled totally by customizing the variable
1680 @code{password-cache} (setting it to @code{nil}).
1682 Implementation Note: password caching is based on the package
1683 @file{password-cache.el}.  For the time being, it is activated only
1684 when this package is seen in the @code{load-path} while loading
1685 @value{tramp}.
1686 @ifset installchapter
1687 If you don't use No Gnus, you can take @file{password.el} from the
1688 @value{tramp} @file{contrib} directory, see @ref{Installation
1689 parameters}.
1690 @end ifset
1693 @node Connection caching
1694 @section Reusing connection related information
1695 @cindex caching
1697 @vindex tramp-persistency-file-name
1698 In order to reduce initial connection time, @value{tramp} stores
1699 connection related information persistently.  The variable
1700 @code{tramp-persistency-file-name} keeps the file name where these
1701 information are written.  Its default value is
1702 @ifset emacs
1703 @file{~/.emacs.d/tramp}.
1704 @end ifset
1705 @ifset xemacs
1706 @file{~/.xemacs/tramp}.
1707 @end ifset
1708 It is recommended to choose a local file name.
1710 @value{tramp} reads this file during startup, and writes it when
1711 exiting @value{emacsname}.  You can simply remove this file if
1712 @value{tramp} shall be urged to recompute these information next
1713 @value{emacsname} startup time.
1715 Using such persistent information can be disabled by setting
1716 @code{tramp-persistency-file-name} to @code{nil}.
1718 Once consequence of reusing connection related information is that
1719 @var{tramp} needs to distinguish hosts.  If you, for example, run a
1720 local @code{sshd} on port 3001, which tunnels @command{ssh} to another
1721 host, you could access both @file{@trampfn{ssh, , localhost,}} and
1722 @file{@trampfn{ssh, , localhost#3001,}}.  @var{tramp} would use the
1723 same host related information (like paths, Perl variants, etc) for
1724 both connections, although the information is valid only for one of
1725 them.
1727 In order to avoid trouble, you must use another host name for one of
1728 the connections, like introducing a @option{Host} section in
1729 @file{~/.ssh/config} (@pxref{Frequently Asked Questions}) or applying
1730 multiple hops (@pxref{Multi-hops}).
1732 When @value{tramp} detects a changed operating system version on a
1733 remote host (via the command @command{uname -sr}), it flushes all
1734 connection related information for this host, and opens the
1735 connection again.
1738 @node Remote Programs
1739 @section How @value{tramp} finds and uses programs on the remote machine
1741 @value{tramp} depends on a number of programs on the remote host in order to
1742 function, including @command{ls}, @command{test}, @command{find} and
1743 @command{cat}.
1745 In addition to these required tools, there are various tools that may be
1746 required based on the connection method.  See @ref{Inline methods} and
1747 @ref{External methods} for details on these.
1749 Certain other tools, such as @command{perl} (or @command{perl5}) and
1750 @command{grep} will be used if they can be found.  When they are
1751 available, they are used to improve the performance and accuracy of
1752 remote file access.
1754 @vindex tramp-remote-path
1755 @vindex tramp-default-remote-path
1756 @vindex tramp-own-remote-path
1757 @defopt tramp-remote-path
1758 When @value{tramp} connects to the remote machine, it searches for the
1759 programs that it can use.  The variable @code{tramp-remote-path}
1760 controls the directories searched on the remote machine.
1762 By default, this is set to a reasonable set of defaults for most
1763 machines.  The symbol @code{tramp-default-remote-path} is a place
1764 holder, it is replaced by the list of directories received via the
1765 command @command{getconf PATH} on your remote machine.  For example,
1766 on Debian GNU/Linux this is @file{/bin:/usr/bin}, whereas on Solaris
1767 this is @file{/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin}.
1768 It is recommended to apply this symbol on top of
1769 @code{tramp-remote-path}.
1771 It is possible, however, that your local (or remote ;) system
1772 administrator has put the tools you want in some obscure local
1773 directory.
1775 In this case, you can still use them with @value{tramp}.  You simply
1776 need to add code to your @file{.emacs} to add the directory to the
1777 remote path.  This will then be searched by @value{tramp} when you
1778 connect and the software found.
1780 To add a directory to the remote search path, you could use code such
1783 @lisp
1784 @i{;; We load @value{tramp} to define the variable.}
1785 (require 'tramp)
1786 @i{;; We have @command{perl} in "/usr/local/perl/bin"}
1787 (add-to-list 'tramp-remote-path "/usr/local/perl/bin")
1788 @end lisp
1790 Another possibility is to reuse the path settings of your remote
1791 account when you log in.  Usually, these settings are overwritten,
1792 because they might not be useful for @value{tramp}.  The place holder
1793 @code{tramp-own-remote-path} preserves these settings.  You can
1794 activate it via
1796 @lisp
1797 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1798 @end lisp
1799 @end defopt
1801 @value{tramp} caches several information, like the Perl binary
1802 location.  The changed remote search path wouldn't affect these
1803 settings.  In order to force @value{tramp} to recompute these values,
1804 you must exit @value{emacsname}, remove your persistency file
1805 (@pxref{Connection caching}), and restart @value{emacsname}.
1808 @node Remote shell setup
1809 @section Remote shell setup hints
1810 @cindex remote shell setup
1811 @cindex @file{.profile} file
1812 @cindex @file{.login} file
1813 @cindex shell init files
1815 As explained in the @ref{Overview} section, @value{tramp} connects to the
1816 remote host and talks to the shell it finds there.  Of course, when you
1817 log in, the shell executes its init files.  Suppose your init file
1818 requires you to enter the birth date of your mother; clearly @value{tramp}
1819 does not know this and hence fails to log you in to that host.
1821 There are different possible strategies for pursuing this problem.  One
1822 strategy is to enable @value{tramp} to deal with all possible situations.
1823 This is a losing battle, since it is not possible to deal with
1824 @emph{all} situations.  The other strategy is to require you to set up
1825 the remote host such that it behaves like @value{tramp} expects.  This might
1826 be inconvenient because you have to invest a lot of effort into shell
1827 setup before you can begin to use @value{tramp}.
1829 The package, therefore, pursues a combined approach.  It tries to
1830 figure out some of the more common setups, and only requires you to
1831 avoid really exotic stuff.  For example, it looks through a list of
1832 directories to find some programs on the remote host.  And also, it
1833 knows that it is not obvious how to check whether a file exists, and
1834 therefore it tries different possibilities.  (On some hosts and
1835 shells, the command @command{test -e} does the trick, on some hosts
1836 the shell builtin doesn't work but the program @command{/usr/bin/test
1837 -e} or @command{/bin/test -e} works.  And on still other hosts,
1838 @command{ls -d} is the right way to do this.)
1840 Below you find a discussion of a few things that @value{tramp} does not deal
1841 with, and that you therefore have to set up correctly.
1843 @table @asis
1844 @item @var{shell-prompt-pattern}
1845 @vindex shell-prompt-pattern
1847 After logging in to the remote host, @value{tramp} has to wait for the remote
1848 shell startup to finish before it can send commands to the remote
1849 shell.  The strategy here is to wait for the shell prompt.  In order to
1850 recognize the shell prompt, the variable @code{shell-prompt-pattern} has
1851 to be set correctly to recognize the shell prompt on the remote host.
1853 Note that @value{tramp} requires the match for @code{shell-prompt-pattern}
1854 to be at the end of the buffer.  Many people have something like the
1855 following as the value for the variable: @code{"^[^>$][>$] *"}.  Now
1856 suppose your shell prompt is @code{a <b> c $ }.  In this case,
1857 @value{tramp} recognizes the @code{>} character as the end of the prompt,
1858 but it is not at the end of the buffer.
1860 @item @var{tramp-shell-prompt-pattern}
1861 @vindex tramp-shell-prompt-pattern
1863 This regular expression is used by @value{tramp} in the same way as
1864 @code{shell-prompt-pattern}, to match prompts from the remote shell.
1865 This second variable exists because the prompt from the remote shell
1866 might be different from the prompt from a local shell---after all,
1867 the whole point of @value{tramp} is to log in to remote hosts as a
1868 different user.  The default value of
1869 @code{tramp-shell-prompt-pattern} is the same as the default value of
1870 @code{shell-prompt-pattern}, which is reported to work well in many
1871 circumstances.
1873 @item @var{tramp-password-prompt-regexp}
1874 @vindex tramp-password-prompt-regexp
1875 @vindex tramp-wrong-passwd-regexp
1877 During login, @value{tramp} might be forced to enter a password or a
1878 passphrase.  The difference between both is that a password is
1879 requested from the shell on the remote host, while a passphrase is
1880 needed for accessing local authentication information, like your ssh
1881 key.
1883 @var{tramp-password-prompt-regexp} handles the detection of such
1884 requests for English environments.  When you use another localization
1885 of your (local or remote) host, you might need to adapt this. Example:
1887 @lisp
1888 (setq
1889   tramp-password-prompt-regexp
1890     (concat
1891       "^.*"
1892       (regexp-opt
1893         '("passphrase" "Passphrase"
1894           ;; English
1895           "password" "Password"
1896           ;; Deutsch
1897           "passwort" "Passwort"
1898           ;; Fran@,{c}ais
1899           "mot de passe" "Mot de passe") t)
1900       ".*:\0? *"))
1901 @end lisp
1903 In parallel, it might also be necessary to adapt
1904 @var{tramp-wrong-passwd-regexp}.
1906 @item @command{tset} and other questions
1907 @cindex Unix command tset
1908 @cindex tset Unix command
1910 Some people invoke the @command{tset} program from their shell startup
1911 scripts which asks the user about the terminal type of the shell.
1912 Maybe some shells ask other questions when they are started.
1913 @value{tramp} does not know how to answer these questions.  There are
1914 two approaches for dealing with this problem.  One approach is to take
1915 care that the shell does not ask any questions when invoked from
1916 @value{tramp}.  You can do this by checking the @env{TERM}
1917 environment variable, it will be set to @code{dumb} when connecting.
1919 @vindex tramp-terminal-type
1920 The variable @code{tramp-terminal-type} can be used to change this value
1921 to @code{dumb}.
1923 @vindex tramp-actions-before-shell
1924 The other approach is to teach @value{tramp} about these questions.  See
1925 the variable @code{tramp-actions-before-shell}.  Example:
1927 @lisp
1928 (defconst my-tramp-prompt-regexp
1929   (concat (regexp-opt '("Enter the birth date of your mother:") t)
1930           "\\s-*")
1931   "Regular expression matching my login prompt question.")
1933 (defun my-tramp-action (proc vec)
1934   "Enter \"19000101\" in order to give a correct answer."
1935   (save-window-excursion
1936     (with-current-buffer (tramp-get-connection-buffer vec)
1937       (tramp-message vec 6 "\n%s" (buffer-string))
1938       (tramp-send-string vec "19000101"))))
1940 (add-to-list 'tramp-actions-before-shell
1941              '(my-tramp-prompt-regexp my-tramp-action))
1942 @end lisp
1945 @item Environment variables named like users in @file{.profile}
1947 If you have a user named frumple and set the variable @env{FRUMPLE} in
1948 your shell environment, then this might cause trouble.  Maybe rename
1949 the variable to @env{FRUMPLE_DIR} or the like.
1951 This weird effect was actually reported by a @value{tramp} user!
1954 @item Non-Bourne commands in @file{.profile}
1956 After logging in to the remote host, @value{tramp} issues the command
1957 @command{exec /bin/sh}.  (Actually, the command is slightly
1958 different.)  When @command{/bin/sh} is executed, it reads some init
1959 files, such as @file{~/.shrc} or @file{~/.profile}.
1961 Now, some people have a login shell which is not @code{/bin/sh} but a
1962 Bourne-ish shell such as bash or ksh.  Some of these people might put
1963 their shell setup into the files @file{~/.shrc} or @file{~/.profile}.
1964 This way, it is possible for non-Bourne constructs to end up in those
1965 files.  Then, @command{exec /bin/sh} might cause the Bourne shell to
1966 barf on those constructs.
1968 As an example, imagine somebody putting @command{export FOO=bar} into
1969 the file @file{~/.profile}.  The standard Bourne shell does not
1970 understand this syntax and will emit a syntax error when it reaches
1971 this line.
1973 Another example is the tilde (@code{~}) character, say when adding
1974 @file{~/bin} to @env{PATH}.  Many Bourne shells will not expand this
1975 character, and since there is usually no directory whose name consists
1976 of the single character tilde, strange things will happen.
1978 What can you do about this?
1980 Well, one possibility is to make sure that everything in
1981 @file{~/.shrc} and @file{~/.profile} on all remote hosts is
1982 Bourne-compatible.  In the above example, instead of @command{export
1983 FOO=bar}, you might use @command{FOO=bar; export FOO} instead.
1985 The other possibility is to put your non-Bourne shell setup into some
1986 other files.  For example, bash reads the file @file{~/.bash_profile}
1987 instead of @file{~/.profile}, if the former exists.  So bash
1988 aficionados just rename their @file{~/.profile} to
1989 @file{~/.bash_profile} on all remote hosts, and Bob's your uncle.
1991 The @value{tramp} developers would like to circumvent this problem, so
1992 if you have an idea about it, please tell us.  However, we are afraid
1993 it is not that simple: before saying @command{exec /bin/sh},
1994 @value{tramp} does not know which kind of shell it might be talking
1995 to.  It could be a Bourne-ish shell like ksh or bash, or it could be a
1996 csh derivative like tcsh, or it could be zsh, or even rc.  If the
1997 shell is Bourne-ish already, then it might be prudent to omit the
1998 @command{exec /bin/sh} step.  But how to find out if the shell is
1999 Bourne-ish?
2002 @item Interactive shell prompt
2004 @value{tramp} redefines the shell prompt in order to parse the shell's
2005 output robustly.  When calling an interactive shell by @kbd{M-x
2006 shell}, this doesn't look nice.
2008 You can redefine the shell prompt by checking the environment variable
2009 @env{INSIDE_EMACS}, which is set by @value{tramp}, in your startup
2010 script @file{~/.emacs_SHELLNAME}. @env{SHELLNAME} might be the string
2011 @code{bash} or similar, in case of doubt you could set it the
2012 environment variable @env{ESHELL} in your @file{.emacs}:
2014 @lisp
2015 (setenv "ESHELL" "bash")
2016 @end lisp
2018 Your file @file{~/.emacs_SHELLNAME} could contain code like
2020 @example
2021 # Reset the prompt for remote Tramp shells.
2022 if [ "$@{INSIDE_EMACS/*tramp*/tramp@}" == "tramp" ] ; then
2023    PS1="[\u@@\h \w]$ "
2025 @end example
2027 @ifinfo
2028 @ifset emacs
2029 @xref{Interactive Shell, , , @value{emacsdir}}.
2030 @end ifset
2031 @end ifinfo
2033 @end table
2036 @node Android shell setup
2037 @section Android shell setup hints
2038 @cindex android shell setup
2040 Android devices use a restricted shell.  They can be accessed via the
2041 @option{adb} method.  However, this restricts the access to a USB
2042 connection, and it requires the installation of the Android SDK on the
2043 local machine.
2045 When an @command{sshd} process runs on the Android device, like
2046 provided by the @code{SSHDroid} app, any @option{ssh}-based method can
2047 be used.  This requires some special settings.
2049 The default shell @code{/bin/sh} does not exist.  Instead, you shall
2050 use just @code{sh}, which invokes the shell installed on the device.
2051 You can instruct @value{tramp} by this form:
2053 @lisp
2054 (add-to-list 'tramp-connection-properties
2055              (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))
2056 @end lisp
2058 @noindent
2059 with @samp{192.168.0.26} being the IP address of your Android device.
2061 The user settings for the @code{$PATH} environment variable must be
2062 preserved.  It has also been reported, that the commands in
2063 @file{/system/xbin} are better suited than the ones in
2064 @file{/system/bin}.  Add these setting:
2066 @lisp
2067 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
2068 (add-to-list 'tramp-remote-path "/system/xbin")
2069 @end lisp
2071 @noindent
2072 If the Android device is not @samp{rooted}, you must give the shell a
2073 writable directory for temporary files:
2075 @lisp
2076 (add-to-list 'tramp-remote-process-environment "TMPDIR=$HOME")
2077 @end lisp
2079 @noindent
2080 Now you shall be able to open a remote connection with @kbd{C-x C-f
2081 @trampfn{ssh, , 192.168.0.26#2222, }}, given that @command{sshd}
2082 listens on port @samp{2222}.
2084 It is also recommended to add a corresponding entry to your
2085 @file{~/.ssh/config} for that connection, like
2087 @example
2088 Host android
2089      HostName 192.168.0.26
2090      User root
2091      Port 2222
2092 @end example
2094 @noindent
2095 In this case, you must change the setting for the remote shell to
2097 @lisp
2098 (add-to-list 'tramp-connection-properties
2099              (list (regexp-quote "android") "remote-shell" "sh"))
2100 @end lisp
2102 @noindent
2103 You would open the connection with @kbd{C-x C-f @trampfn{ssh, ,
2104 android, }} then.
2107 @node Auto-save and Backup
2108 @section Auto-save and Backup configuration
2109 @cindex auto-save
2110 @cindex backup
2111 @ifset emacs
2112 @vindex backup-directory-alist
2113 @end ifset
2114 @ifset xemacs
2115 @vindex bkup-backup-directory-info
2116 @end ifset
2118 Normally, @value{emacsname} writes backup files to the same directory
2119 as the original files, but this behavior can be changed via the
2120 variable
2121 @ifset emacs
2122 @code{backup-directory-alist}.
2123 @end ifset
2124 @ifset xemacs
2125 @code{bkup-backup-directory-info}.
2126 @end ifset
2127 In connection with @value{tramp}, this can have unexpected side
2128 effects.  Suppose that you specify that all backups should go to the
2129 directory @file{~/.emacs.d/backups/}, and then you edit the file
2130 @file{@trampfn{su, root, localhost, /etc/secretfile}}.  The effect is
2131 that the backup file will be owned by you and not by root, thus
2132 possibly enabling others to see it even if they were not intended to
2133 see it.
2135 When
2136 @ifset emacs
2137 @code{backup-directory-alist}
2138 @end ifset
2139 @ifset xemacs
2140 @code{bkup-backup-directory-info}
2141 @end ifset
2142 is @code{nil} (the default), such problems do not occur.
2144 Therefore, it is useful to set special values for @value{tramp}
2145 files.  For example, the following statement effectively `turns off'
2146 the effect of
2147 @ifset emacs
2148 @code{backup-directory-alist}
2149 @end ifset
2150 @ifset xemacs
2151 @code{bkup-backup-directory-info}
2152 @end ifset
2153 for @value{tramp} files:
2155 @ifset emacs
2156 @lisp
2157 (add-to-list 'backup-directory-alist
2158              (cons tramp-file-name-regexp nil))
2159 @end lisp
2160 @end ifset
2161 @ifset xemacs
2162 @lisp
2163 (require 'backup-dir)
2164 (add-to-list 'bkup-backup-directory-info
2165              (list tramp-file-name-regexp ""))
2166 @end lisp
2167 @end ifset
2169 @ifset emacs
2170 It is also possible to disable backups depending on the used method.
2171 The following code disables backups for the @option{su} and
2172 @option{sudo} methods:
2174 @lisp
2175 (setq backup-enable-predicate
2176       (lambda (name)
2177         (and (normal-backup-enable-predicate name)
2178              (not
2179               (let ((method (file-remote-p name 'method)))
2180                 (when (stringp method)
2181                   (member method '("su" "sudo"))))))))
2182 @end lisp
2183 @end ifset
2186 Another possibility is to use the @value{tramp} variable
2187 @ifset emacs
2188 @code{tramp-backup-directory-alist}.
2189 @end ifset
2190 @ifset xemacs
2191 @code{tramp-bkup-backup-directory-info}.
2192 @end ifset
2193 This variable has the same meaning like
2194 @ifset emacs
2195 @code{backup-directory-alist}.
2196 @end ifset
2197 @ifset xemacs
2198 @code{bkup-backup-directory-info}.
2199 @end ifset
2200 If a @value{tramp} file is backed up, and DIRECTORY is an absolute
2201 local file name, DIRECTORY is prepended with the @value{tramp} file
2202 name prefix of the file to be backed up.
2204 @noindent
2205 Example:
2207 @ifset emacs
2208 @lisp
2209 (add-to-list 'backup-directory-alist
2210              (cons "." "~/.emacs.d/backups/"))
2211 (setq tramp-backup-directory-alist backup-directory-alist)
2212 @end lisp
2213 @end ifset
2214 @ifset xemacs
2215 @lisp
2216 (require 'backup-dir)
2217 (add-to-list 'bkup-backup-directory-info
2218              (list "." "~/.emacs.d/backups/" 'full-path))
2219 (setq tramp-bkup-backup-directory-info bkup-backup-directory-info)
2220 @end lisp
2221 @end ifset
2223 @noindent
2224 The backup file name of @file{@trampfn{su, root, localhost,
2225 /etc/secretfile}} would be
2226 @ifset emacs
2227 @file{@trampfn{su, root, localhost,
2228 ~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile~}}
2229 @end ifset
2230 @ifset xemacs
2231 @file{@trampfn{su, root, localhost,
2232 ~/.emacs.d/backups/![su!root@@localhost]!etc!secretfile~}}
2233 @end ifset
2235 The same problem can happen with auto-saving files.
2236 @ifset emacs
2237 The variable @code{auto-save-file-name-transforms} keeps information,
2238 on which directory an auto-saved file should go.  By default, it is
2239 initialized for @value{tramp} files to the local temporary directory.
2241 On some versions of @value{emacsname}, namely the version built for
2242 Debian GNU/Linux, the variable @code{auto-save-file-name-transforms}
2243 contains the directory where @value{emacsname} was built.  A
2244 workaround is to manually set the variable to a sane value.
2246 If auto-saved files should go into the same directory as the original
2247 files, @code{auto-save-file-name-transforms} should be set to @code{nil}.
2249 Another possibility is to set the variable
2250 @code{tramp-auto-save-directory} to a proper value.
2251 @end ifset
2252 @ifset xemacs
2253 For this purpose you can set the variable @code{auto-save-directory}
2254 to a proper value.
2255 @end ifset
2258 @node Windows setup hints
2259 @section Issues with Cygwin ssh
2260 @cindex Cygwin, issues
2262 This section needs a lot of work!  Please help.
2264 @cindex method sshx with Cygwin
2265 @cindex sshx method with Cygwin
2266 The recent Cygwin installation of @command{ssh} works only with a
2267 Cygwinized @value{emacsname}.  You can check it by typing @kbd{M-x
2268 eshell}, and starting @kbd{ssh test.machine}.  The problem is evident
2269 if you see a message like this:
2271 @example
2272 Pseudo-terminal will not be allocated because stdin is not a terminal.
2273 @end example
2275 Older @command{ssh} versions of Cygwin are told to cooperate with
2276 @value{tramp} selecting @option{sshx} as the connection method.  You
2277 can find information about setting up Cygwin in their FAQ at
2278 @uref{http://cygwin.com/faq/}.
2280 @cindex method scpx with Cygwin
2281 @cindex scpx method with Cygwin
2282 If you wish to use the @option{scpx} connection method, then you might
2283 have the problem that @value{emacsname} calls @command{scp} with a
2284 Windows filename such as @code{c:/foo}.  The Cygwin version of
2285 @command{scp} does not know about Windows filenames and interprets
2286 this as a remote filename on the host @code{c}.
2288 One possible workaround is to write a wrapper script for @option{scp}
2289 which converts the Windows filename to a Cygwinized filename.
2291 @cindex Cygwin and ssh-agent
2292 @cindex SSH_AUTH_SOCK and @value{emacsname} on Windows
2293 If you want to use either @option{ssh} based method on Windows, then
2294 you might encounter problems with @command{ssh-agent}.  Using this
2295 program, you can avoid typing the pass-phrase every time you log in.
2296 However, if you start @value{emacsname} from a desktop shortcut, then
2297 the environment variable @env{SSH_AUTH_SOCK} is not set and so
2298 @value{emacsname} and thus @value{tramp} and thus @command{ssh} and
2299 @command{scp} started from @value{tramp} cannot communicate with
2300 @command{ssh-agent}.  It works better to start @value{emacsname} from
2301 the shell.
2303 If anyone knows how to start @command{ssh-agent} under Windows in such a
2304 way that desktop shortcuts can profit, please holler.  I don't really
2305 know anything at all about Windows@dots{}
2308 @node Usage
2309 @chapter Using @value{tramp}
2310 @cindex using @value{tramp}
2312 Once you have installed @value{tramp} it will operate fairly
2313 transparently.  You will be able to access files on any remote machine
2314 that you can log in to as though they were local.
2316 Files are specified to @value{tramp} using a formalized syntax specifying the
2317 details of the system to connect to.  This is similar to the syntax used
2318 by the @value{ftppackagename} package.
2320 @cindex type-ahead
2321 Something that might happen which surprises you is that
2322 @value{emacsname} remembers all your keystrokes, so if you see a
2323 password prompt from @value{emacsname}, say, and hit @kbd{@key{RET}}
2324 twice instead of once, then the second keystroke will be processed by
2325 @value{emacsname} after @value{tramp} has done its thing.  Why, this
2326 type-ahead is normal behavior, you say.  Right you are, but be aware
2327 that opening a remote file might take quite a while, maybe half a
2328 minute when a connection needs to be opened.  Maybe after half a
2329 minute you have already forgotten that you hit that key!
2331 @menu
2332 * Filename Syntax::             @value{tramp} filename conventions.
2333 * Alternative Syntax::          URL-like filename syntax.
2334 * Filename completion::         Filename completion.
2335 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
2336 * Remote processes::            Integration with other @value{emacsname} packages.
2337 * Cleanup remote connections::  Cleanup remote connections.
2338 @end menu
2341 @node Filename Syntax
2342 @section @value{tramp} filename conventions
2343 @cindex filename syntax
2344 @cindex filename examples
2346 To access the file @var{localname} on the remote machine @var{machine}
2347 you would specify the filename @file{@trampfn{, , machine,
2348 localname}}.  This will connect to @var{machine} and transfer the file
2349 using the default method.  @xref{Default Method}.
2351 Some examples of @value{tramp} filenames are shown below.
2353 @table @file
2354 @item @value{prefix}melancholia@value{postfix}.emacs
2355 Edit the file @file{.emacs} in your home directory on the machine
2356 @code{melancholia}.
2358 @item @value{prefix}melancholia.danann.net@value{postfix}.emacs
2359 This edits the same file, using the fully qualified domain name of
2360 the machine.
2362 @item @value{prefix}melancholia@value{postfix}~/.emacs
2363 This also edits the same file; the @file{~} is expanded to your
2364 home directory on the remote machine, just like it is locally.
2366 @item @value{prefix}melancholia@value{postfix}~daniel/.emacs
2367 This edits the file @file{.emacs} in the home directory of the user
2368 @code{daniel} on the machine @code{melancholia}.  The @file{~<user>}
2369 construct is expanded to the home directory of that user on the remote
2370 machine.
2372 @item @value{prefix}melancholia@value{postfix}/etc/squid.conf
2373 This edits the file @file{/etc/squid.conf} on the machine
2374 @code{melancholia}.
2376 @end table
2378 @var{machine} can also be an IPv4 or IPv6 address, like in
2379 @file{@trampfn{, , 127.0.0.1, .emacs}} or @file{@trampfn{, ,
2380 @value{ipv6prefix}::1@value{ipv6postfix}, .emacs}}.
2381 @ifset emacs
2382 For syntactical reasons, IPv6 addresses must be embedded in square
2383 brackets @file{@value{ipv6prefix}} and @file{@value{ipv6postfix}}.
2384 @end ifset
2386 Unless you specify a different name to use, @value{tramp} will use the
2387 current local user name as the remote user name to log in with.  If you
2388 need to log in as a different user, you can specify the user name as
2389 part of the filename.
2391 To log in to the remote machine as a specific user, you use the syntax
2392 @file{@trampfn{, user, machine, path/to.file}}.  That means that
2393 connecting to @code{melancholia} as @code{daniel} and editing
2394 @file{.emacs} in your home directory you would specify
2395 @file{@trampfn{, daniel, melancholia, .emacs}}.
2397 It is also possible to specify other file transfer methods
2398 (@pxref{Inline methods}, @pxref{External methods}) as part of the
2399 filename.
2400 @ifset emacs
2401 This is done by putting the method before the user and host name, as
2402 in @file{@value{prefix}@var{method}@value{postfixhop}} (Note the
2403 trailing colon).
2404 @end ifset
2405 @ifset xemacs
2406 This is done by replacing the initial @file{@value{prefix}} with
2407 @file{@value{prefix}<method>@value{postfixhop}}.  (Note the trailing
2408 slash!).
2409 @end ifset
2410 The user, machine and file specification remain the same.
2412 So, to connect to the machine @code{melancholia} as @code{daniel},
2413 using the @option{ssh} method to transfer files, and edit
2414 @file{.emacs} in my home directory I would specify the filename
2415 @file{@trampfn{ssh, daniel, melancholia, .emacs}}.
2417 Finally, for some methods it is possible to specify a different port
2418 number than the default one, given by the method.  This is specified
2419 by adding @file{#<port>} to the host name, like in @file{@trampfn{ssh,
2420 daniel, melancholia#42, .emacs}}.
2422 Note that @value{tramp} supports only filenames encoded in unibyte.
2425 @node Alternative Syntax
2426 @section URL-like filename syntax
2427 @cindex filename syntax
2428 @cindex filename examples
2430 Additionally to the syntax described in the previous chapter, it is
2431 possible to use a URL-like syntax for @value{tramp}.  This can be
2432 switched on by customizing the variable @code{tramp-syntax}.  Please
2433 note that this feature is experimental for the time being.
2435 The variable @code{tramp-syntax} must be set before requiring @value{tramp}:
2437 @lisp
2438 (setq tramp-syntax 'url)
2439 (require 'tramp)
2440 @end lisp
2442 Then, a @value{tramp} filename would look like this:
2443 @file{/@var{method}://@var{user}@@@var{machine}:@var{port}/@var{path/to.file}}.
2444 @file{/@var{method}://} is mandatory, all other parts are optional.
2445 @file{:@var{port}} is useful for methods only who support this.
2447 The last example from the previous section would look like this:
2448 @file{/ssh://daniel@@melancholia/.emacs}.
2450 For the time being, @code{tramp-syntax} can have the following values:
2452 @itemize @w{}
2453 @ifset emacs
2454 @item @code{ftp}---That is the default syntax
2455 @item @code{url}---URL-like syntax
2456 @end ifset
2457 @ifset xemacs
2458 @item @code{sep}---That is the default syntax
2459 @item @code{url}---URL-like syntax
2460 @item @code{ftp}---EFS-like syntax
2461 @end ifset
2462 @end itemize
2465 @node Filename completion
2466 @section Filename completion
2467 @cindex filename completion
2469 Filename completion works with @value{tramp} for completion of method
2470 names, of user names and of machine names as well as for completion of
2471 file names on remote machines.
2472 @ifset emacs
2473 In order to enable this, partial completion must be activated in your
2474 @file{.emacs}.
2475 @ifinfo
2476 @xref{Completion Options, , , @value{emacsdir}}.
2477 @end ifinfo
2478 @end ifset
2480 If you, for example, type @kbd{C-x C-f @value{prefix}t
2481 @key{TAB}}, @value{tramp} might give you as result the choice for
2483 @example
2484 @c @multitable {@trampfn{telnet, , melancholia.danann.net,}} {@trampfn{telnet, , 192.168.0.1,}}
2485 @multitable @columnfractions .5 .5
2486 @ifset emacs
2487 @item @value{prefixhop}telnet@value{postfixhop} @tab tmp/
2488 @item @value{prefixhop}toto@value{postfix} @tab
2489 @end ifset
2490 @ifset xemacs
2491 @item @value{prefixhop}telnet@value{postfixhop} @tab @value{prefixhop}toto@value{postfix}
2492 @end ifset
2493 @end multitable
2494 @end example
2496 @samp{@value{prefixhop}telnet@value{postfixhop}}
2497 is a possible completion for the respective method,
2498 @ifset emacs
2499 @samp{tmp/} stands for the directory @file{/tmp} on your local
2500 machine,
2501 @end ifset
2502 and @samp{@value{prefixhop}toto@value{postfix}}
2503 might be a host @value{tramp} has detected in your @file{~/.ssh/known_hosts}
2504 file (given you're using default method @option{ssh}).
2506 If you go on to type @kbd{e @key{TAB}}, the minibuffer is completed to
2507 @samp{@value{prefix}telnet@value{postfixhop}}.
2508 Next @kbd{@key{TAB}} brings you all machine names @value{tramp} detects in
2509 your @file{/etc/hosts} file, let's say
2511 @example
2512 @multitable @columnfractions .5 .5
2513 @c @multitable {@trampfn{telnet, , melancholia.danann.net,}} {@trampfn{telnet, , 192.168.0.1,}}
2514 @item @trampfn{telnet, , 127.0.0.1,} @tab @trampfn{telnet, , 192.168.0.1,}
2515 @item @trampfn{telnet, , @value{ipv6prefix}::1@value{ipv6postfix},} @tab @trampfn{telnet, , localhost,}
2516 @item @trampfn{telnet, , melancholia.danann.net,} @tab @trampfn{telnet, , melancholia,}
2517 @end multitable
2518 @end example
2520 Now you can choose the desired machine, and you can continue to
2521 complete file names on that machine.
2523 If the configuration files (@pxref{Customizing Completion}), which
2524 @value{tramp} uses for analysis of completion, offer user names, those user
2525 names will be taken into account as well.
2527 Remote machines which have been visited in the past and kept
2528 persistently (@pxref{Connection caching}) will be offered too.
2530 Once the remote machine identification is completed, it comes to
2531 filename completion on the remote host.  This works pretty much like
2532 for files on the local host, with the exception that minibuffer
2533 killing via a double-slash works only on the filename part, except
2534 that filename part starts with @file{//}.
2535 @ifset emacs
2536 A triple-slash stands for the default behavior.
2537 @end ifset
2538 @ifinfo
2539 @xref{Minibuffer File, , , @value{emacsdir}}.
2540 @end ifinfo
2542 @noindent
2543 Example:
2545 @example
2546 @ifset emacs
2547 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin//etc} @key{TAB}}
2548      @print{} @trampfn{telnet, , melancholia, /etc}
2550 @kbd{C-x C-f @trampfn{telnet, , melancholia, //etc} @key{TAB}}
2551      @print{} /etc
2553 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin///etc} @key{TAB}}
2554      @print{} /etc
2555 @end ifset
2557 @ifset xemacs
2558 @kbd{C-x C-f @trampfn{telnet, , melancholia, /usr/local/bin//}}
2559      @print{} @trampfn{telnet, , melancholia, /}
2561 @kbd{C-x C-f @trampfn{telnet, , melancholia, //}}
2562      @print{} /
2563 @end ifset
2564 @end example
2566 A remote directory might have changed its contents out of
2567 @value{emacsname} control, for example by creation or deletion of
2568 files by other processes.  Therefore, during filename completion, the
2569 remote directory contents are reread regularly in order to detect such
2570 changes, which would be invisible otherwise (@pxref{Connection caching}).
2572 @defopt tramp-completion-reread-directory-timeout
2573 This variable defines the number of seconds since last remote command
2574 before rereading a directory contents.  A value of 0 would require an
2575 immediate reread during filename completion, @code{nil} means to use
2576 always cached values for the directory contents.
2577 @end defopt
2580 @node Ad-hoc multi-hops
2581 @section Declaring multiple hops in the file name
2582 @cindex multi-hop, ad-hoc
2583 @cindex proxy hosts, ad-hoc
2585 Multiple hops are configured with the variable
2586 @code{tramp-default-proxies-alist} (@pxref{Multi-hops}).  However,
2587 sometimes it is desirable to reach a remote host immediately, without
2588 configuration changes.  This can be reached by an ad-hoc specification
2589 of the proxies.
2591 A proxy looks like a remote file name specification without the local
2592 file name part.  It is prepended to the target remote file name,
2593 separated by @samp{|}.  As an example, a remote file on
2594 @samp{you@@remotehost}, passing the proxy @samp{bird@@bastion}, could
2595 be opened by
2597 @example
2598 @c @kbd{C-x C-f @trampfn{ssh@value{postfixhop}bird@@bastion|ssh, you,
2599 @c remotehost, /path}}
2600 @kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path}
2601 @end example
2603 Multiple hops can be cascaded, separating all proxies by @samp{|}.
2604 The proxies can also contain the patterns @code{%h} or @code{%u}.
2606 The ad-hoc definition is added on the fly to
2607 @code{tramp-default-proxies-alist}.  Therefore, during the lifetime of
2608 the @value{emacsname} session it is not necessary to enter this ad-hoc
2609 specification, again.  The remote file name @samp{@trampfn{ssh, you,
2610 remotehost, /path}} would be sufficient from now on.
2612 @vindex tramp-save-ad-hoc-proxies
2613 @defopt tramp-save-ad-hoc-proxies
2614 This customer option controls whether ad-hoc definitions are kept
2615 persistently in @code{tramp-default-proxies-alist}.  That means, those
2616 definitions are available also for future @value{emacsname} sessions.
2617 @end defopt
2620 @node Remote processes
2621 @section Integration with other @value{emacsname} packages
2622 @cindex compile
2623 @cindex recompile
2625 @value{tramp} supports running processes on a remote host.  This
2626 allows to exploit @value{emacsname} packages without modification for
2627 remote file names.  It does not work for the @option{ftp} method.
2628 Association of a pty, as specified in @code{start-file-process}, is
2629 not supported.
2631 @code{process-file} and @code{start-file-process} work on the remote
2632 host when the variable @code{default-directory} is remote:
2634 @lisp
2635 (let ((default-directory "/ssh:remote.host:"))
2636   (start-file-process "grep" (get-buffer-create "*grep*")
2637                       "/bin/sh" "-c" "grep -e tramp *"))
2638 @end lisp
2640 @ifset emacsgvfs
2641 If the remote host is mounted via GVFS (see @ref{GVFS based methods}),
2642 the remote filesystem is mounted locally.  Therefore, there are no
2643 remote processes; all processes run still locally on your machine with
2644 an adapted @code{default-directory}.  This section does not apply for
2645 such connection methods.
2646 @end ifset
2648 Remote processes are started when a corresponding command is executed
2649 from a buffer belonging to a remote file or directory.  Up to now, the
2650 packages @file{compile.el} (commands like @code{compile} and
2651 @code{grep}) and @file{gud.el} (@code{gdb} or @code{perldb}) have been
2652 integrated.  Integration of further packages is planned, any help for
2653 this is welcome!
2655 When your program is not found in the default search path
2656 @value{tramp} sets on the remote machine, you should either use an
2657 absolute path, or extend @code{tramp-remote-path} (see @ref{Remote
2658 Programs}):
2660 @lisp
2661 (add-to-list 'tramp-remote-path "~/bin")
2662 (add-to-list 'tramp-remote-path "/appli/pub/bin")
2663 @end lisp
2665 The environment for your program can be adapted by customizing
2666 @code{tramp-remote-process-environment}.  This variable is a list of
2667 strings.  It is structured like @code{process-environment}.  Each
2668 element is a string of the form @code{"ENVVARNAME=VALUE"}.  An entry
2669 @code{"ENVVARNAME="} disables the corresponding environment variable,
2670 which might have been set in your init file like @file{~/.profile}.
2672 @noindent
2673 Adding an entry can be performed via @code{add-to-list}:
2675 @lisp
2676 (add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java")
2677 @end lisp
2679 Changing or removing an existing entry is not encouraged.  The default
2680 values are chosen for proper @value{tramp} work.  Nevertheless, if for
2681 example a paranoid system administrator disallows changing the
2682 @env{HISTORY} environment variable, you can customize
2683 @code{tramp-remote-process-environment}, or you can apply the
2684 following code in your @file{.emacs}:
2686 @lisp
2687 (let ((process-environment tramp-remote-process-environment))
2688   (setenv "HISTORY" nil)
2689   (setq tramp-remote-process-environment process-environment))
2690 @end lisp
2692 If you use other @value{emacsname} packages which do not run
2693 out-of-the-box on a remote host, please let us know.  We will try to
2694 integrate them as well.  @xref{Bug Reports}.
2697 @subsection Running remote programs that create local X11 windows
2699 If you want to run a remote program, which shall connect the X11
2700 server you are using with your local host, you can set the
2701 @env{DISPLAY} environment variable on the remote host:
2703 @lisp
2704 (add-to-list 'tramp-remote-process-environment
2705              (format "DISPLAY=%s" (getenv "DISPLAY")))
2706 @end lisp
2708 @noindent
2709 @code{(getenv "DISPLAY")} shall return a string containing a host
2710 name, which can be interpreted on the remote host; otherwise you might
2711 use a fixed host name.  Strings like @code{:0} cannot be used properly
2712 on the remote host.
2714 Another trick might be that you put @code{ForwardX11 yes} or
2715 @code{ForwardX11Trusted yes} to your @file{~/.ssh/config} file for
2716 that host.
2719 @subsection Running @code{shell} on a remote host
2720 @cindex shell
2722 Calling @kbd{M-x shell} in a buffer related to a remote host runs the
2723 local shell as defined in @option{shell-file-name}.  This might be
2724 also a valid path name for a shell to be applied on the remote host,
2725 but it will fail at least when your local and remote hosts belong to
2726 different system types, like @samp{windows-nt} and @samp{gnu/linux}.
2728 You must set the variable @option{explicit-shell-file-name} to the
2729 shell path name on the remote host, in order to start that shell on
2730 the remote host.
2732 @ifset emacs
2733 Starting with Emacs 24 this won't be necessary, if you call
2734 @code{shell} interactively.  You will be asked for the remote shell
2735 path, if you are on a remote buffer, and if
2736 @option{explicit-shell-file-name} is equal to @code{nil}.
2737 @end ifset
2740 @subsection Running @code{shell-command} on a remote host
2741 @cindex shell-command
2743 @code{shell-command} allows to execute commands in a shell, either
2744 synchronously, either asynchronously.  This works also on remote
2745 hosts.  Example:
2747 @example
2748 @kbd{C-x C-f @trampfn{sudo, , , } @key{RET}}
2749 @kbd{M-! tail -f /var/log/syslog.log & @key{RET}}
2750 @end example
2752 You will see the buffer @file{*Async Shell Command*}, containing the
2753 continuous output of the @command{tail} command.
2755 @ifset emacs
2756 A similar behaviour can be reached by @kbd{M-x auto-revert-tail-mode},
2757 if available.
2758 @end ifset
2761 @subsection Running @code{eshell} on a remote host
2762 @cindex eshell
2764 @value{tramp} is integrated into @file{eshell.el}.  That is, you can
2765 open an interactive shell on your remote host, and run commands there.
2766 After you have started @kbd{M-x eshell}, you could perform commands
2767 like this:
2769 @example
2770 @b{~ $} cd @trampfn{sudo, , , /etc} @key{RET}
2771 @b{@trampfn{sudo, root, host, /etc} $} hostname @key{RET}
2772 host
2773 @b{@trampfn{sudo, root, host, /etc} $} id @key{RET}
2774 uid=0(root) gid=0(root) groups=0(root)
2775 @b{@trampfn{sudo, root, host, /etc} $} find-file shadow @key{RET}
2776 #<buffer shadow>
2777 @b{@trampfn{sudo, root, host, /etc} $}
2778 @end example
2780 @ifset emacs
2781 Since @value{emacsname} 23.2, @code{eshell} has also an own
2782 implementation of the @code{su} and @code{sudo} commands.  Both
2783 commands change the default directory of the @file{*eshell*} buffer to
2784 the value related to the user the command has switched to.  This works
2785 even on remote hosts, adding silently a corresponding entry to the
2786 variable @code{tramp-default-proxies-alist} (@pxref{Multi-hops}):
2788 @example
2789 @b{~ $} cd @trampfn{ssh, user, remotehost, /etc} @key{RET}
2790 @b{@trampfn{ssh, user, remotehost, /etc} $} find-file shadow @key{RET}
2791 File is not readable: @trampfn{ssh, user, remotehost, /etc/shadow}
2792 @b{@trampfn{ssh, user, remotehost, /etc} $} sudo find-file shadow @key{RET}
2793 #<buffer shadow>
2795 @b{@trampfn{ssh, user, remotehost, /etc} $} su - @key{RET}
2796 @b{@trampfn{su, root, remotehost, /root} $} id @key{RET}
2797 uid=0(root) gid=0(root) groups=0(root)
2798 @b{@trampfn{su, root, remotehost, /root} $}
2799 @end example
2800 @end ifset
2803 @anchor{Running a debugger on a remote host}
2804 @subsection Running a debugger on a remote host
2805 @cindex gud
2806 @cindex gdb
2807 @cindex perldb
2809 @file{gud.el} offers an unified interface to several symbolic
2810 debuggers
2811 @ifset emacs
2812 @ifinfo
2813 (@ref{Debuggers, , , @value{emacsdir}}).
2814 @end ifinfo
2815 @end ifset
2816 With @value{tramp}, it is possible to debug programs on
2817 remote hosts.  You can call @code{gdb} with a remote file name:
2819 @example
2820 @kbd{M-x gdb @key{RET}}
2821 @b{Run gdb (like this):} gdb --annotate=3 @trampfn{ssh, , host, ~/myprog} @key{RET}
2822 @end example
2824 The file name can also be relative to a remote default directory.
2825 Given you are in a buffer that belongs to the remote directory
2826 @trampfn{ssh, , host, /home/user}, you could call
2828 @example
2829 @kbd{M-x perldb @key{RET}}
2830 @b{Run perldb (like this):} perl -d myprog.pl @key{RET}
2831 @end example
2833 It is not possible to use just the absolute local part of a remote
2834 file name as program to debug, like @kbd{perl -d
2835 /home/user/myprog.pl}, though.
2837 Arguments of the program to be debugged are taken literally.  That
2838 means, file names as arguments must be given as ordinary relative or
2839 absolute file names, without any remote specification.
2842 @subsection Running remote processes on Windows hosts
2843 @cindex winexe
2844 @cindex powershell
2846 With the help of the @command{winexe} it is possible tu run processes
2847 on a remote Windows host.  @value{tramp} has implemented this for
2848 @code{process-file} and @code{start-file-process}.
2850 The variable @code{tramp-smb-winexe-program} must contain the file
2851 name of your local @command{winexe} command.  On the remote host,
2852 Powershell V2.0 must be installed; it is used to run the remote
2853 process.
2855 In order to open a remote shell on the Windows host via @kbd{M-x
2856 shell}, you must set the variables @option{explicit-shell-file-name}
2857 and @option{explicit-*-args}.  If you want, for example, run
2858 @command{cmd}, you must set:
2860 @lisp
2861 (setq explicit-shell-file-name "cmd"
2862       explicit-cmd-args '("/q"))
2863 @end lisp
2865 @noindent
2866 In case of running @command{powershell} as remote shell, the settings are
2868 @lisp
2869 (setq explicit-shell-file-name "powershell"
2870       explicit-powershell-args '("-file" "-"))
2871 @end lisp
2874 @node Cleanup remote connections
2875 @section Cleanup remote connections
2876 @cindex cleanup
2878 Sometimes it is useful to cleanup remote connections.  The following
2879 commands support this.
2881 @deffn Command tramp-cleanup-connection vec
2882 This command flushes all connection related objects.  @option{vec} is
2883 the internal representation of a remote connection.  Called
2884 interactively, the command offers all active remote connections in the
2885 minibuffer as remote file name prefix like @file{@trampfn{method,
2886 user, host, }}.  The cleanup includes password cache (@pxref{Password
2887 handling}), file cache, connection cache (@pxref{Connection caching}),
2888 connection buffers.
2889 @end deffn
2891 @deffn Command tramp-cleanup-this-connection
2892 This command flushes all objects of the current buffer's remote
2893 connection.  The same objects are removed as in
2894 @code{tramp-cleanup-connection}.
2895 @end deffn
2897 @deffn Command tramp-cleanup-all-connections
2898 This command flushes objects for all active remote connections.  The
2899 same objects are removed as in @code{tramp-cleanup-connection}.
2900 @end deffn
2902 @deffn Command tramp-cleanup-all-buffers
2903 Like in @code{tramp-cleanup-all-connections}, all remote connections
2904 are cleaned up.  Additionally all buffers, which are related to a
2905 remote connection, are killed.
2906 @end deffn
2909 @node Bug Reports
2910 @chapter Reporting Bugs and Problems
2911 @cindex bug reports
2913 Bugs and problems with @value{tramp} are actively worked on by the
2914 development team.  Feature requests and suggestions are also more than
2915 welcome.
2917 The @value{tramp} mailing list is a great place to get information on
2918 working with @value{tramp}, solving problems and general discussion
2919 and advice on topics relating to the package.  It is moderated so
2920 non-subscribers can post but messages will be delayed, possibly up to
2921 48 hours (or longer in case of holidays), until the moderator approves
2922 your message.
2924 The mailing list is at @email{tramp-devel@@gnu.org}.  Messages sent to
2925 this address go to all the subscribers.  This is @emph{not} the address
2926 to send subscription requests to.
2928 Subscribing to the list is performed via
2929 @uref{http://lists.gnu.org/mailman/listinfo/tramp-devel/,
2930 the @value{tramp} Mail Subscription Page}.
2932 @findex tramp-bug
2933 To report a bug in @value{tramp}, you should execute @kbd{M-x
2934 tramp-bug}.  This will automatically generate a buffer with the details
2935 of your system and @value{tramp} version.
2937 When submitting a bug report, please try to describe in excruciating
2938 detail the steps required to reproduce the problem, the setup of the
2939 remote machine and any special conditions that exist.  You should also
2940 check that your problem is not described already in @xref{Frequently
2941 Asked Questions}.
2943 If you can identify a minimal test case that reproduces the problem,
2944 include that with your bug report.  This will make it much easier for
2945 the development team to analyze and correct the problem.
2947 Sometimes, there might be also problems due to Tramp caches.  Flush
2948 all caches before running the test, @ref{Cleanup remote connections}.
2950 Before reporting the bug, you should set the verbosity level to 6
2951 (@pxref{Traces and Profiles, Traces}) in the @file{~/.emacs} file and
2952 repeat the bug.  Then, include the contents of the @file{*tramp/foo*}
2953 and @file{*debug tramp/foo*} buffers in your bug report.  A verbosity
2954 level greater than 6 will produce a very huge debug buffer, which is
2955 mostly not necessary for the analysis.
2957 Please be aware that, with a verbosity level of 6 or greater, the
2958 contents of files and directories will be included in the debug
2959 buffer.  Passwords you've typed will never be included there.
2962 @node Frequently Asked Questions
2963 @chapter Frequently Asked Questions
2964 @cindex frequently asked questions
2965 @cindex FAQ
2967 @itemize @bullet
2968 @item
2969 Where can I get the latest @value{tramp}?
2971 @value{tramp} is available under the URL below.
2973 @noindent
2974 @uref{ftp://ftp.gnu.org/gnu/tramp/}
2976 @noindent
2977 There is also a Savannah project page.
2979 @noindent
2980 @uref{http://savannah.gnu.org/projects/tramp/}
2983 @item
2984 Which systems does it work on?
2986 The package has been used successfully on Emacs 22, Emacs 23, Emacs
2987 24, XEmacs 21 (starting with 21.4), and SXEmacs 22.
2989 The package was intended to work on Unix, and it really expects a
2990 Unix-like system on the remote end (except the @option{smb} method),
2991 but some people seemed to have some success getting it to work on MS
2992 Windows XP/Vista/7 @value{emacsname}.
2995 @item
2996 How could I speed up @value{tramp}?
2998 In the backstage, @value{tramp} needs a lot of operations on the
2999 remote host.  The time for transferring data from and to the remote
3000 host as well as the time needed to perform the operations there count.
3001 In order to speed up @value{tramp}, one could either try to avoid some
3002 of the operations, or one could try to improve their performance.
3004 Use an external method, like @option{scp}.
3006 Use caching.  This is already enabled by default.  Information about
3007 the remote host as well as the remote files are cached for reuse.  The
3008 information about remote hosts is kept in the file specified in
3009 @code{tramp-persistency-file-name}.  Keep this file.  If you are
3010 confident that files on remote hosts are not changed out of
3011 @value{emacsname}' control, set @code{remote-file-name-inhibit-cache}
3012 to @code{nil}.  Set also @code{tramp-completion-reread-directory-timeout}
3013 to @code{nil}, @ref{Filename completion}.
3015 Disable version control.  If you access remote files which are not
3016 under version control, a lot of check operations can be avoided by
3017 disabling VC@.  This can be achieved by
3019 @lisp
3020 (setq vc-ignore-dir-regexp
3021       (format "\\(%s\\)\\|\\(%s\\)"
3022               vc-ignore-dir-regexp
3023               tramp-file-name-regexp))
3024 @end lisp
3026 Disable excessive traces.  The default trace level of @value{tramp},
3027 defined in the variable @code{tramp-verbose}, is 3.  You should
3028 increase this level only temporarily, hunting bugs.
3031 @item
3032 @value{tramp} does not connect to the remote host
3034 When @value{tramp} does not connect to the remote host, there are three
3035 reasons heading the bug mailing list:
3037 @itemize @minus
3038 @item
3039 Unknown characters in the prompt
3041 @value{tramp} needs to recognize the prompt on the remote machine
3042 after execution any command.  This is not possible when the prompt
3043 contains unknown characters like escape sequences for coloring.  This
3044 should be avoided on the remote side.  @xref{Remote shell setup}. for
3045 setting the regular expression detecting the prompt.
3047 You can check your settings after an unsuccessful connection by
3048 switching to the @value{tramp} connection buffer @file{*tramp/foo*},
3049 setting the cursor at the top of the buffer, and applying the expression
3051 @example
3052 @kbd{M-: (re-search-forward (concat tramp-shell-prompt-pattern "$"))}
3053 @end example
3055 If it fails, or the cursor is not moved at the end of the buffer, your
3056 prompt is not recognized correctly.
3058 A special problem is the zsh, which uses left-hand side and right-hand
3059 side prompts in parallel.  Therefore, it is necessary to disable the
3060 zsh line editor on the remote host.  You shall add to @file{~/.zshrc}
3061 the following command:
3063 @example
3064 [ $TERM = "dumb" ] && unsetopt zle && PS1='$ '
3065 @end example
3067 Furthermore it has been reported, that @value{tramp} (like sshfs,
3068 incidentally) doesn't work with WinSSHD due to strange prompt settings.
3070 @item
3071 Echoed characters after login
3073 When the remote machine opens an echoing shell, there might be control
3074 characters in the welcome message.  @value{tramp} tries to suppress
3075 such echoes via the @command{stty -echo} command, but sometimes this
3076 command is not reached, because the echoed output has confused
3077 @value{tramp} already.  In such situations it might be helpful to use
3078 the @option{sshx} or @option{scpx} methods, which allocate a pseudo tty.
3079 @xref{Inline methods}.
3081 @item
3082 @value{tramp} doesn't transfer strings with more than 500 characters
3083 correctly
3085 On some few systems, the implementation of @code{process-send-string}
3086 seems to be broken for longer strings.  It is reported for HP-UX,
3087 FreeBSD and Tru64 Unix, for example.  This case, you should customize
3088 the variable @code{tramp-chunksize} to 500.  For a description how to
3089 determine whether this is necessary see the documentation of
3090 @code{tramp-chunksize}.
3092 Additionally, it will be useful to set @code{file-precious-flag} to
3093 @code{t} for @value{tramp} files.  Then the file contents will be
3094 written into a temporary file first, which is checked for correct
3095 checksum.
3096 @ifinfo
3097 @pxref{Saving Buffers, , , elisp}
3098 @end ifinfo
3100 @lisp
3101 (add-hook
3102  'find-file-hook
3103  (lambda ()
3104    (when (file-remote-p default-directory)
3105      (set (make-local-variable 'file-precious-flag) t))))
3106 @end lisp
3107 @end itemize
3110 @item
3111 @value{tramp} does not recognize hung @command{ssh} sessions
3113 When your network connection is down, @command{ssh} sessions might
3114 hang.  @value{tramp} cannot detect it safely, because it still sees a
3115 running @command{ssh} process.  Timeouts cannot be used as well,
3116 because it cannot be predicted how long a remote command will last,
3117 for example when copying very large files.
3119 Therefore, you must configure the @command{ssh} process to die
3120 in such a case.  The following entry in @file{~/.ssh/config} would do
3121 the job:
3123 @example
3124 Host *
3125      ServerAliveInterval 5
3126 @end example
3129 @item
3130 File name completion does not work with @value{tramp}
3132 When you log in to the remote machine, do you see the output of
3133 @command{ls} in color? If so, this may be the cause of your problems.
3135 @command{ls} outputs @acronym{ANSI} escape sequences that your terminal
3136 emulator interprets to set the colors.  These escape sequences will
3137 confuse @value{tramp} however.
3139 In your @file{.bashrc}, @file{.profile} or equivalent on the remote
3140 machine you probably have an alias configured that adds the option
3141 @option{--color=yes} or @option{--color=auto}.
3143 You should remove that alias and ensure that a new login @emph{does not}
3144 display the output of @command{ls} in color.  If you still cannot use
3145 filename completion, report a bug to the @value{tramp} developers.
3148 @item
3149 File name completion does not work in large directories
3151 @value{tramp} uses globbing for some operations.  (Globbing means to use the
3152 shell to expand wildcards such as `*.c'.)  This might create long
3153 command lines, especially in directories with many files.  Some shells
3154 choke on long command lines, or don't cope well with the globbing
3155 itself.
3157 If you have a large directory on the remote end, you may wish to execute
3158 a command like @samp{ls -d * ..?* > /dev/null} and see if it hangs.
3159 Note that you must first start the right shell, which might be
3160 @command{/bin/sh}, @command{ksh} or @command{bash}, depending on which
3161 of those supports tilde expansion.
3164 @item
3165 How can I get notified when @value{tramp} file transfers are complete?
3167 The following snippet can be put in your @file{~/.emacs} file.  It
3168 makes @value{emacsname} beep after reading from or writing to the
3169 remote host.
3171 @lisp
3172 (defadvice tramp-handle-write-region
3173   (after tramp-write-beep-advice activate)
3174   "Make tramp beep after writing a file."
3175   (interactive)
3176   (beep))
3178 (defadvice tramp-handle-do-copy-or-rename-file
3179   (after tramp-copy-beep-advice activate)
3180   "Make tramp beep after copying a file."
3181   (interactive)
3182   (beep))
3184 (defadvice tramp-handle-insert-file-contents
3185   (after tramp-insert-beep-advice activate)
3186   "Make tramp beep after inserting a file."
3187   (interactive)
3188   (beep))
3189 @end lisp
3192 @ifset emacs
3193 @item
3194 I'ld like to get a Visual Warning when working in a sudo:ed context
3196 When you are working with @samp{root} privileges, it might be useful
3197 to get an indication in the buffer's modeline.  The following code,
3198 tested with @value{emacsname} 22.1, does the job.  You should put it
3199 into your @file{~/.emacs}:
3201 @lisp
3202 (defun my-mode-line-function ()
3203   (when (string-match "^/su\\(do\\)?:" default-directory)
3204     (setq mode-line-format
3205           (format-mode-line mode-line-format 'font-lock-warning-face))))
3207 (add-hook 'find-file-hook 'my-mode-line-function)
3208 (add-hook 'dired-mode-hook 'my-mode-line-function)
3209 @end lisp
3210 @end ifset
3213 @ifset emacs
3214 @item
3215 I'ld like to see a host indication in the mode line when I'm remote
3217 The following code has been tested with @value{emacsname} 22.1.  You
3218 should put it into your @file{~/.emacs}:
3220 @lisp
3221 (defconst my-mode-line-buffer-identification
3222   (list
3223    '(:eval
3224      (let ((host-name
3225             (if (file-remote-p default-directory)
3226                 (tramp-file-name-host
3227                  (tramp-dissect-file-name default-directory))
3228               (system-name))))
3229        (if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
3230            (substring host-name 0 (match-beginning 1))
3231          host-name)))
3232    ": %12b"))
3234 (setq-default
3235  mode-line-buffer-identification
3236  my-mode-line-buffer-identification)
3238 (add-hook
3239  'dired-mode-hook
3240  (lambda ()
3241    (setq
3242     mode-line-buffer-identification
3243     my-mode-line-buffer-identification)))
3244 @end lisp
3246 Since @value{emacsname} 23.1, the mode line contains an indication if
3247 @code{default-directory} for the current buffer is on a remote host.
3248 The corresponding tooltip includes the name of that host.  If you
3249 still want the host name as part of the mode line, you can use the
3250 example above, but the @code{:eval} clause can be simplified:
3252 @lisp
3253    '(:eval
3254      (let ((host-name
3255             (or (file-remote-p default-directory 'host)
3256                 (system-name))))
3257        (if (string-match "^[^0-9][^.]*\\(\\..*\\)" host-name)
3258            (substring host-name 0 (match-beginning 1))
3259          host-name)))
3260 @end lisp
3261 @end ifset
3264 @ifset emacs
3265 @item
3266 My remote host does not understand default directory listing options
3268 @value{emacsname} computes the @command{dired} options depending on
3269 the local host you are working.  If your @command{ls} command on the
3270 remote host does not understand those options, you can change them
3271 like this:
3273 @lisp
3274 (add-hook
3275  'dired-before-readin-hook
3276  (lambda ()
3277    (when (file-remote-p default-directory)
3278      (setq dired-actual-switches "-al"))))
3279 @end lisp
3280 @end ifset
3283 @item
3284 There's this @file{~/.sh_history} file on the remote host which keeps
3285 growing and growing.  What's that?
3287 Sometimes, @value{tramp} starts @command{ksh} on the remote host for
3288 tilde expansion.  Maybe @command{ksh} saves the history by default.
3289 @value{tramp} tries to turn off saving the history, but maybe you have
3290 to help.  For example, you could put this in your @file{.kshrc}:
3292 @example
3293 if [ -f $HOME/.sh_history ] ; then
3294    /bin/rm $HOME/.sh_history
3296 if [ "$@{HISTFILE-unset@}" != "unset" ] ; then
3297    unset HISTFILE
3299 if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then
3300    unset HISTSIZE
3302 @end example
3305 @item There are longish file names to type.  How to shorten this?
3307 Let's say you need regularly access to @file{@trampfn{ssh, news,
3308 news.my.domain, /opt/news/etc}}, which is boring to type again and
3309 again.  The following approaches can be mixed:
3311 @enumerate
3313 @item Use default values for method and user name:
3315 You can define default methods and user names for hosts,
3316 (@pxref{Default Method}, @pxref{Default User}):
3318 @lisp
3319 (setq tramp-default-method "ssh"
3320       tramp-default-user "news")
3321 @end lisp
3323 The file name left to type would be
3324 @kbd{C-x C-f @trampfn{, , news.my.domain, /opt/news/etc}}.
3326 Note that there are some useful settings already.  Accessing your
3327 local host as @samp{root} user, is possible just by @kbd{C-x C-f
3328 @trampfn{su, , ,}}.
3330 @item Use configuration possibilities of your method:
3332 Several connection methods (i.e., the programs used) offer powerful
3333 configuration possibilities (@pxref{Customizing Completion}).  In the
3334 given case, this could be @file{~/.ssh/config}:
3336 @example
3337 Host xy
3338      HostName news.my.domain
3339      User news
3340 @end example
3342 The file name left to type would be @kbd{C-x C-f @trampfn{ssh, , xy,
3343 /opt/news/etc}}.  Depending on files in your directories, it is even
3344 possible to complete the host name with @kbd{C-x C-f
3345 @value{prefix}ssh@value{postfixhop}x @key{TAB}}.
3347 @item Use environment variables:
3349 File names typed in the minibuffer can be expanded by environment
3350 variables.  You can set them outside @value{emacsname}, or even with
3351 Lisp:
3353 @lisp
3354 (setenv "xy" "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}")
3355 @end lisp
3357 Then you need simply to type @kbd{C-x C-f $xy @key{RET}}, and here you
3358 are.  The disadvantage is that you cannot edit the file name, because
3359 environment variables are not expanded during editing in the
3360 minibuffer.
3362 @item Define own keys:
3364 You can define your own key sequences in @value{emacsname}, which can
3365 be used instead of @kbd{C-x C-f}:
3367 @lisp
3368 (global-set-key
3369  [(control x) (control y)]
3370  (lambda ()
3371    (interactive)
3372    (find-file
3373     (read-file-name
3374      "Find Tramp file: "
3375      "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))))
3376 @end lisp
3378 Simply typing @kbd{C-x C-y} would initialize the minibuffer for
3379 editing with your beloved file name.
3381 See also @uref{http://www.emacswiki.org/cgi-bin/wiki/TrampMode, the
3382 Emacs Wiki} for a more comprehensive example.
3384 @item Define own abbreviation (1):
3386 It is possible to define an own abbreviation list for expanding file
3387 names:
3389 @lisp
3390 (add-to-list
3391  'directory-abbrev-alist
3392  '("^/xy" . "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))
3393 @end lisp
3395 This shortens the file opening command to @kbd{C-x C-f /xy
3396 @key{RET}}.  The disadvantage is, again, that you cannot edit the file
3397 name, because the expansion happens after entering the file name only.
3399 @item Define own abbreviation (2):
3401 The @code{abbrev-mode} gives more flexibility for editing the
3402 minibuffer:
3404 @lisp
3405 (define-abbrev-table 'my-tramp-abbrev-table
3406   '(("xy" "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}")))
3408 (add-hook
3409  'minibuffer-setup-hook
3410  (lambda ()
3411    (abbrev-mode 1)
3412    (setq local-abbrev-table my-tramp-abbrev-table)))
3414 (defadvice minibuffer-complete
3415   (before my-minibuffer-complete activate)
3416   (expand-abbrev))
3418 ;; If you use partial-completion-mode
3419 (defadvice PC-do-completion
3420   (before my-PC-do-completion activate)
3421   (expand-abbrev))
3422 @end lisp
3424 After entering @kbd{C-x C-f xy @key{TAB}}, the minibuffer is
3425 expanded, and you can continue editing.
3427 @item Use bookmarks:
3429 Bookmarks can be used to visit Tramp files or directories.
3430 @ifinfo
3431 @pxref{Bookmarks, , , @value{emacsdir}}
3432 @end ifinfo
3434 When you have opened @file{@trampfn{ssh, news, news.my.domain,
3435 /opt/news/etc/}}, you should save the bookmark via
3436 @ifset emacs
3437 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{set}}.
3438 @end ifset
3439 @ifset xemacs
3440 @kbd{@key{menu-bar} @key{view} @key{bookmarks} @key{set}}.
3441 @end ifset
3443 Later on, you can always navigate to that bookmark via
3444 @ifset emacs
3445 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{jump}}.
3446 @end ifset
3447 @ifset xemacs
3448 @kbd{@key{menu-bar} @key{view} @key{bookmarks} @key{jump}}.
3449 @end ifset
3451 @item Use recent files:
3453 @ifset emacs
3454 @file{recentf}
3455 @end ifset
3456 @ifset xemacs
3457 @file{recent-files}
3458 @end ifset
3459 remembers visited places.
3460 @ifinfo
3461 @ifset emacs
3462 @pxref{File Conveniences, , , @value{emacsdir}}
3463 @end ifset
3464 @ifset xemacs
3465 @pxref{recent-files, , , edit-utils}
3466 @end ifset
3467 @end ifinfo
3469 You could keep remote file names in the recent list without checking
3470 their readability through a remote access:
3472 @lisp
3473 @ifset emacs
3474 (recentf-mode 1)
3475 @end ifset
3476 @ifset xemacs
3477 (recent-files-initialize)
3478 (add-hook
3479  'find-file-hook
3480  (lambda ()
3481    (when (file-remote-p (buffer-file-name))
3482      (recent-files-make-permanent)))
3483  'append)
3484 @end ifset
3485 @end lisp
3487 The list of files opened recently is reachable via
3488 @ifset emacs
3489 @kbd{@key{menu-bar} @key{file} @key{Open Recent}}.
3490 @end ifset
3491 @ifset xemacs
3492 @kbd{@key{menu-bar} @key{Recent Files}}.
3493 @end ifset
3495 @ifset emacs
3496 @item Use filecache:
3498 @file{filecache} remembers visited places.  Add the directory into
3499 the cache:
3501 @lisp
3502 (eval-after-load "filecache"
3503   '(file-cache-add-directory
3504     "@trampfn{ssh, news, news.my.domain, /opt/news/etc/}"))
3505 @end lisp
3507 Whenever you want to load a file, you can enter @kbd{C-x C-f
3508 C-@key{TAB}} in the minibuffer.  The completion is done for the given
3509 directory.
3510 @end ifset
3512 @ifset emacs
3513 @item Use bbdb:
3515 @file{bbdb} has a built-in feature for @value{ftppackagename} files,
3516 which works also for @value{tramp}.
3517 @ifinfo
3518 @pxref{bbdb-ftp, Storing FTP sites in the BBDB, , bbdb}
3519 @end ifinfo
3521 You need to load @file{bbdb}:
3523 @lisp
3524 (require 'bbdb)
3525 (bbdb-initialize)
3526 @end lisp
3528 Then you can create a BBDB entry via @kbd{M-x bbdb-create-ftp-site}.
3529 Because BBDB is not prepared for @value{tramp} syntax, you must
3530 specify a method together with the user name when needed. Example:
3532 @example
3533 @kbd{M-x bbdb-create-ftp-site @key{RET}}
3534 @b{Ftp Site:} news.my.domain @key{RET}
3535 @b{Ftp Directory:} /opt/news/etc/ @key{RET}
3536 @b{Ftp Username:} ssh@value{postfixhop}news @key{RET}
3537 @b{Company:} @key{RET}
3538 @b{Additional Comments:} @key{RET}
3539 @end example
3541 When you have opened your BBDB buffer, you can access such an entry by
3542 pressing the key @key{F}.
3543 @end ifset
3545 @end enumerate
3547 I would like to thank all @value{tramp} users who have contributed to
3548 the different recipes!
3551 @ifset emacs
3552 @item
3553 How can I use @value{tramp} to connect to a remote @value{emacsname}
3554 session?
3556 You can configure Emacs Client doing this.
3557 @ifinfo
3558 @xref{Emacs Server, , , @value{emacsdir}}.
3559 @end ifinfo
3561 On the remote host, you start the Emacs Server:
3563 @lisp
3564 (require 'server)
3565 (setq server-host (system-name)
3566       server-use-tcp t)
3567 (server-start)
3568 @end lisp
3570 Make sure that the result of @code{(system-name)} can be resolved on
3571 your local host; otherwise you might use a hard coded IP address.
3573 The resulting file @file{~/.emacs.d/server/server} must be copied to
3574 your local host, at the same location.  You can call then the Emacs
3575 Client from the command line:
3577 @example
3578 emacsclient @trampfn{ssh, user, host, /file/to/edit}
3579 @end example
3581 @code{user} and @code{host} shall be related to your local host.
3583 If you want to use Emacs Client also as editor for other programs, you
3584 could write a script @file{emacsclient.sh}:
3586 @example
3587 #!/bin/sh
3588 emacsclient @trampfn{ssh, $(whoami), $(hostname --fqdn), $1}
3589 @end example
3591 Then you must set the environment variable @env{EDITOR} pointing to
3592 that script:
3594 @example
3595 export EDITOR=/path/to/emacsclient.sh
3596 @end example
3597 @end ifset
3600 @item
3601 There are packages which call @value{tramp} although I haven't entered
3602 a remote file name ever.  I dislike it, how could I disable it?
3604 In general, @value{tramp} functions are used only when
3605 you apply remote file name syntax.  However, some packages enable
3606 @value{tramp} on their own.
3608 @itemize @minus
3609 @item
3610 @file{ido.el}
3612 You could disable @value{tramp} file name completion:
3614 @lisp
3615 (custom-set-variables
3616  '(ido-enable-tramp-completion nil))
3617 @end lisp
3619 @item
3620 @file{rlogin.el}
3622 You could disable remote directory tracking mode:
3624 @lisp
3625 (rlogin-directory-tracking-mode -1)
3626 @end lisp
3627 @end itemize
3630 @item
3631 How can I disable @value{tramp} at all?
3633 Shame on you, why did you read until now?
3635 @itemize @minus
3636 @ifset emacs
3637 @item
3638 If you just want to have @value{ftppackagename} as default remote
3639 files access package, you should apply the following code:
3641 @lisp
3642 (setq tramp-default-method "ftp")
3643 @end lisp
3644 @end ifset
3646 @item
3647 In order to disable
3648 @ifset emacs
3649 @value{tramp} (and @value{ftppackagename}),
3650 @end ifset
3651 @ifset xemacs
3652 @value{tramp},
3653 @end ifset
3654 you must set @code{tramp-mode} to @code{nil}:
3656 @lisp
3657 (setq tramp-mode nil)
3658 @end lisp
3660 @item
3661 Unloading @value{tramp} can be achieved by applying @kbd{M-x
3662 tramp-unload-tramp}.
3663 @ifset emacs
3664 This resets also the @value{ftppackagename} plugins.
3665 @end ifset
3666 @end itemize
3667 @end itemize
3670 @c For the developer
3671 @node Files directories and localnames
3672 @chapter How file names, directories and localnames are mangled and managed.
3674 @menu
3675 * Localname deconstruction::    Breaking a localname into its components.
3676 @ifset emacs
3677 * External packages::           Integration with external Lisp packages.
3678 @end ifset
3679 @end menu
3682 @node Localname deconstruction
3683 @section Breaking a localname into its components
3685 @value{tramp} file names are somewhat different, obviously, to ordinary file
3686 names.  As such, the lisp functions @code{file-name-directory} and
3687 @code{file-name-nondirectory} are overridden within the @value{tramp}
3688 package.
3690 Their replacements are reasonably simplistic in their approach.  They
3691 dissect the filename, call the original handler on the localname and
3692 then rebuild the @value{tramp} file name with the result.
3694 This allows the platform specific hacks in the original handlers to take
3695 effect while preserving the @value{tramp} file name information.
3698 @ifset emacs
3699 @node External packages
3700 @section Integration with external Lisp packages
3701 @subsection Filename completion.
3703 While reading filenames in the minibuffer, @value{tramp} must decide
3704 whether it completes possible incomplete filenames, or not.  Imagine
3705 there is the following situation: You have typed @kbd{C-x C-f
3706 @value{prefix}ssh@value{postfixhop} @key{TAB}}.  @value{tramp} cannot
3707 know, whether @option{ssh} is a method or a host name.  It checks
3708 therefore the last input character you have typed.  If this is
3709 @key{TAB}, @key{SPACE} or @kbd{?}, @value{tramp} assumes that you are
3710 still in filename completion, and it does not connect to the possible
3711 remote host @option{ssh}.
3713 @vindex tramp-completion-mode
3714 External packages, which use other characters for completing filenames
3715 in the minibuffer, must signal this to @value{tramp}.  For this case,
3716 the variable @code{tramp-completion-mode} can be bound temporarily to
3717 a non-@code{nil} value.
3719 @lisp
3720 (let ((tramp-completion-mode t))
3721   ...)
3722 @end lisp
3725 @subsection File attributes cache.
3727 When @value{tramp} runs remote processes, files on the remote host
3728 could change their attributes.  Consequently, @value{tramp} must flush
3729 its complete cache keeping attributes for all files of the remote host
3730 it has seen so far.
3732 This is a performance degradation, because the lost file attributes
3733 must be recomputed when needed again.  In cases the caller of
3734 @code{process-file} knows that there are no file attribute changes, it
3735 shall let-bind the variable @code{process-file-side-effects} to
3736 @code{nil}.  @value{tramp} wouldn't flush the file attributes cache then.
3738 @lisp
3739 (let (process-file-side-effects)
3740   ...)
3741 @end lisp
3743 For asynchronous processes, @value{tramp} flushes the file attributes
3744 cache via a process sentinel.  If the caller of
3745 @code{start-file-process} knows that there are no file attribute
3746 changes, it shall set the process sentinel to @code{nil}.  In case the
3747 caller defines an own process sentinel, @value{tramp}'s process
3748 sentinel is overwritten.  The caller can still flush the file
3749 attributes cache in its process sentinel with this code:
3751 @lisp
3752 (unless (memq (process-status proc) '(run open))
3753   (dired-uncache remote-directory))
3754 @end lisp
3756 @code{remote-directory} shall be the root directory, where file
3757 attribute changes can happen during the process lifetime.
3758 @value{tramp} traverses all subdirectories, starting at this
3759 directory.  Often, it is sufficient to use @code{default-directory} of
3760 the process buffer as root directory.
3761 @end ifset
3764 @node Traces and Profiles
3765 @chapter How to Customize Traces
3767 All @value{tramp} messages are raised with a verbosity level.  The
3768 verbosity level can be any number between 0 and 10.  Only messages with
3769 a verbosity level less than or equal to @code{tramp-verbose} are
3770 displayed.
3772 The verbosity levels are
3774           @w{ 0}  silent (no @value{tramp} messages at all)
3775 @*@indent @w{ 1}  errors
3776 @*@indent @w{ 2}  warnings
3777 @*@indent @w{ 3}  connection to remote hosts (default verbosity)
3778 @*@indent @w{ 4}  activities
3779 @*@indent @w{ 5}  internal
3780 @*@indent @w{ 6}  sent and received strings
3781 @*@indent @w{ 7}  file caching
3782 @*@indent @w{ 8}  connection properties
3783 @*@indent @w{ 9}  test commands
3784 @*@indent @w{10}  traces (huge)
3786 When @code{tramp-verbose} is greater than or equal to 4, the messages
3787 are also written into a @value{tramp} debug buffer.  This debug buffer
3788 is useful for analyzing problems; sending a @value{tramp} bug report
3789 should be done with @code{tramp-verbose} set to a verbosity level of at
3790 least 6 (@pxref{Bug Reports}).
3792 The debug buffer is in
3793 @ifinfo
3794 @ref{Outline Mode, , , @value{emacsdir}}.
3795 @end ifinfo
3796 @ifnotinfo
3797 Outline Mode.
3798 @end ifnotinfo
3799 That means, you can change the level of messages to be viewed.  If you
3800 want, for example, see only messages up to verbosity level 5, you must
3801 enter @kbd{C-u 6 C-c C-q}.
3802 @ifinfo
3803 Other keys for navigating are described in
3804 @ref{Outline Visibility, , , @value{emacsdir}}.
3805 @end ifinfo
3807 @value{tramp} errors are handled internally in order to raise the
3808 verbosity level 1 messages.  When you want to get a Lisp backtrace in
3809 case of an error, you need to set both
3811 @lisp
3812 (setq debug-on-error t
3813       debug-on-signal t)
3814 @end lisp
3816 Sometimes, it might be even necessary to step through @value{tramp}
3817 function call traces.  Such traces are enabled by the following code:
3819 @lisp
3820 (require 'tramp)
3821 (require 'trace)
3822 (dolist (elt (all-completions "tramp-" obarray 'functionp))
3823   (trace-function-background (intern elt)))
3824 (untrace-function 'tramp-read-passwd)
3825 (untrace-function 'tramp-gw-basic-authentication)
3826 @end lisp
3828 The function call traces are inserted in the buffer
3829 @file{*trace-output*}.  @code{tramp-read-passwd} and
3830 @code{tramp-gw-basic-authentication} shall be disabled when the
3831 function call traces are added to @value{tramp}, because both
3832 functions return password strings, which should not be distributed.
3835 @node Issues
3836 @chapter Debatable Issues and What Was Decided
3838 @itemize @bullet
3839 @item The uuencode method does not always work.
3841 Due to the design of @value{tramp}, the encoding and decoding programs
3842 need to read from stdin and write to stdout.  On some systems,
3843 @command{uudecode -o -} will read stdin and write the decoded file to
3844 stdout, on other systems @command{uudecode -p} does the same thing.
3845 But some systems have uudecode implementations which cannot do this at
3846 all---it is not possible to call these uudecode implementations with
3847 suitable parameters so that they write to stdout.
3849 Of course, this could be circumvented: the @code{begin foo 644} line
3850 could be rewritten to put in some temporary file name, then
3851 @command{uudecode} could be called, then the temp file could be
3852 printed and deleted.
3854 But I have decided that this is too fragile to reliably work, so on some
3855 systems you'll have to do without the uuencode methods.
3857 @item The @value{tramp} filename syntax differs between Emacs and XEmacs.
3859 The Emacs maintainers wish to use a unified filename syntax for
3860 Ange-FTP and @value{tramp} so that users don't have to learn a new
3861 syntax.  It is sufficient to learn some extensions to the old syntax.
3863 For the XEmacs maintainers, the problems caused from using a unified
3864 filename syntax are greater than the gains.  The XEmacs package system
3865 uses EFS for downloading new packages.  So, obviously, EFS has to be
3866 installed from the start.  If the filenames were unified, @value{tramp}
3867 would have to be installed from the start, too.
3869 @ifset xemacs
3870 @strong{Note:} If you'd like to use a similar syntax like
3871 @value{ftppackagename}, you need the following settings in your init
3872 file:
3874 @lisp
3875 (setq tramp-unified-filenames t)
3876 (require 'tramp)
3877 @end lisp
3879 The autoload of the @value{emacsname} @value{tramp} package must be
3880 disabled.  This can be achieved by setting file permissions @code{000}
3881 to the files @file{.../xemacs-packages/lisp/tramp/auto-autoloads.el*}.
3883 In case of unified filenames, all @value{emacsname} download sites are
3884 added to @code{tramp-default-method-alist} with default method
3885 @option{ftp} @xref{Default Method}.  These settings shouldn't be
3886 touched for proper working of the @value{emacsname} package system.
3888 The syntax for unified filenames is described in the @value{tramp} manual
3889 for @value{emacsothername}.
3890 @end ifset
3891 @end itemize
3893 @node GNU Free Documentation License
3894 @appendix GNU Free Documentation License
3895 @include doclicense.texi
3897 @node Function Index
3898 @unnumbered Function Index
3899 @printindex fn
3901 @node Variable Index
3902 @unnumbered Variable Index
3903 @printindex vr
3905 @node Concept Index
3906 @unnumbered Concept Index
3907 @printindex cp
3909 @bye
3911 @c TODO
3913 @c * Say something about the .login and .profile files of the remote
3914 @c   shells.
3915 @c * Explain how tramp.el works in principle: open a shell on a remote
3916 @c   host and then send commands to it.
3917 @c * Use `filename' resp. `file name' consistently.
3918 @c * Use `host' resp. `machine' consistently.
3919 @c * Consistent small or capitalized words especially in menus.
3920 @c * Make a unique declaration of @trampfn.