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