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