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