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