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