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