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