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