* doc/misc/tramp.texi: Highlight @cindex entries properly.
[emacs.git] / doc / misc / tramp.texi
blobf5dfef261f7e6aaa520be09845e6862e9a7cc000
1 \input texinfo   @c -*- mode: texinfo; coding: utf-8 -*-
2 @setfilename ../../info/tramp.info
3 @c %**start of header
4 @settitle TRAMP User Manual
5 @include docstyle.texi
6 @c %**end of header
8 @c This is *so* much nicer :)
9 @footnotestyle end
11 @c In the Tramp repository, the version number is auto-frobbed from
12 @c configure.ac, so you should edit that file and run
13 @c "autoconf && ./configure" to change the version number.
15 @include trampver.texi
17 @c Macro for formatting a file name according to the respective
18 @c syntax.  Macro arguments should not have any leading or trailing
19 @c whitespace.  Not very elegant, but I don't know it better.
21 @macro trampfn {method, userhost, localname}
22 @value{prefix}@c
23 \method\@value{postfixhop}@c
24 \userhost\@value{postfix}\localname\
25 @end macro
27 @copying
28 Copyright @copyright{} 1999--2018 Free Software Foundation, Inc.
30 @quotation
31 Permission is granted to copy, distribute and/or modify this document
32 under the terms of the GNU Free Documentation License, Version 1.3 or
33 any later version published by the Free Software Foundation; with no
34 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
35 and with the Back-Cover Texts as in (a) below.  A copy of the license
36 is included in the section entitled ``GNU Free Documentation License''.
38 (a) The FSF's Back-Cover Text is: ``You have the freedom to
39 copy and modify this GNU manual.''
40 @end quotation
41 @end copying
43 @c Entries for @command{install-info} to use
44 @dircategory Emacs network features
45 @direntry
46 * @value{tramp}: (tramp).               Transparent Remote Access, Multiple Protocol
47                                   Emacs remote file access via ssh and scp.
48 @end direntry
50 @titlepage
51 @title @value{tramp} version @value{trampver} User Manual
52 @author by Daniel Pittman
53 @author based on documentation by Kai Großjohann
54 @end titlepage
56 @contents
59 @node Top, Overview, (dir), (dir)
60 @top @value{tramp} version @value{trampver} User Manual
62 This file documents @value{tramp} version @value{trampver}, a remote file
63 editing package for Emacs.
65 @value{tramp} stands for ``Transparent Remote (file) Access, Multiple
66 Protocol''.  This package provides remote file editing, similar to
67 Ange FTP.
69 The difference is that Ange FTP uses FTP to transfer files between the
70 local and the remote host, whereas @value{tramp} uses a combination of
71 @command{rsh} and @command{rcp} or other work-alike programs, such as
72 @command{ssh}/@command{scp}.
74 You can find the latest version of this document on the web at
75 @uref{https://www.gnu.org/software/tramp/}.
77 @ifhtml
78 The latest release of @value{tramp} is available for
79 @uref{https://ftp.gnu.org/gnu/tramp/, download}, or you may see
80 @ref{Obtaining @value{tramp}} for more details, including the Git
81 server details.
83 @value{tramp} also has a @uref{https://savannah.gnu.org/projects/tramp/,
84 Savannah Project Page}.
85 @end ifhtml
87 There is a mailing list for @value{tramp}, available at
88 @email{tramp-devel@@gnu.org}, and archived at
89 @uref{https://lists.gnu.org/r/tramp-devel/, the
90 @value{tramp} Mail Archive}.
92 @page
93 @insertcopying
95 @menu
96 * Overview::                    What @value{tramp} can and cannot do.
98 For the end user:
100 * Obtaining @value{tramp}::             How to obtain @value{tramp}.
101 * History::                     History of @value{tramp}.
102 @ifset installchapter
103 * Installation::                Installing @value{tramp} with your Emacs.
104 @end ifset
105 * Quick Start Guide::           Short introduction how to use @value{tramp}.
106 * Configuration::               Configuring @value{tramp} for use.
107 * Usage::                       An overview of the operation of @value{tramp}.
108 * Bug Reports::                 Reporting Bugs and Problems.
109 * Frequently Asked Questions::  Questions and answers from the mailing list.
111 For the developer:
113 * Files directories and localnames::
114                                 How file names, directories and localnames
115                                   are mangled and managed.
116 * Traces and Profiles::         How to Customize Traces.
118 * GNU Free Documentation License:: The license for this documentation.
119 * Function Index::              @value{tramp} functions.
120 * Variable Index::              User options and variables.
121 * Concept Index::               An item for each concept.
123 @detailmenu
124  --- The Detailed Node Listing ---
126 @ifset installchapter
127 Installing @value{tramp} with your Emacs
129 * Installation parameters::     Parameters in order to control installation.
130 * Testing::                     A test suite for @value{tramp}.
131 * Load paths::                  How to plug-in @value{tramp} into your environment.
132 @end ifset
134 Configuring @value{tramp} for use
136 * Connection types::            Types of connections to remote hosts.
137 * Inline methods::              Inline methods.
138 * External methods::            External methods.
139 * GVFS based methods::          GVFS based external methods.
140 * Default Method::              Selecting a default method.
141 * Default User::                Selecting a default user.
142 * Default Host::                Selecting a default host.
143 * Multi-hops::                  Connecting to a remote host using multiple hops.
144 * Firewalls::                   Passing firewalls.
145 * Customizing Methods::         Using Non-Standard Methods.
146 * Customizing Completion::      Selecting config files for user/host name completion.
147 * Password handling::           Reusing passwords for several connections.
148 * Connection caching::          Reusing connection related information.
149 * Predefined connection information::
150                                 Setting own connection related information.
151 * Remote programs::             How @value{tramp} finds and uses programs on the remote host.
152 * Remote shell setup::          Remote shell setup hints.
153 * Android shell setup::         Android shell setup hints.
154 * Auto-save and Backup::        Auto-save and Backup.
155 * Windows setup hints::         Issues with Cygwin ssh.
157 Using @value{tramp}
159 * File name syntax::            @value{tramp} file name conventions.
160 @ifset unified
161 * Change file name syntax::     Alternative file name syntax.
162 @end ifset
163 * File name completion::        File name completion.
164 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
165 * Remote processes::            Integration with other Emacs packages.
166 * Cleanup remote connections::  Cleanup remote connections.
167 * Archive file names::          Access to files in file archives.
169 How file names, directories and localnames are mangled and managed
171 * Localname deconstruction::    Breaking a localname into its components.
172 * External packages::           Integration with external Lisp packages.
174 @end detailmenu
175 @end menu
178 @node Overview
179 @chapter An overview of @value{tramp}
180 @cindex overview
182 @value{tramp} is for transparently accessing remote files from within
183 Emacs.  @value{tramp} enables an easy, convenient, and consistent
184 interface to remote files as if they are local files.  @value{tramp}'s
185 transparency extends to editing, version control, and @code{dired}.
187 @value{tramp} can access remote hosts using any number of access
188 methods, such as @command{rsh}, @command{rlogin}, @command{telnet},
189 and related programs.  If these programs can successfully pass
190 @acronym{ASCII} characters, @value{tramp} can use them.
191 @value{tramp} does not require or mandate 8-bit clean connections.
193 @value{tramp}'s most common access method is through @command{ssh}, a
194 more secure alternative to @command{ftp} and other older access
195 methods.
197 @value{tramp} on MS Windows operating systems is integrated with the
198 PuTTY package, and uses the @command{plink} program.
200 @value{tramp} mostly operates transparently in the background using
201 the connection programs.  As long as these programs enable remote login
202 and can use the terminal, @value{tramp} can adapt them for seamless
203 and transparent access.
205 @value{tramp} temporarily transfers a remote file's contents to the
206 local host editing and related operations.  @value{tramp} can also
207 transfer files between hosts using standard Emacs interfaces, a
208 benefit of direct integration of @value{tramp} in Emacs.
210 @value{tramp} can transfer files using any number of available host
211 programs for remote files, such as @command{rcp}, @command{scp},
212 @command{rsync} or (under MS Windows) @command{pscp}.  @value{tramp}
213 provides easy ways to specify these programs and customize them to
214 specific files, hosts, or access methods.
216 For faster small-size file transfers, @value{tramp} supports encoded
217 transfers directly through the shell using @command{mimencode} or
218 @command{uuencode} provided such tools are available on the remote
219 host.
222 @subsubheading @value{tramp} behind the scenes
223 @cindex behind the scenes
224 @cindex details of operation
225 @cindex how it works
227 Accessing a remote file through @value{tramp} entails a series of
228 actions, many of which are transparent to the user.  Yet some actions
229 may require user response (such as entering passwords or completing
230 file names).  One typical scenario, opening a file on a remote host, is
231 presented here to illustrate the steps involved:
233 @kbd{C-x C-f} to initiate find-file, enter part of the @value{tramp}
234 file name, then hit @kbd{@key{TAB}} for completion.  If this is the
235 first time connection to that host, here's what happens:
237 @itemize
238 @item
239 @value{tramp} invokes @samp{telnet @var{host}} or @samp{rsh @var{host}
240 -l @var{user}} and establishes an external process to connect to the
241 remote host.  @value{tramp} communicates with the process through an
242 Emacs buffer, which also shows output from the remote host.
244 @item
245 The remote host may prompt for a login name (for @command{telnet}, for
246 example) in the buffer.  If on the other hand, the login name was
247 included in the file name portion, @value{tramp} sends the login name
248 followed by a newline.
250 @item
251 The remote host may then prompt for a password or pass phrase (for
252 @command{rsh} or for @command{telnet}).  @value{tramp} displays the
253 password prompt in the minibuffer.  @value{tramp} then sends whatever
254 is entered to the remote host, followed by a newline.
256 @item
257 @value{tramp} now waits for either the shell prompt or a failed login
258 message.
260 If @value{tramp} does not receive any messages within a timeout period
261 (a minute, for example), then @value{tramp} responds with an error
262 message about not finding the remote shell prompt.  If any messages
263 from the remote host, @value{tramp} displays them in the buffer.
265 For any @samp{login failed} message from the remote host,
266 @value{tramp} aborts the login attempt, and repeats the login steps
267 again.
269 @item
270 Upon successful login and @value{tramp} recognizes the shell prompt
271 from the remote host, @value{tramp} prepares the shell environment by
272 turning off echoing, setting shell prompt, and other housekeeping
273 chores.
275 @strong{Note} that for the remote shell, @value{tramp} invokes
276 @command{/bin/sh}.  The remote host must recognize @samp{exec /bin/sh}
277 and execute the appropriate shell.  This shell must support Bourne
278 shell syntax.
280 @item
281 @value{tramp} executes @command{cd} and @command{ls} commands to find
282 which files exist on the remote host.  @value{tramp} sometimes uses
283 @command{echo} with globbing.  @value{tramp} checks if a file or
284 directory is writable with @command{test}.  After each command,
285 @value{tramp} parses the output from the remote host for completing
286 the next operation.
288 @item
289 After remote file name completion, @value{tramp} transfers the file
290 contents from the remote host.
292 For inline transfers, @value{tramp} sends a command, such as
293 @samp{mimencode -b /path/to/remote/file}, waits until the output has
294 accumulated in the buffer, decodes that output to produce the file's
295 contents.
297 For external transfers, @value{tramp} sends a command as follows:
298 @example
299 rcp user@@host:/path/to/remote/file /tmp/tramp.4711
300 @end example
301 @value{tramp} reads the local temporary file @file{/tmp/tramp.4711}
302 into a buffer, and then deletes the temporary file.
304 @item
305 Edit, modify, change the buffer contents as normal, and then save the
306 buffer wth @kbd{C-x C-s}.
308 @item
309 @value{tramp} transfers the buffer contents to the remote host in
310 a reverse of the process using the appropriate inline or external
311 program.
312 @end itemize
314 I hope this has provided you with a basic overview of what happens
315 behind the scenes when you open a file with @value{tramp}.
318 @c For the end user
319 @node Obtaining @value{tramp}
320 @chapter Obtaining @value{tramp}
321 @cindex obtaining @value{tramp}
323 @value{tramp} is included as part of Emacs (since Emacs version 22.1).
325 @value{tramp} is also freely packaged for download on the Internet at
326 @uref{https://ftp.gnu.org/gnu/tramp/}.
328 @value{tramp} development versions are available on Git servers.
329 Development versions contain new and incomplete features.
331 One way to obtain from Git server is to visit the Savannah project
332 page at the following URL and then clicking on the Git link in the
333 navigation bar at the top.
335 @noindent
336 @uref{https://savannah.gnu.org/projects/tramp/}
338 @noindent
339 Another way is to follow the terminal session below:
341 @example
342 @group
343 $ cd ~/emacs
344 $ git clone git://git.savannah.gnu.org/tramp.git
345 @end group
346 @end example
348 @noindent
349 From behind a firewall:
351 @example
352 @group
353 $ git config --global http.proxy http://user:pwd@@proxy.server.com:8080
354 $ git clone https://git.savannah.gnu.org/r/tramp.git
355 @end group
356 @end example
358 @noindent
359 @value{tramp} developers:
361 @example
362 $ git clone login@@git.sv.gnu.org:/srv/git/tramp.git
363 @end example
365 @noindent
366 After one of the above commands, @file{~/emacs/tramp} will
367 containing the latest version of @value{tramp}.
369 @noindent
370 To fetch updates from the repository, use git pull:
372 @example
373 @group
374 $ cd ~/emacs/tramp
375 $ git pull
376 @end group
377 @end example
379 @noindent
380 Run @command{autoconf} as follows to generate an up-to-date
381 @file{configure} script:
383 @example
384 @group
385 $ cd ~/emacs/tramp
386 $ autoconf
387 @end group
388 @end example
391 @node History
392 @chapter History of @value{tramp}
393 @cindex history
394 @cindex development history
396 @value{tramp} development started at the end of November 1998 as
397 @file{rssh.el}.  It provided only one method of access.  It used
398 @command{ssh} for login and @command{scp} to transfer file contents.
399 The name was changed to @file{rcp.el} before it got its present name
400 @value{tramp}.  New methods of remote access were added, so was support
401 for version control.
403 April 2000 was the first time when multi-hop methods were added.  In
404 July 2002, @value{tramp} unified file names with Ange FTP@.  In July
405 2004, proxy hosts replaced multi-hop methods.  Running commands on
406 remote hosts was introduced in December 2005.  Support for gateways
407 since April 2007 (and removed in December 2016).  GVFS integration
408 started in February 2009.  Remote commands on MS Windows hosts since
409 September 2011.  Ad-hoc multi-hop methods (with a changed syntax)
410 re-enabled in November 2011.  In November 2012, added Juergen
411 Hoetzel's @file{tramp-adb.el}.  Archive file names are supported since
412 December 2017.
414 XEmacs support was stopped in January 2016.  Since March 2017,
415 @value{tramp} syntax mandates a method.
417 @c Installation chapter is necessary only in case of standalone
418 @c installation.  Text taken from trampinst.texi.
419 @ifset installchapter
420 @include trampinst.texi
421 @end ifset
424 @node Quick Start Guide
425 @chapter Short introduction how to use @value{tramp}
426 @cindex quick start guide
428 @value{tramp} extends the Emacs file name syntax by a remote
429 component.  A remote file name looks always like
430 @file{@trampfn{method,user@@host,/path/to/file}}.
432 You can use remote files exactly like ordinary files, that means you
433 could open a file or directory by @kbd{C-x C-f
434 @trampfn{method,user@@host,/path/to/file} @key{RET}}, edit the file,
435 and save it.  You can also mix local files and remote files in file
436 operations with two arguments, like @code{copy-file} or
437 @code{rename-file}.  And finally, you can run even processes on a
438 remote host, when the buffer you call the process from has a remote
439 @code{default-directory}.
442 @anchor{Quick Start Guide: File name syntax}
443 @section File name syntax
444 @cindex file name syntax
446 Remote file names are prepended by the @code{method}, @code{user} and
447 @code{host} parts.  All of them, and also the local file name part,
448 are optional, in case of a missing part a default value is assumed.
449 The default value for an empty local file name part is the remote
450 user's home directory.  The shortest remote file name is
451 @file{@trampfn{-,,}}, therefore.  The @samp{-} notation for the
452 default host is used for syntactical reasons, @ref{Default Host}.
454 The @code{method} part describes the connection method used to reach
455 the remote host, see below.
457 The @code{user} part is the user name for accessing the remote host.
458 For the @option{smb} method, this could also require a domain name, in
459 this case it is written as @code{user%domain}.
461 The @code{host} part must be a host name which could be resolved on
462 your local host.  It could be a short host name, a fully qualified
463 domain name, an IPv4 or IPv6 address, @ref{File name syntax}.  Some
464 connection methods support also a notation of the port to be used, in
465 this case it is written as @code{host#port}.
468 @anchor{Quick Start Guide: @option{ssh} and @option{plink} methods}
469 @section Using @option{ssh} and @option{plink}
470 @cindex method @option{ssh}
471 @cindex @option{ssh} method
472 @cindex method @option{plink}
473 @cindex @option{plink} method
475 If your local host runs an SSH client, and the remote host runs an SSH
476 server, the most simple remote file name is
477 @file{@trampfn{ssh,user@@host,/path/to/file}}.  The remote file name
478 @file{@trampfn{ssh,,}} opens a remote connection to yourself on the
479 local host, and is taken often for testing @value{tramp}.
481 On MS Windows, PuTTY is often used as SSH client.  Its @command{plink}
482 method can be used there to open a connection to a remote host running
483 an @command{ssh} server:
484 @file{@trampfn{plink,user@@host,/path/to/file}}.
487 @anchor{Quick Start Guide: @option{su}, @option{sudo} and @option{sg} methods}
488 @section Using @option{su}, @option{sudo} and @option{sg}
489 @cindex method @option{su}
490 @cindex @option{su} method
491 @cindex method @option{sudo}
492 @cindex @option{sudo} method
493 @cindex method @option{sg}
494 @cindex @option{sg} method
496 Sometimes, it is necessary to work on your local host under different
497 permissions.  For this, you could use the @option{su} or @option{sudo}
498 connection method.  Both methods use @samp{root} as default user name
499 and the return value of @code{(system-name)} as default host name.
500 Therefore, it is convenient to open a file as
501 @file{@trampfn{sudo,,/path/to/file}}.
503 The method @option{sg} stands for ``switch group''; the changed group
504 must be used here as user name.  The default host name is the same.
507 @anchor{Quick Start Guide: @option{smb} method}
508 @section Using @command{smbclient}
509 @cindex method @option{smb}
510 @cindex @option{smb} method
511 @cindex ms windows (with @option{smb} method)
512 @cindex @command{smbclient}
514 In order to access a remote MS Windows host or Samba server, the
515 @command{smbclient} client is used.  The remote file name syntax is
516 @file{@trampfn{smb,user%domain@@host,/path/to/file}}.  The first part
517 of the local file name is the share exported by the remote host,
518 @samp{path} in this example.
521 @anchor{Quick Start Guide: GVFS-based methods}
522 @section Using GVFS-based methods
523 @cindex methods, gvfs
524 @cindex gvfs based methods
525 @cindex method @option{sftp}
526 @cindex @option{sftp} method
527 @cindex method @option{afp}
528 @cindex @option{afp} method
529 @cindex method @option{dav}
530 @cindex method @option{davs}
531 @cindex @option{dav} method
532 @cindex @option{davs} method
534 On systems, which have installed the virtual file system for the
535 @acronym{GNOME} Desktop (GVFS), its offered methods could be used by
536 @value{tramp}.  Examples are
537 @file{@trampfn{sftp,user@@host,/path/to/file}},
538 @file{@trampfn{afp,user@@host,/path/to/file}} (accessing Apple's AFP
539 file system), @file{@trampfn{dav,user@@host,/path/to/file}} and
540 @file{@trampfn{davs,user@@host,/path/to/file}} (for WebDAV shares).
543 @anchor{Quick Start Guide: GNOME Online Accounts based methods}
544 @section Using @acronym{GNOME} Online Accounts based methods
545 @cindex @acronym{GNOME} Online Accounts
546 @cindex method @option{gdrive}
547 @cindex @option{gdrive} method
548 @cindex google drive
549 @cindex method @option{owncloud}
550 @cindex @option{owncloud} method
551 @cindex nextcloud
553 GVFS-based methods include also @acronym{GNOME} Online Accounts, which
554 support the @option{Files} service.  These are the Google Drive file
555 system, and the OwnCloud/NextCloud file system.  The file name syntax
556 is here always
557 @file{@trampfn{gdrive,john.doe@@gmail.com,/path/to/file}}
558 (@samp{john.doe@@gmail.com} stands here for your Google Drive
559 account), or @file{@trampfn{owncloud,user@@host#8081,/path/to/file}}
560 (@samp{8081} stands for the port number) for OwnCloud/NextCloud files.
563 @anchor{Quick Start Guide: Android}
564 @section Using Android
565 @cindex method @option{adb}
566 @cindex @option{adb} method
567 @cindex android
569 An Android device, which is connected via USB to your local host, can
570 be accessed via the @command{adb} command.  No user or host name is
571 needed.  The file name syntax is @file{@trampfn{adb,,/path/to/file}}.
574 @node Configuration
575 @chapter Configuring @value{tramp}
576 @cindex configuration
577 @cindex default configuration
579 @value{tramp} is initially configured to use the @command{scp} program
580 to connect to the remote host.  Just type @kbd{C-x C-f} and then enter
581 file name @file{@trampfn{scp,user@@host,/path/to/file}}.  For details,
582 @xref{Default Method}, @xref{Default User}, @xref{Default Host}.
584 For problems related to the behavior of the remote shell, @xref{Remote
585 shell setup}.
587 For changing the connection type and file access method from the
588 defaults to one of several other options, @xref{Connection types}.
590 @strong{Note} that some user options described in these examples are
591 not auto loaded by Emacs.  All examples require @value{tramp} is
592 installed and loaded:
594 @lisp
595 (customize-set-variable 'tramp-verbose 6 "Enable remote command traces")
596 @end lisp
599 @menu
600 * Connection types::            Types of connections to remote hosts.
601 * Inline methods::              Inline methods.
602 * External methods::            External methods.
603 * GVFS based methods::          GVFS based external methods.
604 * Default Method::              Selecting a default method.
605                                   Here we also try to help those who
606                                   don't have the foggiest which method
607                                   is right for them.
608 * Default User::                Selecting a default user.
609 * Default Host::                Selecting a default host.
610 * Multi-hops::                  Connecting to a remote host using multiple hops.
611 * Firewalls::                   Passing firewalls.
612 * Customizing Methods::         Using Non-Standard Methods.
613 * Customizing Completion::      Selecting config files for user/host name completion.
614 * Password handling::           Reusing passwords for several connections.
615 * Connection caching::          Reusing connection related information.
616 * Predefined connection information::
617                                 Setting own connection related information.
618 * Remote programs::             How @value{tramp} finds and uses programs on the remote host.
619 * Remote shell setup::          Remote shell setup hints.
620 * Android shell setup::         Android shell setup hints.
621 * Auto-save and Backup::        Auto-save and Backup.
622 * Windows setup hints::         Issues with Cygwin ssh.
623 @end menu
626 @node Connection types
627 @section Types of connections to remote hosts
628 @cindex connection types, overview
630 @dfn{Inline method} and @dfn{external method} are the two basic types
631 of access methods.  While they both use the same remote shell access
632 programs, such as @command{rsh}, @command{ssh}, or @command{telnet},
633 they differ in the file access methods.  Choosing the right method
634 becomes important for editing files, transferring large files, or
635 operating on a large number of files.
637 The performance of the external methods is generally better than that
638 of the inline methods, at least for large files.  This is caused by
639 the need to encode and decode the data when transferring inline.
641 The one exception to this rule are the @option{scp}-based access
642 methods.  While these methods do see better performance when actually
643 transferring files, the overhead of the cryptographic negotiation at
644 startup may drown out the improvement in file transfer times.
646 External methods should be configured such a way that they don't
647 require a password (with @command{ssh-agent}, or such alike).  Modern
648 @command{scp} implementations offer options to reuse existing
649 @command{ssh} connections, which will be enabled by default if
650 available.  If it isn't possible, you should consider @ref{Password
651 handling}, otherwise you will be prompted for a password every copy
652 action.
655 @node Inline methods
656 @section Inline methods
657 @cindex inline methods
658 @cindex methods, inline
660 Inline methods use the same login connection to transfer file
661 contents.  Inline methods are quick and easy for small files.  They
662 depend on the availability of suitable encoding and decoding programs
663 on the remote host.  For local source and destination, @value{tramp}
664 may use built-in equivalents of such programs in Emacs.
666 Inline methods can work in situations where an external transfer
667 program is unavailable.  Inline methods also work when transferring
668 files between different @emph{user identities} on the same host.
670 @cindex @command{uuencode}
671 @cindex @command{mimencode}
672 @cindex base-64 encoding
674 @value{tramp} checks the remote host for the availability and
675 usability of @command{mimencode} (part of the @command{metamail}
676 package) or @command{uuencode}.  @value{tramp} uses the first reliable
677 command it finds.  @value{tramp}'s search path can be customized, see
678 @ref{Remote programs}.
680 In case both @command{mimencode} and @command{uuencode} are
681 unavailable, @value{tramp} first transfers a small Perl program to the
682 remote host, and then tries that program for encoding and decoding.
684 To increase transfer speeds for large text files, use compression
685 before encoding.  The user option
686 @option{tramp-inline-compress-start-size} specifies the file size for
687 such optimization.
689 @table @asis
690 @item @option{rsh}
691 @cindex method @option{rsh}
692 @cindex @option{rsh} method
694 @command{rsh} is an option for connecting to hosts within local
695 networks since @command{rsh} is not as secure as other methods.
697 @item @option{ssh}
698 @cindex method @option{ssh}
699 @cindex @option{ssh} method
701 @command{ssh} is a more secure option than others to connect to a
702 remote host.
704 @command{ssh} can also take extra parameters as port numbers.  For
705 example, a host on port 42 is specified as @file{host#42} (the real
706 host name, a hash sign, then a port number).  It is the same as passing
707 @samp{-p 42} to the @command{ssh} command.
709 @item @option{telnet}
710 @cindex method @option{telnet}
711 @cindex @option{telnet} method
713 Connecting to a remote host with @command{telnet} is as insecure
714 as the @option{rsh} method.
716 @item @option{su}
717 @cindex method @option{su}
718 @cindex @option{su} method
720 Instead of connecting to a remote host, @command{su} program allows
721 editing as another user.  The host can be either @samp{localhost} or
722 the host returned by the function @command{(system-name)}.  See
723 @ref{Multi-hops} for an exception to this behavior.
725 @item @option{sudo}
726 @cindex method @option{sudo}
727 @cindex @option{sudo} method
729 Similar to @option{su} method, @option{sudo} uses @command{sudo}.
730 @command{sudo} must have sufficient rights to start a shell.
732 @item @option{doas}
733 @cindex method @option{doas}
734 @cindex @option{doas} method
736 This method is used on OpenBSD like the @command{sudo} command.
738 @item @option{sg}
739 @cindex method @option{sg}
740 @cindex @option{sg} method
742 The @command{sg} program allows editing as different group.  The host
743 can be either @samp{localhost} or the host returned by the function
744 @command{(system-name)}.  The user name must be specified, but it
745 denotes a group name.  See @ref{Multi-hops} for an exception to this
746 behavior.
748 @item @option{sshx}
749 @cindex method @option{sshx}
750 @cindex @option{sshx} method
752 Works like @option{ssh} but without the extra authentication prompts.
753 @option{sshx} uses @samp{ssh -t -t @var{host} -l @var{user} /bin/sh}
754 to open a connection with a ``standard'' login shell.
756 @strong{Note} that @option{sshx} does not bypass authentication
757 questions.  For example, if the host key of the remote host is not
758 known, @option{sshx} will still ask ``Are you sure you want to
759 continue connecting?''.  @value{tramp} cannot handle such questions.
760 Connections will have to be setup where logins can proceed without
761 such questions.
763 @option{sshx} is useful for MS Windows users when @command{ssh}
764 triggers an error about allocating a pseudo tty.  This happens due to
765 missing shell prompts that confuses @value{tramp}.
767 @option{sshx} supports the @samp{-p} argument.
769 @item @option{krlogin}
770 @cindex method @option{krlogin}
771 @cindex @option{krlogin} method
772 @cindex kerberos (with @option{krlogin} method)
774 This method is also similar to @option{ssh}.  It uses the
775 @command{krlogin -x} command only for remote host login.
777 @item @option{ksu}
778 @cindex method @option{ksu}
779 @cindex @option{ksu} method
780 @cindex kerberos (with @option{ksu} method)
782 This is another method from the Kerberos suite.  It behaves like @option{su}.
784 @item @option{plink}
785 @cindex method @option{plink}
786 @cindex @option{plink} method
788 @option{plink} method is for MS Windows users with the PuTTY
789 implementation of SSH@.  It uses @samp{plink -ssh} to log in to the
790 remote host.
792 Check the @samp{Share SSH connections if possible} control for that
793 session.
795 @option{plink} method supports the @samp{-P} argument.
797 @item @option{plinkx}
798 @cindex method @option{plinkx}
799 @cindex @option{plinkx} method
801 Another method using PuTTY on MS Windows with session names instead of
802 host names.  @option{plinkx} calls @samp{plink -load @var{session}
803 -t}.  User names and port numbers must be defined in the session.
805 Check the @samp{Share SSH connections if possible} control for that
806 session.
808 @end table
811 @node External methods
812 @section External methods
813 @cindex methods, external
814 @cindex external methods
816 External methods operate over multiple channels, using the remote
817 shell connection for some actions while delegating file transfers to
818 an external transfer program.
820 External methods save on the overhead of encoding and decoding of
821 inline methods.
823 Since external methods have the overhead of opening a new channel,
824 files smaller than @var{tramp-copy-size-limit} still use inline
825 methods.
827 @table @asis
828 @item @option{rcp}
829 @cindex method @option{rcp}
830 @cindex @option{rcp} method
831 @cindex @command{rsh} (with @option{rcp} method)
833 This method uses the @command{rsh} and @command{rcp} commands to
834 connect to the remote host and transfer files.  This is the fastest
835 access method available.
837 The alternative method @option{remcp} uses the @command{remsh} and
838 @command{rcp} commands.
840 @item @option{scp}
841 @cindex method @option{scp}
842 @cindex @option{scp} method
843 @cindex @command{ssh} (with @option{scp} method)
845 Using a combination of @command{ssh} to connect and @command{scp} to
846 transfer is the most secure.  While the performance is good, it is
847 slower than the inline methods for smaller files.  Though there is no
848 overhead of encoding and decoding of the inline methods,
849 @command{scp}'s cryptographic handshake negates those speed gains.
851 @option{ssh}-based methods support @samp{-p} feature for specifying
852 port numbers.  For example, @file{host#42} passes @samp{-p 42} in the
853 argument list to @command{ssh}, and @samp{-P 42} in the argument list
854 to @command{scp}.
856 @item @option{rsync}
857 @cindex method @option{rsync}
858 @cindex @option{rsync} method
859 @cindex @command{ssh} (with @option{rsync} method)
861 @command{ssh} command to connect in combination with @command{rsync}
862 command to transfer is similar to the @option{scp} method.
864 @command{rsync} performs much better than @command{scp} when
865 transferring files that exist on both hosts.  However, this advantage
866 is lost if the file exists only on one side of the connection.
868 This method supports the @samp{-p} argument.
870 @item @option{scpx}
871 @cindex method @option{scpx}
872 @cindex @option{scpx} method
873 @cindex @command{ssh} (with @option{scpx} method)
875 @option{scpx} is useful to avoid login shell questions.  It is similar
876 in performance to @option{scp}.  @option{scpx} uses @samp{ssh -t -t
877 @var{host} -l @var{user} /bin/sh} to open a connection.
879 @option{scpx} is useful for MS Windows users when @command{ssh}
880 triggers an error about allocating a pseudo tty.  This happens due to
881 missing shell prompts that confuses @value{tramp}.
883 This method supports the @samp{-p} argument.
885 @item @option{pscp}
886 @item @option{psftp}
887 @cindex method @option{pscp}
888 @cindex @option{pscp} method
889 @cindex @command{plink} (with @option{pscp} method)
890 @cindex @command{putty} (with @option{pscp} method)
891 @cindex method @option{psftp}
892 @cindex @option{psftp} method
893 @cindex @command{plink} (with @option{psftp} method)
894 @cindex @command{putty} (with @option{psftp} method)
896 These methods are similar to @option{scp} or @option{sftp}, but they
897 use the @command{plink} command to connect to the remote host, and
898 they use @command{pscp} or @command{psftp} for transferring the files.
899 These programs are part of PuTTY, an SSH implementation for MS Windows.
901 Check the @samp{Share SSH connections if possible} control for that
902 session.
904 These methods support the @samp{-P} argument.
906 @item @option{fcp}
907 @cindex method @option{fcp}
908 @cindex @option{fcp} method
909 @cindex @command{fsh} (with @option{fcp} method)
911 This method is similar to @option{scp}, but uses @command{fsh} to
912 connect and @command{fcp} to transfer files.  @command{fsh/fcp}, a
913 front-end for @command{ssh}, reuse @command{ssh} session by
914 submitting several commands.  This avoids the startup overhead due to
915 @command{scp}'s secure connection.  Inline methods have similar
916 benefits.
918 The command used for this connection is: @samp{fsh @var{host} -l
919 @var{user} /bin/sh -i}
921 @cindex method @option{fsh}
922 @cindex @option{fsh} method
924 @option{fsh} has no inline method since the multiplexing it offers is
925 not useful for @value{tramp}.  @command{fsh} connects to remote host
926 and @value{tramp} keeps that one connection open.
928 @item @option{nc}
929 @cindex method @option{nc}
930 @cindex @option{nc} method
931 @cindex @command{telnet} (with @option{nc} method)
933 Using @command{telnet} to connect and @command{nc} to transfer files
934 is sometimes the only combination suitable for accessing routers or
935 NAS hosts.  These dumb devices have severely restricted local shells,
936 such as the @command{busybox} and do not host any other encode or
937 decode programs.
939 @item @option{ftp}
940 @cindex method @option{ftp}
941 @cindex @option{ftp} method
943 When @value{tramp} uses @option{ftp}, it forwards requests to whatever
944 ftp program is specified by Ange FTP.  This external program must be
945 capable of servicing requests from @value{tramp}.
947 @item @option{smb}
948 @cindex method @option{smb}
949 @cindex @option{smb} method
950 @cindex ms windows (with @option{smb} method)
951 @cindex @command{smbclient}
953 This non-native @value{tramp} method connects via the Server Message
954 Block (SMB) networking protocol to hosts running file servers that are
955 typically based on @url{https://www.samba.org/,,Samba} or MS Windows.
957 Using @command{smbclient} requires a few tweaks when working with
958 @value{tramp}:
960 The first directory in the localname must be a share name on the
961 remote host.
963 Since some SMB share names end in the @code{$} character,
964 @value{tramp} must use @code{$$} when specifying those shares to avoid
965 environment variable substitutions.
967 When @value{tramp} is not specific about the share name or uses the
968 generic remote directory @file{/}, @command{smbclient} returns all
969 available shares.
971 Since SMB authentication is based on each SMB share, @value{tramp}
972 prompts for a password even when accessing a different share on the
973 same SMB host.  This prompting can be suppressed by @ref{Password
974 handling}.
976 To accommodate user name/domain name syntax required by MS Windows
977 authorization, @value{tramp} provides for an extended syntax in
978 @code{user%domain} format (where @code{user} is the user name,
979 @code{%} is the percent symbol, and @code{domain} is the MS Windows
980 domain name).  An example:
982 @example
983 @trampfn{smb,daniel%BIZARRE@@melancholia,/daniel$$/.emacs}
984 @end example
986 where user @code{daniel} connects as a domain user to the SMB host
987 @code{melancholia} in the MS Windows domain @code{BIZARRE} to edit
988 @file{.emacs} located in the home directory (share @code{daniel$}).
990 Alternatively, for local WINS users (as opposed to domain users),
991 substitute the domain name with the name of the local host in
992 UPPERCASE as shown here:
994 @example
995 @trampfn{smb,daniel%MELANCHOLIA@@melancholia,/daniel$$/.emacs}
996 @end example
998 where user @code{daniel} connects as local user to the SMB host
999 @code{melancholia} in the local domain @code{MELANCHOLIA} to edit
1000 @file{.emacs} located in the home directory (share @code{daniel$}).
1002 The domain name and user name are optional for @command{smbclient}
1003 authentication.  When user name is not specified, @command{smbclient}
1004 uses the anonymous user (without prompting for password).  This
1005 behavior is unlike other @value{tramp} methods, where local user name
1006 is substituted.
1008 The @option{smb} method is unavailable if Emacs is run under a local
1009 user authentication context in MS Windows.  However such users can
1010 still access remote files using UNC file names instead of @value{tramp}:
1012 @example
1013 //melancholia/daniel$$/.emacs
1014 @end example
1016 UNC file name specification does not allow the specification of a
1017 different user name for authentication like the @command{smbclient}
1018 can.
1021 @item @option{adb}
1022 @cindex method @option{adb}
1023 @cindex @option{adb} method
1024 @cindex android (with @option{adb} method)
1026 This method uses Android Debug Bridge program for accessing Android
1027 devices.  The Android Debug Bridge must be installed locally for
1028 @value{tramp} to work.  Some GNU/Linux distributions provide Android
1029 Debug Bridge as an installation package.  Alternatively, the program
1030 is installed as part of the Android SDK@.  @value{tramp} finds the
1031 @command{adb} program either via the @env{PATH} environment variable
1032 or the absolute path set in the user option @option{tramp-adb-program}.
1034 @value{tramp} connects to Android devices with @option{adb} only when
1035 the user option @option{tramp-adb-connect-if-not-connected} is not
1036 @code{nil}.  Otherwise, the connection must be established outside
1037 Emacs.
1039 @value{tramp} does not require a host name part of the remote file
1040 name when a single Android device is connected to @command{adb}.
1041 @value{tramp} instead uses @file{@trampfn{adb,,}} as the default name.
1042 @command{adb devices} shows available host names.
1044 @option{adb} method normally does not need user name to authenticate
1045 on the Android device because it runs under the @command{adbd}
1046 process.  But when a user name is specified, however, @value{tramp}
1047 applies an @command{su} in the syntax.  When authentication does not
1048 succeed, especially on un-rooted Android devices, @value{tramp}
1049 displays login errors.
1051 For Android devices connected through TCP/IP, a port number can be
1052 specified using @file{device#42} host name syntax or @value{tramp} can
1053 use the default value as declared in @command{adb} command.  Port
1054 numbers are not applicable to Android devices connected through USB@.
1056 @end table
1059 @node GVFS based methods
1060 @section GVFS based external methods
1061 @cindex methods, gvfs
1062 @cindex gvfs based methods
1063 @cindex dbus
1065 GVFS is the virtual file system for the @acronym{GNOME} Desktop,
1066 @uref{https://en.wikipedia.org/wiki/GVFS}.  Remote files on GVFS are
1067 mounted locally through FUSE and @value{tramp} uses this locally
1068 mounted directory internally.
1070 Emacs uses the D-Bus mechanism to communicate with GVFS@.  Emacs must
1071 have the message bus system, D-Bus integration active, @pxref{Top, ,
1072 D-Bus, dbus}.
1074 @table @asis
1075 @item @option{afp}
1076 @cindex method @option{afp}
1077 @cindex @option{afp} method
1079 This method is for connecting to remote hosts with the Apple Filing
1080 Protocol for accessing files on macOS volumes.  @value{tramp} access
1081 syntax requires a leading volume (share) name, for example:
1082 @file{@trampfn{afp,user@@host,/volume}}.
1084 @item @option{dav}
1085 @item @option{davs}
1086 @cindex method @option{dav}
1087 @cindex method @option{davs}
1088 @cindex @option{dav} method
1089 @cindex @option{davs} method
1091 @option{dav} method provides access to WebDAV files and directories
1092 based on standard protocols, such as HTTP@.  @option{davs} does the same
1093 but with SSL encryption.  Both methods support the port numbers.
1095 @item @option{gdrive}
1096 @cindex method @option{gdrive}
1097 @cindex @option{gdrive} method
1098 @cindex google drive
1100 Via the @option{gdrive} method it is possible to access your Google
1101 Drive online storage.  User and host name of the remote file name are
1102 your email address of the Google Drive credentials, like
1103 @file{@trampfn{gdrive,john.doe@@gmail.com,/}}.  These credentials must
1104 be populated in your @command{Online Accounts} application outside Emacs.
1106 Since Google Drive uses cryptic blob file names internally,
1107 @value{tramp} works with the @code{display-name} of the files.  This
1108 could produce unexpected behavior in case two files in the same
1109 directory have the same @code{display-name}, such a situation must be avoided.
1111 @item @option{obex}
1112 @cindex method @option{obex}
1113 @cindex @option{obex} method
1115 OBEX is an FTP-like access protocol for cell phones and similar simple
1116 devices.  @value{tramp} supports OBEX over Bluetooth.
1118 @item @option{owncloud}
1119 @cindex @acronym{GNOME} Online Accounts
1120 @cindex method @option{owncloud}
1121 @cindex @option{owncloud} method
1122 @cindex nextcloud
1124 As the name indicates, the method @option{owncloud} allows you to
1125 access OwnCloud or NextCloud hosted files and directories.  Like the
1126 @option{gdrive} method, your credentials must be populated in your
1127 @command{Online Accounts} application outside Emacs. The method
1128 supports port numbers.
1130 @item @option{sftp}
1131 @cindex method @option{sftp}
1132 @cindex @option{sftp} method
1134 This method uses @command{sftp} in order to securely access remote
1135 hosts.  @command{sftp} is a more secure option for connecting to hosts
1136 that for security reasons refuse @command{ssh} connections.
1138 @item @option{synce}
1139 @cindex method @option{synce}
1140 @cindex @option{synce} method
1142 @option{synce} method allows connecting to MS Windows Mobile devices.
1143 It uses GVFS for mounting remote files and directories via FUSE and
1144 requires the SYNCE-GVFS plugin.
1146 @end table
1148 @defopt tramp-gvfs-methods
1149 This user option is a list of external methods for GVFS@.  By default,
1150 this list includes @option{afp}, @option{dav}, @option{davs},
1151 @option{gdrive}, @option{obex}, @option{owncloud}, @option{sftp} and
1152 @option{synce}.  Other methods to include are @option{ftp},
1153 @option{http}, @option{https} and @option{smb}.  These methods are not
1154 intended to be used directly as GVFS based method.  Instead, they are
1155 added here for the benefit of @ref{Archive file names}.
1156 @end defopt
1159 @node Default Method
1160 @section Selecting a default method
1161 @cindex default method
1163 In a remote file name, the use of a default method is indicated by the
1164 pseudo method @option{-}, @ref{File name syntax}.
1166 @defopt tramp-default-method
1167 Default method is for transferring files.  The user option
1168 @option{tramp-default-method} sets it.  @value{tramp} uses this user
1169 option to determine the default method for remote file names that do
1170 not have one specified.
1172 @lisp
1173 (customize-set-variable 'tramp-default-method "ssh")
1174 @end lisp
1175 @end defopt
1177 @defopt tramp-default-method-alist
1178 Default methods for transferring files can be customized for specific
1179 user and host combinations through the user option
1180 @option{tramp-default-method-alist}.
1182 For example, the following two lines specify to use the @option{ssh}
1183 method for all user names matching @samp{john} and the @option{rsync}
1184 method for all host names matching @samp{lily}.  The third line
1185 specifies to use the @option{su} method for the user @samp{root} on
1186 the host @samp{localhost}.
1188 @lisp
1189 @group
1190 (add-to-list 'tramp-default-method-alist '("" "john" "ssh"))
1191 (add-to-list 'tramp-default-method-alist '("lily" "" "rsync"))
1192 (add-to-list 'tramp-default-method-alist
1193              '("\\`localhost\\'" "\\`root\\'" "su"))
1194 @end group
1195 @end lisp
1196 @end defopt
1198 @noindent
1199 External methods performance faster for large files.  @pxref{Inline
1200 methods}.  @pxref{External methods}.
1202 Choosing the access method also depends on the security environment.
1203 For example, @option{rsh} and @option{telnet} methods that use clear
1204 text password transfers are inappropriate for over the Internet
1205 connections.  Secure remote connections should use @option{ssh} that
1206 provide encryption.
1209 @subsection Which method to use?
1210 @cindex choosing the right method
1212 @value{tramp} provides maximum number of choices for maximum
1213 flexibility.  Choosing which method depends on the hosts, clients,
1214 network speeds, and the security context.
1216 Start by using an inline method.
1218 External methods might be more efficient for large files, but most
1219 @value{tramp} users edit small files more often than large files.
1221 Enable compression, @var{tramp-inline-compress-start-size}, for a
1222 performance boost for large files.
1224 Since @command{ssh} has become the most common method of remote host
1225 access and it has the most reasonable security protocols, use
1226 @option{ssh} method.  Typical @option{ssh} usage to edit the
1227 @file{/etc/motd} file on the otherhost:
1229 @example
1230 @kbd{C-x C-f @trampfn{ssh,root@@otherhost,/etc/motd} @key{RET}}
1231 @end example
1233 If @option{ssh} is unavailable for whatever reason, look for other
1234 obvious options.  For MS Windows, try the @option{plink} method.  For
1235 Kerberos, try @option{krlogin}.
1237 For editing local files as @option{su} or @option{sudo} methods, try
1238 the shortened syntax of @samp{root}:
1240 @example
1241 @kbd{C-x C-f @trampfn{su,,/etc/motd} @key{RET}}
1242 @end example
1244 For editing large files, @option{scp} is faster than @option{ssh}.
1245 @option{pscp} is faster than @option{plink}.  But this speed
1246 improvement is not always true.
1249 @node Default User
1250 @section Selecting a default user
1251 @cindex default user
1253 @defopt tramp-default-user
1254 @value{tramp} file name can omit the user name part since
1255 @value{tramp} substitutes the currently logged-in user name.  However
1256 this substitution can be overridden with @option{tramp-default-user}.
1257 For example:
1259 @lisp
1260 (customize-set-variable 'tramp-default-user "root")
1261 @end lisp
1262 @end defopt
1264 @defopt tramp-default-user-alist
1265 Instead of a single default user, @option{tramp-default-user-alist}
1266 allows multiple default user values based on access method or host
1267 name combinations.  The alist can hold multiple values.  For example, to
1268 use the @samp{john} as the default user for the domain
1269 @samp{somewhere.else} only:
1271 @lisp
1272 @group
1273 (add-to-list 'tramp-default-user-alist
1274              '("ssh" ".*\\.somewhere\\.else\\'" "john"))
1275 @end group
1276 @end lisp
1278 A Caution: @value{tramp} will override any default user specified in
1279 the configuration files outside Emacs, such as @file{~/.ssh/config}.
1280 To stop @value{tramp} from applying the default value, set the
1281 corresponding alist entry to nil:
1283 @lisp
1284 @group
1285 (add-to-list 'tramp-default-user-alist
1286              '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
1287 @end group
1288 @end lisp
1290 The last entry in @option{tramp-default-user-alist} should be reserved
1291 for catch-all or most often used login.
1293 @lisp
1294 @group
1295 (add-to-list 'tramp-default-user-alist
1296              '(nil nil "jonas") t)
1297 @end group
1298 @end lisp
1299 @end defopt
1302 @node Default Host
1303 @section Selecting a default host
1304 @cindex default host
1306 @defopt tramp-default-host
1307 When host name is omitted, @value{tramp} substitutes the value from
1308 the @option{tramp-default-host} user option.  It is initially
1309 populated with the local host name where Emacs is running.  The
1310 default method, default user and default host can be overridden as
1311 follows:
1313 @lisp
1314 @group
1315 (custom-set-variables
1316  '(tramp-default-method "ssh")
1317  '(tramp-default-user "john")
1318  '(tramp-default-host "target"))
1319 @end group
1320 @end lisp
1322 With all defaults set, @samp{@trampfn{-,,}} will connect @value{tramp}
1323 to John's home directory on @code{target} via @code{ssh}.
1324 @end defopt
1326 @defopt tramp-default-host-alist
1327 Instead of a single default host, @option{tramp-default-host-alist}
1328 allows multiple default host values based on access method or user
1329 name combinations.  The alist can hold multiple values.  While
1330 @option{tramp-default-host} is sufficient in most cases, some methods,
1331 like @option{adb}, require defaults overwritten.
1332 @end defopt
1335 @node Multi-hops
1336 @section Connecting to a remote host using multiple hops
1337 @cindex multi-hop
1338 @cindex proxy hosts
1340 Multi-hops are methods to reach hosts behind firewalls or to reach the
1341 outside world from inside a bastion host.  With multi-hops,
1342 @value{tramp} can negotiate these hops with the appropriate user/host
1343 authentication at each hop.  All methods until now have been the single
1344 hop kind, where the start and end points of the connection did not
1345 have intermediate check points.
1347 @defopt tramp-default-proxies-alist
1348 @option{tramp-default-proxies-alist} specifies proxy hosts to pass
1349 through.  This user option is list of triples consisting of
1350 @code{(@var{host} @var{user} @var{proxy})}.
1352 The first match is the proxy host through which passes the file name
1353 and the target host matching @var{user}@@@var{host}.  @var{host} and
1354 @var{user} are regular expressions or @code{nil}, interpreted as a
1355 regular expression which always matches.
1357 @var{proxy} is a literal @value{tramp} file name whose local name part
1358 is ignored, and the method and user name parts are optional.
1360 The method must be an inline method (@pxref{Inline methods}).  If
1361 @var{proxy} is @code{nil}, no additional hop is required reaching
1362 @var{user}@@@var{host}.
1364 For example, to pass through the host @samp{bastion.your.domain} as
1365 user @samp{bird} to reach remote hosts outside the local domain:
1367 @lisp
1368 @group
1369 (add-to-list 'tramp-default-proxies-alist
1370              '("\\." nil "@trampfn{ssh,bird@@bastion.your.domain,}"))
1371 (add-to-list 'tramp-default-proxies-alist
1372              '("\\.your\\.domain\\'" nil nil))
1373 @end group
1374 @end lisp
1376 @strong{Note}: @code{add-to-list} adds elements at the beginning of a
1377 list.  Therefore, most relevant rules must come last in the list.
1379 Proxy hosts can be cascaded in the alist.  If there is another host
1380 called @samp{jump.your.domain}, which is the only host allowed to
1381 connect to @samp{bastion.your.domain}, then:
1383 @lisp
1384 @group
1385 (add-to-list 'tramp-default-proxies-alist
1386              '("\\`bastion\\.your\\.domain\\'"
1387                "\\`bird\\'"
1388                "@trampfn{ssh,jump.your.domain,}"))
1389 @end group
1390 @end lisp
1392 @var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
1393 @var{user} respectively.
1395 To login as @samp{root} on remote hosts in the domain
1396 @samp{your.domain}, but login as @samp{root} is disabled for non-local
1397 access, then use this alist entry:
1399 @lisp
1400 @group
1401 (add-to-list 'tramp-default-proxies-alist
1402              '("\\.your\\.domain\\'" "\\`root\\'" "@trampfn{ssh,%h,}"))
1403 @end group
1404 @end lisp
1406 Opening @file{@trampfn{sudo,randomhost.your.domain,}} first connects
1407 to @samp{randomhost.your.domain} via @code{ssh} under your account
1408 name, and then performs @code{sudo -u root} on that host.
1410 It is key for the sudo method in the above example to be applied on
1411 the host after reaching it and not on the local host.
1413 @var{host}, @var{user} and @var{proxy} can also take Lisp forms.  These
1414 forms when evaluated must return either a string or @code{nil}.
1416 To generalize (from the previous example): For all hosts, except my
1417 local one, first connect via @command{ssh}, and then apply
1418 @command{sudo -u root}:
1420 @lisp
1421 @group
1422 (add-to-list 'tramp-default-proxies-alist
1423              '(nil "\\`root\\'" "@trampfn{ssh,%h,}"))
1424 (add-to-list 'tramp-default-proxies-alist
1425              '((regexp-quote (system-name)) nil nil))
1426 @end group
1427 @end lisp
1428 @end defopt
1430 Passing through hops involves dealing with restricted shells, such as
1431 @command{rbash}.  If @value{tramp} is made aware, then it would use
1432 them for proxies only.
1434 @defopt tramp-restricted-shell-hosts-alist
1435 An alist of regular expressions of hosts running restricted shells,
1436 such as @command{rbash}.  @value{tramp} will then use them only as
1437 proxies.
1439 To specify the bastion host from the example above as running a
1440 restricted shell:
1442 @lisp
1443 @group
1444 (add-to-list 'tramp-restricted-shell-hosts-alist
1445              "\\`bastion\\.your\\.domain\\'")
1446 @end group
1447 @end lisp
1448 @end defopt
1451 @node Firewalls
1452 @section Passing firewalls
1453 @cindex http tunnel
1454 @cindex proxy hosts, http tunnel
1456 Sometimes, it is not possible to reach a remote host directly.  A
1457 firewall might be in the way, which could be passed via a proxy
1458 server.
1460 Both ssh and PuTTY support such proxy settings, using an HTTP tunnel
1461 via the @command{CONNECT} command (conforming to RFC 2616, 2817
1462 specifications).  Proxy servers using HTTP version 1.1 or later
1463 protocol support this command.
1465 @subsection Tunneling with ssh
1467 With ssh, you could use the @code{ProxyCommand} entry in the
1468 @file{~/.ssh/config}:
1470 @example
1471 @group
1472 Host host.other.domain
1473      ProxyCommand nc -X connect -x proxy.your.domain:3128 %h %p
1474 @end group
1475 @end example
1477 @code{nc} is BSD's netcat program, which establishes HTTP tunnels. Any
1478 other program with such a feature could be used as well.
1480 In the example, opening @file{@trampfn{ssh,host.your.domain,}} passes
1481 the HTTP proxy server @samp{proxy.your.domain} on port 3128.
1483 @subsection Tunneling with PuTTY
1485 PuTTY does not need an external program, HTTP tunnel support is
1486 built-in.  In the PuTTY config program, create a session for
1487 @samp{host.your.domain}.  In the @option{Connection/Data} entry,
1488 select the @option{HTTP} option, and add @samp{proxy.your.domain} as
1489 @option{Proxy hostname}, and 3128 as @option{Port}.
1491 Opening @file{@trampfn{plinkx,host.your.domain,}} passes the HTTP
1492 proxy server @samp{proxy.your.domain} on port 3128.
1495 @node Customizing Methods
1496 @section Using Non-Standard Methods
1497 @cindex customizing methods
1498 @cindex using non-standard methods
1499 @cindex create your own methods
1501 The @code{tramp-methods} variable currently has an exhaustive list of
1502 predefined methods.  Any part of this list can be modified with more
1503 suitable settings.  Refer to the Lisp documentation of that variable,
1504 accessible with @kbd{C-h v tramp-methods @key{RET}}.
1507 @node Customizing Completion
1508 @section Selecting config files for user/host name completion
1509 @cindex customizing completion
1510 @cindex selecting config files
1511 @vindex tramp-completion-function-alist
1513 @code{tramp-completion-function-alist} uses predefined files for user
1514 and host name completion (@pxref{File name completion}).  For each
1515 method, it keeps a set of configuration files and a function that can
1516 parse that file.  Each entry in @code{tramp-completion-function-alist}
1517 is of the form (@var{method} @var{pair1} @var{pair2} @dots{}).
1519 Each @var{pair} is composed of (@var{function} @var{file}).
1520 @var{function} is responsible for extracting user names and host names
1521 from @var{file} for completion.  There are two functions which access
1522 this variable:
1524 @defun tramp-get-completion-function method
1525 This function returns the list of completion functions for @var{method}.
1527 Example:
1528 @example
1529 @group
1530 (tramp-get-completion-function "rsh")
1532      @result{} ((tramp-parse-rhosts "/etc/hosts.equiv")
1533          (tramp-parse-rhosts "~/.rhosts"))
1534 @end group
1535 @end example
1536 @end defun
1538 @defun tramp-set-completion-function method function-list
1539 This function sets @var{function-list} as list of completion functions
1540 for @var{method}.
1542 Example:
1543 @example
1544 @group
1545 (tramp-set-completion-function "ssh"
1546  '((tramp-parse-sconfig "/etc/ssh_config")
1547    (tramp-parse-sconfig "~/.ssh/config")))
1549      @result{} ((tramp-parse-sconfig "/etc/ssh_config")
1550          (tramp-parse-sconfig "~/.ssh/config"))
1551 @end group
1552 @end example
1553 @end defun
1555 The following predefined functions parsing configuration files exist:
1557 @table @asis
1558 @item @code{tramp-parse-rhosts}
1559 @findex tramp-parse-rhosts
1561 This function parses files which are syntactical equivalent to
1562 @file{~/.rhosts}.  It returns both host names and user names, if
1563 specified.
1565 @item @code{tramp-parse-shosts}
1566 @findex tramp-parse-shosts
1568 This function parses files which are syntactical equivalent to
1569 @file{~/.ssh/known_hosts}.  Since there are no user names specified
1570 in such files, it can return host names only.
1572 @item @code{tramp-parse-sconfig}
1573 @findex tramp-parse-sconfig
1575 This function returns the host nicknames defined by @code{Host} entries
1576 in @file{~/.ssh/config} style files.
1578 @item @code{tramp-parse-shostkeys}
1579 @findex tramp-parse-shostkeys
1581 SSH2 parsing of directories @file{/etc/ssh2/hostkeys/*} and
1582 @file{~/ssh2/hostkeys/*}.  Hosts are coded in file names
1583 @file{hostkey_@var{portnumber}_@var{host-name}.pub}.  User names
1584 are always @code{nil}.
1586 @item @code{tramp-parse-sknownhosts}
1587 @findex tramp-parse-sknownhosts
1589 Another SSH2 style parsing of directories like
1590 @file{/etc/ssh2/knownhosts/*} and @file{~/ssh2/knownhosts/*}.  This
1591 case, hosts names are coded in file names
1592 @file{@var{host-name}.@var{algorithm}.pub}.  User names are always @code{nil}.
1594 @item @code{tramp-parse-hosts}
1595 @findex tramp-parse-hosts
1597 A function dedicated to @file{/etc/hosts} for host names.
1599 @item @code{tramp-parse-passwd}
1600 @findex tramp-parse-passwd
1602 A function which parses @file{/etc/passwd} files for user names.
1604 @item @code{tramp-parse-etc-group}
1605 @findex tramp-parse-etc-group
1607 A function which parses @file{/etc/group} files for group names.
1609 @item @code{tramp-parse-netrc}
1610 @findex tramp-parse-netrc
1612 A function which parses @file{~/.netrc} and @file{~/.authinfo}-style files.
1614 @end table
1616 To keep a custom file with custom data in a custom structure, a custom
1617 function has to be provided.  This function must meet the following
1618 conventions:
1620 @defun my-tramp-parse file
1621 @var{file} must be either a file on the host, or @code{nil}.  The
1622 function must return a list of (@var{user} @var{host}), which are
1623 taken as candidates for completion for user and host names.
1625 Example:
1626 @example
1627 @group
1628 (my-tramp-parse "~/.my-tramp-hosts")
1630      @result{} ((nil "toto") ("daniel" "melancholia"))
1631 @end group
1632 @end example
1633 @end defun
1636 @node Password handling
1637 @section Reusing passwords for several connections
1638 @cindex passwords
1640 To avoid repeated prompts for passwords, consider native caching
1641 mechanisms, such as @command{ssh-agent} for @option{ssh}-like
1642 methods, or @command{pageant} for @option{plink}-like methods.
1644 @value{tramp} offers alternatives when native solutions cannot meet
1645 the need.
1648 @anchor{Using an authentication file}
1649 @subsection Using an authentication file
1650 @vindex auth-sources
1652 The package @file{auth-source.el}, originally developed for No Gnus,
1653 reads passwords from different sources, @xref{Help for users, ,
1654 auth-source, auth}.  The default authentication file is
1655 @file{~/.authinfo.gpg}, but this can be changed via the variable
1656 @code{auth-sources}.
1658 @noindent
1659 A typical entry in the authentication file:
1661 @example
1662 machine melancholia port scp login daniel password geheim
1663 @end example
1665 The port can take any @value{tramp} method (@pxref{Inline methods},
1666 @pxref{External methods}).  Omitting port values matches all
1667 @value{tramp} methods.  Domain and ports, as used in @value{tramp}
1668 file name syntax, must be appended to the machine and login items:
1670 @example
1671 machine melancholia#4711 port davs login daniel%BIZARRE password geheim
1672 @end example
1674 @vindex auth-source-debug
1675 Set @code{auth-source-debug} to @code{t} to debug messages.
1678 @anchor{Caching passwords}
1679 @subsection Caching passwords
1681 @value{tramp} can cache passwords as entered and reuse when needed for
1682 the same user or host name independent of the access method.
1684 @vindex password-cache-expiry
1685 @code{password-cache-expiry} sets the duration (in seconds) the
1686 passwords are remembered.  Passwords are never saved permanently nor
1687 can they extend beyond the lifetime of the current Emacs session.  Set
1688 @code{password-cache-expiry} to @code{nil} to disable expiration.
1690 @vindex password-cache
1691 Set @code{password-cache} to @code{nil} to disable password caching.
1694 @node Connection caching
1695 @section Reusing connection related information
1696 @cindex caching
1697 @vindex tramp-persistency-file-name
1699 For faster initial connection times, @value{tramp} stores previous
1700 connection properties in a file specified by the user option
1701 @option{tramp-persistency-file-name}.
1703 The default file name for @option{tramp-persistency-file-name} is
1704 @file{~/.emacs.d/tramp}.
1706 @value{tramp} reads this file during Emacs startup, and writes to it
1707 when exiting Emacs.  Delete this file for @value{tramp} to recreate a
1708 new one on next Emacs startup.
1710 Set @option{tramp-persistency-file-name} to @code{nil} to disable
1711 storing connections persistently.
1713 When @value{tramp} detects a change in the operating system version in
1714 a remote host (via the command @command{uname -sr}), it flushes all
1715 connection related information for that host and creates a new entry.
1718 @node Predefined connection information
1719 @section Setting own connection related information
1720 @vindex tramp-connection-properties
1722 For more precise customization, parameters specified by
1723 @code{tramp-methods} can be overwritten manually.
1725 Set @option{tramp-connection-properties} to manually override
1726 @code{tramp-methods}.  Properties in this list are in the form
1727 @code{(@var{regexp} @var{property} @var{value})}.  @var{regexp}
1728 matches remote file names.  Use @code{nil} to match all.
1729 @var{property} is the property's name, and @var{value} is the
1730 property's value.
1732 @var{property} is any method specific parameter contained in
1733 @code{tramp-methods}.  The parameter key in @code{tramp-methods} is a
1734 symbol name @code{tramp-<foo>}.  To overwrite that property, use the
1735 string @samp{<foo>} for @var{property}.  For example, this changes the
1736 remote shell:
1738 @lisp
1739 @group
1740 (add-to-list 'tramp-connection-properties
1741              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1742                    "remote-shell" "/bin/ksh"))
1743 @end group
1745 @group
1746 (add-to-list 'tramp-connection-properties
1747              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1748                    "remote-shell-login" '("-")))
1749 @end group
1750 @end lisp
1752 The parameters @code{tramp-remote-shell} and
1753 @code{tramp-remote-shell-login} in @code{tramp-methods} now have new
1754 values for the remote host.
1756 @var{property} could also be any property found in
1757 @option{tramp-persistency-file-name}.
1759 To get around how restricted shells randomly drop connections, set the
1760 special property @samp{busybox}.  For example:
1762 @lisp
1763 @group
1764 (add-to-list 'tramp-connection-properties
1765              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1766                    "busybox" t))
1767 @end group
1768 @end lisp
1771 @node Remote programs
1772 @section How @value{tramp} finds and uses programs on the remote host
1774 @value{tramp} requires access to and rights to several commands on
1775 remote hosts: @command{ls}, @command{test}, @command{find} and
1776 @command{cat}.
1778 Besides there are other required programs for @ref{Inline methods} and
1779 @ref{External methods} of connection.
1781 To improve performance and accuracy of remote file access,
1782 @value{tramp} uses @command{perl} (or @command{perl5}) and
1783 @command{grep} when available.
1785 @defopt tramp-remote-path
1786 @option{tramp-remote-path} specifies which remote directory paths
1787 @value{tramp} can search for @ref{Remote programs}.
1789 @vindex tramp-default-remote-path
1790 @value{tramp} uses standard defaults, such as @file{/bin} and
1791 @file{/usr/bin}, which are reasonable for most hosts.  To accommodate
1792 differences in hosts and paths, for example, @file{/bin:/usr/bin} on
1793 Debian GNU/Linux or
1794 @file{/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin} on
1795 Solaris, @value{tramp} queries the remote host with @command{getconf
1796 PATH} and updates the symbol @code{tramp-default-remote-path}.
1798 For instances where hosts keep obscure locations for paths for
1799 security reasons, manually add such paths to local @file{.emacs} as
1800 shown below for @value{tramp} to use when connecting.
1802 @lisp
1803 (add-to-list 'tramp-remote-path "/usr/local/perl/bin")
1804 @end lisp
1806 @vindex tramp-own-remote-path
1807 Another way to find the remote path is to use the path assigned to the
1808 remote user by the remote host.  @value{tramp} does not normally retain
1809 this remote path after login.  However, @code{tramp-own-remote-path}
1810 preserves the path value, which can be used to update
1811 @option{tramp-remote-path}.
1813 @lisp
1814 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1815 @end lisp
1817 @strong{Note} that this works only if your remote @command{/bin/sh}
1818 shell supports the login argument @samp{-l}.
1819 @end defopt
1821 When remote search paths are changed, local @value{tramp} caches must
1822 be recomputed.  To force @value{tramp} to recompute afresh, exit
1823 Emacs, remove the persistent file (@pxref{Connection caching}), and
1824 restart Emacs.
1827 @node Remote shell setup
1828 @section Remote shell setup hints
1829 @cindex remote shell setup
1830 @cindex @file{.profile} file
1831 @cindex @file{.login} file
1832 @cindex shell init files
1834 @value{tramp} checks for the availability of standard programs in the
1835 usual locations.  Common tactics include successively trying
1836 @command{test -e}, @command{/usr/bin/test -e}, and @command{/bin/test
1837 -e}.  @command{ls -d} is another approach.  But these approaches do not
1838 help with these new login patterns.
1840 When @value{tramp} encounters two-factor logins or additional challenge
1841 questions, such as entering birth date or security code or passphrase,
1842 @value{tramp} needs a few more configuration steps to accommodate
1843 them.
1845 The difference between a password prompt and a passphrase prompt is
1846 that the password for completing the login while the passphrase is
1847 for authorizing access to local authentication information, such as
1848 the ssh key.
1850 There is no one configuration to accommodate all the variations in
1851 login security, especially not the exotic ones.  However, @value{tramp}
1852 provides a few tweaks to address the most common ones.
1854 @table @asis
1855 @item @option{tramp-shell-prompt-pattern}
1856 @vindex tramp-shell-prompt-pattern
1858 @option{tramp-shell-prompt-pattern} is for remote login shell prompt,
1859 which may not be the same as the local login shell prompt,
1860 @code{shell-prompt-pattern}.  Since most hosts use identical prompts,
1861 @value{tramp} sets a similar default value for both prompts.
1863 @item @option{tramp-password-prompt-regexp}
1864 @item @option{tramp-wrong-passwd-regexp}
1865 @vindex tramp-password-prompt-regexp
1866 @vindex tramp-wrong-passwd-regexp
1868 @value{tramp} uses @option{tramp-password-prompt-regexp} to
1869 distinguish between prompts for passwords and prompts for passphrases.
1870 By default, @option{tramp-password-prompt-regexp} handles the
1871 detection in English language environments.  See a localization
1872 example below:
1874 @lisp
1875 @group
1876 (customize-set-variable
1877  'tramp-password-prompt-regexp
1878   (concat
1879    "^.*"
1880    (regexp-opt
1881     '("passphrase" "Passphrase"
1882       ;; English
1883       "password" "Password"
1884       ;; Deutsch
1885       "passwort" "Passwort"
1886       ;; Français
1887       "mot de passe" "Mot de passe")
1888     t)
1889    ".*:\0? *"))
1890 @end group
1891 @end lisp
1893 Similar localization may be necessary for handling wrong password
1894 prompts, for which @value{tramp} uses @option{tramp-wrong-passwd-regexp}.
1896 @item @command{tset} and other questions
1897 @cindex unix command @command{tset}
1898 @cindex @command{tset} unix command
1899 @vindex tramp-terminal-type
1901 To suppress inappropriate prompts for terminal type, @value{tramp}
1902 sets the @env{TERM} to @code{dumb} before the remote login process
1903 begins via the user option @option{tramp-terminal-type}.  This will
1904 silence common @command{tset} related prompts.
1906 @value{tramp}'s strategy for handling such prompts (commonly triggered
1907 from login scripts on remote hosts) is to set the environment
1908 variables so that no prompts interrupt the shell initialization
1909 process.
1911 @vindex tramp-actions-before-shell
1912 An alternative approach is to configure @value{tramp} with strings
1913 that can identify such questions using
1914 @code{tramp-actions-before-shell}.  Example:
1916 @lisp
1917 @group
1918 (defconst my-tramp-prompt-regexp
1919   (concat (regexp-opt '("Enter the birth date of your mother:") t)
1920           "\\s-*")
1921   "Regular expression matching my login prompt question.")
1922 @end group
1924 @group
1925 (defun my-tramp-action (proc vec)
1926   "Enter \"19000101\" in order to give a correct answer."
1927   (save-window-excursion
1928     (with-current-buffer (tramp-get-connection-buffer vec)
1929       (tramp-message vec 6 "\n%s" (buffer-string))
1930       (tramp-send-string vec "19000101"))))
1931 @end group
1933 @group
1934 (add-to-list 'tramp-actions-before-shell
1935              '(my-tramp-prompt-regexp my-tramp-action))
1936 @end group
1937 @end lisp
1940 @item Conflicting names for users and variables in @file{.profile}
1942 When a user name is the same as a variable name in a local file, such
1943 as @file{.profile}, then @value{tramp} may send incorrect values for
1944 environment variables.  To avoid incorrect values, change the local
1945 variable name to something different from the user name.  For example,
1946 if the user name is @env{FRUMPLE}, then change the variable name to
1947 @env{FRUMPLE_DIR}.
1950 @item Non-Bourne commands in @file{.profile}
1952 When the remote host's @file{.profile} is also used for shells other
1953 than Bourne shell, then some incompatible syntaxes for commands in
1954 @file{.profile} may trigger errors in Bourne shell on the host and may
1955 not complete client's @value{tramp} connections.
1957 One example of a Bourne shell incompatible syntax in @file{.profile}:
1958 using @command{export FOO=bar} instead of @command{FOO=bar; export
1959 FOO}.  After remote login, @value{tramp} will trigger an error during
1960 its execution of @command{/bin/sh} on the remote host because Bourne
1961 shell does not recognize the export command as entered in
1962 @file{.profile}.
1964 Likewise, (@code{~}) character in paths will cause errors because
1965 Bourne shell does not do (@code{~}) character expansions.
1967 One approach to avoiding these incompatibilities is to make all
1968 commands in @file{~/.shrc} and @file{~/.profile} Bourne shell
1969 compatible so @value{tramp} can complete connections to that remote.
1970 To accommodate using non-Bourne shells on that remote, use other
1971 shell-specific config files.  For example, bash can use
1972 @file{~/.bash_profile} and ignore @file{.profile}.
1975 @item Interactive shell prompt
1977 @value{tramp} redefines the remote shell prompt internally for robust
1978 parsing.  This redefinition affects the looks of a prompt in an
1979 interactive remote shell through commands, such as @kbd{M-x
1980 shell}.  Such prompts, however, can be reset to something more readable
1981 and recognizable using these @value{tramp} variables.
1983 @value{tramp} sets the @env{INSIDE_EMACS} variable in the startup
1984 script file @file{~/.emacs_SHELLNAME}.
1986 @env{SHELLNAME} is @code{bash} or equivalent shell names.  Change it by
1987 setting the environment variable @env{ESHELL} in the @file{.emacs} as
1988 follows:
1990 @lisp
1991 (setenv "ESHELL" "bash")
1992 @end lisp
1994 Then re-set the prompt string in @file{~/.emacs_SHELLNAME} as follows:
1996 @example
1997 @group
1998 # Reset the prompt for remote @value{tramp} shells.
1999 if [ "$@{INSIDE_EMACS/*tramp*/tramp@}" == "tramp" ] ; then
2000    PS1="[\u@@\h \w]$ "
2002 @end group
2003 @end example
2005 @ifinfo
2006 @xref{Interactive Shell, , , emacs}.
2007 @end ifinfo
2009 @item @command{busybox} / @command{nc}
2010 @cindex unix command @command{nc}
2011 @cindex @command{nc} unix command
2013 @value{tramp}'s @option{nc} method uses the @command{nc} command to
2014 install and execute a listener as follows (see @code{tramp-methods}):
2016 @example
2017 $ nc -l -p 42
2018 @end example
2020 The above command-line syntax has changed with @command{busybox}
2021 versions.  If @command{nc} refuses the @samp{-p} parameter, then
2022 overwrite as follows:
2024 @lisp
2025 @group
2026 (add-to-list
2027  'tramp-connection-properties
2028  `(,(regexp-quote "192.168.0.1")
2029    "remote-copy-args" (("-l") ("%r"))))
2030 @end group
2031 @end lisp
2033 @noindent
2034 where @samp{192.168.0.1} is the remote host IP address
2035 (@pxref{Predefined connection information}).
2037 @end table
2040 @node Android shell setup
2041 @section Android shell setup hints
2042 @cindex android shell setup for ssh
2044 @value{tramp} uses the @option{adb} method to access Android devices.
2045 Android devices provide a restricted shell access through an USB
2046 connection.  The local host must have the @command{adb} program
2047 installed.  Usually, it is sufficient to open the file
2048 @file{@trampfn{adb,,/}}.  Then you can navigate in the filesystem via
2049 @code{dired}.
2051 Alternatively, applications such as @code{SSHDroid} that run
2052 @command{sshd} process on the Android device can accept any
2053 @option{ssh}-based methods provided these settings are adjusted:
2055 @itemize
2056 @item
2057 @command{sh} must be specified for remote shell since Android devices
2058 do not provide @command{/bin/sh}.  @command{sh} will then invoke
2059 whatever shell is installed on the device with this setting:
2061 @lisp
2062 @group
2063 (add-to-list 'tramp-connection-properties
2064              (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))
2065 @end group
2066 @end lisp
2068 @noindent
2069 where @samp{192.168.0.26} is the Android device's IP address.
2070 (@pxref{Predefined connection information}).
2072 @item
2073 @value{tramp} requires preserving @env{PATH} environment variable from
2074 user settings.  Android devices prefer @file{/system/xbin} path over
2075 @file{/system/bin}.  Both of these are set as follows:
2077 @lisp
2078 @group
2079 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
2080 (add-to-list 'tramp-remote-path "/system/xbin")
2081 @end group
2082 @end lisp
2084 @item
2085 When the Android device is not @samp{rooted}, specify a writable
2086 directory for temporary files:
2088 @lisp
2089 (add-to-list 'tramp-remote-process-environment "TMPDIR=$HOME")
2090 @end lisp
2092 @item
2093 Open a remote connection with the command @kbd{C-x C-f
2094 @trampfn{ssh,192.168.0.26#2222,}}, where @command{sshd} is listening
2095 on port @samp{2222}.
2097 To add a corresponding entry to the @file{~/.ssh/config} file
2098 (recommended), use this:
2100 @example
2101 @group
2102 Host android
2103      HostName 192.168.0.26
2104      User root
2105      Port 2222
2106 @end group
2107 @end example
2109 @noindent
2110 To use the host name @samp{android} instead of the IP address shown in
2111 the previous example, fix the connection properties as follows:
2113 @lisp
2114 @group
2115 (add-to-list 'tramp-connection-properties
2116              (list (regexp-quote "android") "remote-shell" "sh"))
2117 @end group
2118 @end lisp
2120 @noindent
2121 Open a remote connection with a more concise command @kbd{C-x C-f
2122 @trampfn{ssh,android,}}.
2123 @end itemize
2126 @node Auto-save and Backup
2127 @section Auto-save and Backup configuration
2128 @cindex auto-save
2129 @cindex backup
2130 @vindex backup-directory-alist
2132 To avoid @value{tramp} from saving backup files owned by @samp{root}
2133 to locations accessible to others, default backup settings in
2134 @option{backup-directory-alist} have to be altered.
2136 Here's a scenario where files could be inadvertently exposed.  Emacs
2137 by default writes backup files to the same directory as the original
2138 files unless changed to another location, such as
2139 @file{~/.emacs.d/backups/}.  Such a directory will also be used by
2140 default by @value{tramp} when using, say, a restricted file
2141 @file{@trampfn{su,root@@localhost,/etc/secretfile}}.  The backup file
2142 of the secretfile is now owned by the user logged in from
2143 @value{tramp} and not @samp{root}.
2145 When @option{backup-directory-alist} is @code{nil} (the default), such
2146 problems do not occur.
2148 To ``turn off'' the backup feature for @value{tramp} files and stop
2149 @value{tramp} from saving to the backup directory, use this:
2151 @lisp
2152 @group
2153 (add-to-list 'backup-directory-alist
2154              (cons tramp-file-name-regexp nil))
2155 @end group
2156 @end lisp
2158 @noindent
2159 Disabling backups can be targeted to just the @option{su} and
2160 @option{sudo} methods:
2162 @lisp
2163 @group
2164 (setq backup-enable-predicate
2165       (lambda (name)
2166         (and (normal-backup-enable-predicate name)
2167              (not
2168               (let ((method (file-remote-p name 'method)))
2169                 (when (stringp method)
2170                   (member method '("su" "sudo"))))))))
2171 @end group
2172 @end lisp
2174 Another option is to create better backup file naming with user and
2175 host names prefixed to the file name.  For example, transforming
2176 @file{/etc/secretfile} to
2177 @file{~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile}, set the
2178 @value{tramp} user option @option{tramp-backup-directory-alist} from
2179 the existing user option @option{backup-directory-alist}.
2181 Then @value{tramp} backs up to a file name that is transformed with a
2182 prefix consisting of the DIRECTORY name.  This file name prefixing
2183 happens only when the DIRECTORY is an absolute local file name.
2185 @noindent
2186 Example:
2188 @lisp
2189 @group
2190 (add-to-list 'backup-directory-alist
2191              (cons "." "~/.emacs.d/backups/"))
2192 (customize-set-variable
2193  'tramp-backup-directory-alist backup-directory-alist)
2194 @end group
2195 @end lisp
2197 @noindent
2198 The backup file name of
2199 @file{@trampfn{su,root@@localhost,/etc/secretfile}} would be
2200 @ifset unified
2201 @file{@trampfn{su,root@@localhost,~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile~}}
2202 @end ifset
2203 @ifset separate
2204 @file{@trampfn{su,root@@localhost,~/.emacs.d/backups/![su!root@@localhost]!etc!secretfile~}}
2205 @end ifset
2207 Just as for backup files, similar issues of file naming affect
2208 auto-saving @value{tramp} files.  Auto-saved files are saved in the
2209 directory specified by the user option
2210 @option{auto-save-file-name-transforms}.  By default this is set to
2211 the local temporary directory.  But in some versions of Debian
2212 GNU/Linux, this points to the source directory where the Emacs was
2213 compiled.  Reset such values to a valid directory.
2215 Set @option{auto-save-file-name-transforms} to @code{nil} to save
2216 auto-saved files to the same directory as the original file.
2218 Alternatively, set the user option @option{tramp-auto-save-directory}
2219 to direct all auto saves to that location.
2221 @node Windows setup hints
2222 @section Issues with Cygwin ssh
2223 @cindex cygwin, issues
2225 This section is incomplete.  Please share your solutions.
2227 @cindex method @option{sshx} with cygwin
2228 @cindex @option{sshx} method with cygwin
2230 Cygwin's @command{ssh} works only with a Cygwin version of Emacs.  To
2231 check for compatibility: type @kbd{M-x eshell}, and start @kbd{ssh
2232 test.host}.  Incompatibilities trigger this message:
2234 @example
2235 Pseudo-terminal will not be allocated because stdin is not a terminal.
2236 @end example
2238 Some older versions of Cygwin's @command{ssh} work with the
2239 @option{sshx} access method.  Consult Cygwin's FAQ at
2240 @uref{https://cygwin.com/faq/} for details.
2242 @cindex cygwin and fakecygpty
2243 @cindex fakecygpty and cygwin
2245 On @uref{https://www.emacswiki.org/emacs/SshWithNTEmacs, the Emacs
2246 Wiki} it is explained how to use the helper program @code{fakecygpty}
2247 to fix this problem.
2249 @cindex method @option{scpx} with cygwin
2250 @cindex @option{scpx} method with cygwin
2252 When using the @option{scpx} access method, Emacs may call
2253 @command{scp} with MS Windows file naming, such as @code{c:/foo}.  But
2254 the version of @command{scp} that is installed with Cygwin does not
2255 know about MS Windows file naming, which causes it to incorrectly look
2256 for a host named @code{c}.
2258 A workaround: write a wrapper script for @option{scp} to convert
2259 Windows file names to Cygwin file names.
2261 @cindex cygwin and ssh-agent
2262 @cindex @env{SSH_AUTH_SOCK} and emacs on ms windows
2264 When using the @command{ssh-agent} on MS Windows for password-less
2265 interaction, @option{ssh} methods depend on the environment variable
2266 @env{SSH_AUTH_SOCK}.  But this variable is not set when Emacs is
2267 started from a Desktop shortcut and authentication fails.
2269 One workaround is to use an MS Windows based SSH Agent, such as
2270 Pageant.  It is part of the Putty Suite of tools.
2272 The fallback is to start Emacs from a shell.
2275 @node Usage
2276 @chapter Using @value{tramp}
2277 @cindex using @value{tramp}
2279 @value{tramp} operates transparently, accessing remote files as if
2280 they are local.  However, @value{tramp} employs a formalized remote
2281 file naming syntax to perform its functions transparently.  This
2282 syntax consists of many parts specifying access methods,
2283 authentication, host names, and file names.  Ange FTP uses a similar
2284 syntax.
2286 @cindex type-ahead
2288 Unlike opening local files in Emacs, which are instantaneous, opening
2289 remote files in @value{tramp} is slower at first.  Sometimes there is
2290 a noticeable delay before the prompts for passwords or authentication
2291 appear in the minibuffer.  Hitting @kbd{@key{RET}} or other keys
2292 during this gap will be processed by Emacs.  This type-ahead facility
2293 is a feature of Emacs that may cause missed prompts when using
2294 @value{tramp}.
2296 @menu
2297 * File name syntax::            @value{tramp} file name conventions.
2298 @ifset unified
2299 * Change file name syntax::     Alternative file name syntax.
2300 @end ifset
2301 * File name completion::        File name completion.
2302 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
2303 * Remote processes::            Integration with other Emacs packages.
2304 * Cleanup remote connections::  Cleanup remote connections.
2305 * Archive file names::          Access to files in file archives.
2306 @end menu
2309 @node File name syntax
2310 @section @value{tramp} file name conventions
2311 @cindex file name syntax
2312 @cindex file name examples
2314 @file{@trampfn{method,host,/path/to/file}} opens file @var{/path/to/file}
2315 on the remote host @var{host}, using the method @var{method}.
2317 @table @file
2318 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}.emacs
2319 For the file @file{.emacs} located in the home directory, on the host
2320 @code{melancholia}, using method @code{ssh}.
2322 @item @value{prefix}ssh@value{postfixhop}melancholia.danann.net@value{postfix}.emacs
2323 For the file @file{.emacs} specified using the fully qualified domain name of
2324 the host.
2326 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~/.emacs
2327 For the file @file{.emacs} specified using the @file{~}, which is expanded.
2329 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~daniel/.emacs
2330 For the file @file{.emacs} located in @code{daniel}'s home directory
2331 on the host, @code{melancholia}.  The @file{~<user>} construct is
2332 expanded to the home directory of that user on the remote host.
2334 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}/etc/squid.conf
2335 For the file @file{/etc/squid.conf} on the host @code{melancholia}.
2337 @end table
2339 @var{host} can take IPv4 or IPv6 address, as in
2340 @file{@trampfn{ssh,127.0.0.1,.emacs}} or
2341 @file{@trampfn{ssh,@value{ipv6prefix}::1@value{ipv6postfix},.emacs}}.
2342 @ifset unified
2343 For syntactical reasons, IPv6 addresses must be embedded in square
2344 brackets @file{@value{ipv6prefix}} and @file{@value{ipv6postfix}}.
2345 @end ifset
2347 By default, @value{tramp} will use the current local user name as the
2348 remote user name for log in to the remote host.  Specifying a different
2349 name using the proper syntax will override this default behavior:
2351 @example
2352 @trampfn{method,user@@host,path/to/file}
2353 @end example
2355 @file{@trampfn{ssh,daniel@@melancholia,.emacs}} is for file
2356 @file{.emacs} in @code{daniel}'s home directory on the host,
2357 @code{melancholia}, accessing via method @code{ssh}.
2359 For specifying port numbers, affix @file{#<port>} to the host
2360 name.  For example: @file{@trampfn{ssh,daniel@@melancholia#42,.emacs}}.
2362 All method, user name, host name, port number and local name parts are
2363 optional, @xref{Default Method}, @xref{Default User}, @xref{Default Host}.
2364 @ifset unified
2365 For syntactical reasons, the default method must be indicated by the
2366 pseudo method @file{-}.
2367 @end ifset
2370 @ifset unified
2371 @node Change file name syntax
2372 @section Alternative file name syntax
2373 @cindex change file name syntax
2374 @cindex alternative file name syntax
2376 The syntax described in @ref{File name syntax} is the @code{default}
2377 syntax, which is active after Emacs startup.  However, this can be
2378 changed.
2380 @deffn Command tramp-change-syntax syntax
2381 This command changes the syntax @value{tramp} uses for remote file
2382 names.  Beside the @code{default} value, @var{syntax} can be
2384 @itemize
2385 @item @code{simplified}
2386 @cindex simplified syntax
2388 The remote file name syntax is similar to the syntax used by Ange FTP.
2389 A remote file name has the form
2390 @code{@value{prefix}user@@host@value{postfix}path/to/file}.  The
2391 @code{user@@} part is optional, and the method is determined by
2392 @ref{Default Method}.
2394 @item @code{separate}
2395 @cindex separate syntax
2397 @clear unified
2398 @set separate
2399 @include trampver.texi
2400 The remote file name syntax is similar to the syntax used by XEmacs.
2401 A remote file name has the form
2402 @code{@trampfn{method,user@@host,path/to/file}}.  The @code{method}
2403 and @code{user@@} parts are optional.
2404 @clear separate
2405 @set unified
2406 @include trampver.texi
2407 @end itemize
2408 @end deffn
2410 @defvar tramp-file-name-regexp
2411 This variable keeps a regexp which matches the selected remote file
2412 name syntax.  However, it is not recommended to use this variable in
2413 external packages, a call of @code{file-remote-p} is much more
2414 appropriate.
2415 @ifinfo
2416 @pxref{Magic File Names, , , elisp}
2417 @end ifinfo
2418 @end defvar
2419 @end ifset
2422 @node File name completion
2423 @section File name completion
2424 @cindex file name completion
2426 @value{tramp} can complete the following @value{tramp} file name
2427 components: method names, user names, host names, and file names
2428 located on remote hosts.  Enable this by activating partial completion
2429 in @file{.emacs}.
2430 @ifinfo
2431 @xref{Completion Options, , , emacs}.
2432 @end ifinfo
2434 For example, type @kbd{C-x C-f @value{prefixwithspace} s @key{TAB}},
2435 @value{tramp} completion choices show up as
2437 @example
2438 @group
2439 @multitable @columnfractions .2 .2 .2 .2 .2
2440 @item @c
2441   sbin/ @tab @c
2442   @value{prefixhop}scp@value{postfix} @tab @c
2443   @value{prefixhop}scpx@value{postfix} @tab @c
2444   @value{prefixhop}sftp@value{postfix} @tab @c
2445   @value{prefixhop}sg@value{postfix}
2446 @item @c
2447   @value{prefixhop}smb@value{postfix} @tab @c
2448   srv/ @tab @c
2449   @value{prefixhop}ssh@value{postfix} @tab @c
2450   @value{prefixhop}sshx@value{postfix} @tab @c
2451   @value{prefixhop}su@value{postfix}
2452 @item @c
2453   @value{prefixhop}sudo@value{postfix} @tab @c
2454   sys/
2455 @end multitable
2456 @end group
2457 @end example
2459 @samp{@value{prefixhop}ssh@value{postfixhop}} is a possible
2460 completion for the respective method, and @samp{sbin/} stands for the
2461 directory @file{/sbin} on your local host.
2463 Type @kbd{s h @value{postfixhop}} for the minibuffer completion to
2464 @samp{@value{prefix}ssh@value{postfixhop}}.  Typing @kbd{@key{TAB}}
2465 shows host names @value{tramp} extracts from @file{~/.ssh/config}
2466 file, for example.
2468 @example
2469 @group
2470 @multitable @columnfractions .5 .5
2471 @item @c
2472   @value{prefixhop}ssh@value{postfixhop}127.0.0.1@value{postfix} @tab @c
2473   @value{prefixhop}ssh@value{postfixhop}192.168.0.1@value{postfix}
2474 @item @c
2475   @value{prefixhop}ssh@value{postfixhop}@value{ipv6prefix}::1@value{ipv6postfix}@value{postfix} @tab @c
2476   @value{prefixhop}ssh@value{postfixhop}localhost@value{postfix}
2477 @item @c
2478   @value{prefixhop}ssh@value{postfixhop}melancholia.danann.net@value{postfix} @tab @c
2479   @value{prefixhop}ssh@value{postfixhop}melancholia@value{postfix}
2480 @end multitable
2481 @end group
2482 @end example
2484 Choose a host from the above list and then continue to complete file
2485 names on that host.
2487 When the configuration (@pxref{Customizing Completion}) includes user
2488 names, then the completion lists will account for the user names as well.
2490 Remote hosts previously visited or hosts whose connections are kept
2491 persistently (@pxref{Connection caching}) will be included in the
2492 completion lists.
2494 After remote host name completion comes completion of file names on
2495 the remote host.  It works the same as with local host file completion
2496 except that killing with double-slash @file{//} kills only the file
2497 name part of the @value{tramp} file name syntax.  A triple-slash
2498 stands for the default behavior.
2499 @ifinfo
2500 @xref{Minibuffer File, , , emacs}.
2501 @end ifinfo
2503 @noindent
2504 Example:
2506 @example
2507 @group
2508 @kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin//etc} @key{TAB}}
2509      @print{} @trampfn{ssh,melancholia,/etc}
2511 @kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}}
2512      @print{} /etc
2514 @kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}}
2515      @print{} /etc
2516 @end group
2517 @end example
2519 During file name completion, remote directory contents are re-read
2520 regularly to account for any changes in the filesystem that may affect
2521 the completion candidates.  Such re-reads can account for changes to
2522 the file system by applications outside Emacs (@pxref{Connection
2523 caching}).
2525 @defopt tramp-completion-reread-directory-timeout
2526 The timeout is number of seconds since last remote command for
2527 rereading remote directory contents.  A value of 0 re-reads
2528 immediately during file name completion, @code{nil} uses cached
2529 directory contents.
2530 @end defopt
2533 @node Ad-hoc multi-hops
2534 @section Declaring multiple hops in the file name
2535 @cindex multi-hop, ad-hoc
2536 @cindex proxy hosts, ad-hoc
2538 @value{tramp} file name syntax can accommodate ad hoc specification of
2539 multiple proxies without using @option{tramp-default-proxies-alist}
2540 configuration setup(@pxref{Multi-hops}).
2542 Each proxy is specified using the same syntax as the remote host
2543 specification minus the file name part.  Each hop is separated by a
2544 @samp{|}.  Chain the proxies from the starting host to the destination
2545 remote host name and file name.  For example, hopping over a single
2546 proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}:
2548 @example
2549 @c @kbd{C-x C-f @trampfn{ssh@value{postfixhop}bird@@bastion|ssh,you,remotehost,/path}}
2550 @kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path}
2551 @end example
2553 Proxies can take patterns @code{%h} or @code{%u}.
2555 @value{tramp} adds the ad-hoc definitions on the fly to
2556 @option{tramp-default-proxies-alist} and is available for re-use
2557 during that Emacs session.  Subsequent @value{tramp} connections to
2558 the same remote host can then use the shortcut form:
2559 @samp{@trampfn{ssh,you@@remotehost,/path}}.
2561 @defopt tramp-save-ad-hoc-proxies
2562 For ad-hoc definitions to be saved automatically in
2563 @option{tramp-default-proxies-alist} for future Emacs sessions, set
2564 @option{tramp-save-ad-hoc-proxies} to non-@code{nil}.
2566 @lisp
2567 (customize-set-variable 'tramp-save-ad-hoc-proxies t)
2568 @end lisp
2569 @end defopt
2572 @node Remote processes
2573 @section Integration with other Emacs packages
2574 @cindex @code{compile}
2575 @cindex @code{recompile}
2577 @value{tramp} supports starting new running processes on the remote
2578 host for discovering remote file names.  Emacs packages on the remote
2579 host need no specific modifications for @value{tramp}'s use.
2581 This type of integration does not work with the @option{ftp} method,
2582 and does not support the pty association as specified in
2583 @code{start-file-process}.
2585 @code{process-file} and @code{start-file-process} work on the remote
2586 host when the variable @code{default-directory} is remote:
2588 @lisp
2589 @group
2590 (let ((default-directory "/ssh:remote.host:"))
2591   (start-file-process "grep" (get-buffer-create "*grep*")
2592                       "/bin/sh" "-c" "grep -e tramp *"))
2593 @end group
2594 @end lisp
2596 Remote processes do not apply to GVFS (see @ref{GVFS based methods})
2597 because the remote file system is mounted on the local host and
2598 @value{tramp} just accesses by changing the @code{default-directory}.
2600 @value{tramp} starts a remote process when a command is executed in a
2601 remote file or directory buffer.  As of now, these packages have been
2602 integrated to work with @value{tramp}: @file{compile.el} (commands
2603 like @code{compile} and @code{grep}) and @file{gud.el} (@code{gdb} or
2604 @code{perldb}).
2606 For @value{tramp} to find the command on the remote, it must be
2607 accessible through the default search path as setup by @value{tramp}
2608 upon first connection.  Alternatively, use an absolute path or extend
2609 @option{tramp-remote-path} (see @ref{Remote programs}):
2611 @lisp
2612 @group
2613 (add-to-list 'tramp-remote-path "~/bin")
2614 (add-to-list 'tramp-remote-path "/appli/pub/bin")
2615 @end group
2616 @end lisp
2618 Customize user option @option{tramp-remote-process-environment} to
2619 suit the remote program's environment for the remote host.
2620 @option{tramp-remote-process-environment} is a list of strings
2621 structured similar to @code{process-environment}, where each element
2622 is a string of the form @samp{ENVVARNAME=VALUE}.
2624 To avoid any conflicts with local host environment variables set
2625 through local configuration files, such as @file{~/.profile}, use
2626 @samp{ENVVARNAME=} to unset them for the remote environment.
2628 @noindent
2629 Use @code{add-to-list} to add entries:
2631 @lisp
2632 (add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java")
2633 @end lisp
2635 Modifying or deleting already existing values in the
2636 @option{tramp-remote-process-environment} list may not be feasible on
2637 restricted remote hosts.  For example, some system administrators
2638 disallow changing @env{HISTORY} environment variable.  To accommodate
2639 such restrictions when using @value{tramp}, fix the
2640 @option{tramp-remote-process-environment} by the following code in the
2641 local @file{.emacs} file:
2643 @lisp
2644 @group
2645 (let ((process-environment tramp-remote-process-environment))
2646   (setenv "HISTORY" nil)
2647   (setq tramp-remote-process-environment process-environment))
2648 @end group
2649 @end lisp
2651 Setting the @env{ENV} environment variable instructs some shells to
2652 read an initialization file.  Per default, @value{tramp} has disabled
2653 this.  You could overwrite this behavior by evaluating
2655 @lisp
2656 @group
2657 (let ((process-environment tramp-remote-process-environment))
2658   (setenv "ENV" "$HOME/.profile")
2659   (setq tramp-remote-process-environment process-environment))
2660 @end group
2661 @end lisp
2663 @value{tramp} does not use the defaults specified in
2664 @code{process-environment} for running @code{process-file} or
2665 @code{start-file-process} on remote hosts.  When values from
2666 @code{process-environment} are needed for remote processes, then set
2667 them as follows:
2669 @lisp
2670 @group
2671 (let ((process-environment (cons "HGPLAIN=1" process-environment)))
2672   (process-file @dots{}))
2673 @end group
2674 @end lisp
2676 This works only for environment variables not already set in the
2677 @code{process-environment}.
2679 For integrating other Emacs packages so @value{tramp} can execute
2680 remotely, please file a bug report.  @xref{Bug Reports}.
2683 @subsection Running remote programs that create local X11 windows
2685 To allow a remote program to create an X11 window on the local host,
2686 set the @env{DISPLAY} environment variable for the remote host as
2687 follows in the local @file{.emacs} file:
2689 @lisp
2690 @group
2691 (add-to-list 'tramp-remote-process-environment
2692              (format "DISPLAY=%s" (getenv "DISPLAY")))
2693 @end group
2694 @end lisp
2696 @noindent
2697 @code{(getenv "DISPLAY")} should return a recognizable name for the
2698 local host that the remote host can redirect X11 window
2699 interactions.  If querying for a recognizable name is not possible for
2700 whatever reason, then replace @code{(getenv "DISPLAY")} with a
2701 hard-coded, fixed name.  Note that using @code{:0} for X11 display name
2702 here will not work as expected.
2704 An alternate approach is specify @code{ForwardX11 yes} or
2705 @code{ForwardX11Trusted yes} in the file @file{~/.ssh/config} on the
2706 local host.
2709 @subsection Running @code{shell} on a remote host
2710 @cindex @code{shell}
2712 Set @option{explicit-shell-file-name} to the appropriate shell name
2713 when using @value{tramp} between two hosts with different operating
2714 systems, such as @samp{windows-nt} and @samp{gnu/linux}.  This option
2715 ensures the correct name of the remote shell program.
2717 When @option{explicit-shell-file-name} is equal to @code{nil}, calling
2718 @code{shell} interactively will prompt for a shell name.
2720 Starting with Emacs 26, you could use connection-local variables for
2721 setting different values of @option{explicit-shell-file-name} for
2722 different remote hosts.
2723 @ifinfo
2724 @pxref{Connection Local Variables, , , elisp}
2725 @end ifinfo
2727 @lisp
2728 @group
2729 (connection-local-set-profile-variables
2730   'remote-bash
2731   '((explicit-shell-file-name . "/bin/bash")
2732     (explicit-bash-args . ("-i"))))
2733 @end group
2735 @group
2736 (connection-local-set-profile-variables
2737   'remote-ksh
2738   '((explicit-shell-file-name . "/bin/ksh")
2739     (explicit-ksh-args . ("-i"))))
2740 @end group
2742 @group
2743 (connection-local-set-profiles
2744   '(:application tramp :protocol "ssh" :machine "localhost")
2745   'remote-bash)
2746 @end group
2748 @group
2749 (connection-local-set-profiles
2750   `(:application tramp :protocol "sudo"
2751     :user "root" :machine ,(system-name))
2752   'remote-ksh)
2753 @end group
2754 @end lisp
2757 @subsection Running @code{shell-command} on a remote host
2758 @cindex @code{shell-command}
2760 @code{shell-command} executes commands synchronously or asynchronously
2761 on remote hosts and displays output in buffers on the local
2762 host.  Example:
2764 @example
2765 @group
2766 @kbd{C-x C-f @trampfn{sudo,,} @key{RET}}
2767 @kbd{M-! tail -f /var/log/syslog.log & @key{RET}}
2768 @end group
2769 @end example
2771 @command{tail} command outputs continuously to the local buffer,
2772 @file{*Async Shell Command*}
2774 @kbd{M-x auto-revert-tail-mode} runs similarly showing continuous output.
2777 @subsection Running @code{eshell} on a remote host
2778 @cindex @code{eshell}
2780 @value{tramp} is integrated into @file{eshell.el}, which enables
2781 interactive eshell sessions on remote hosts at the command prompt.
2782 You must add the module @code{em-tramp} to @code{eshell-modules-list}.
2783 Here's a sample interaction after opening @kbd{M-x eshell} on a remote
2784 host:
2786 @example
2787 @group
2788 @b{~ $} cd @trampfn{sudo,,/etc} @key{RET}
2789 @b{@trampfn{sudo,root@@host,/etc} $} hostname @key{RET}
2790 host
2791 @b{@trampfn{sudo,root@@host,/etc} $} id @key{RET}
2792 uid=0(root) gid=0(root) groups=0(root)
2793 @b{@trampfn{sudo,root@@host,/etc} $} find-file shadow @key{RET}
2794 #<buffer shadow>
2795 @b{@trampfn{sudo,root@@host,/etc} $}
2796 @end group
2797 @end example
2799 @code{eshell} added custom @code{su} and @code{sudo} commands that set
2800 the default directory correctly for the @file{*eshell*} buffer.
2801 @value{tramp} silently updates @option{tramp-default-proxies-alist}
2802 with an entry for this directory (@pxref{Multi-hops}):
2804 @example
2805 @group
2806 @b{~ $} cd @trampfn{ssh,user@@remotehost,/etc} @key{RET}
2807 @b{@trampfn{ssh,user@@remotehost,/etc} $} find-file shadow @key{RET}
2808 File is not readable: @trampfn{ssh,user@@remotehost,/etc/shadow}
2809 @b{@trampfn{ssh,user@@remotehost,/etc} $} sudo find-file shadow @key{RET}
2810 #<buffer shadow>
2811 @end group
2813 @group
2814 @b{@trampfn{ssh,user@@remotehost,/etc} $} su - @key{RET}
2815 @b{@trampfn{su,root@@remotehost,/root} $} id @key{RET}
2816 uid=0(root) gid=0(root) groups=0(root)
2817 @b{@trampfn{su,root@@remotehost,/root} $}
2818 @end group
2819 @end example
2822 @anchor{Running a debugger on a remote host}
2823 @subsection Running a debugger on a remote host
2824 @cindex @file{gud.el}
2825 @cindex @code{gdb}
2826 @cindex @code{perldb}
2828 @file{gud.el} provides a unified interface to symbolic debuggers
2829 @ifinfo
2830 (@ref{Debuggers, , , emacs}).
2831 @end ifinfo
2832 @value{tramp} can run debug on remote hosts by calling @code{gdb}
2833 with a remote file name:
2835 @example
2836 @group
2837 @kbd{M-x gdb @key{RET}}
2838 @b{Run gdb (like this):} gdb -i=mi @trampfn{ssh,host,~/myprog} @key{RET}
2839 @end group
2840 @end example
2842 Since the remote @code{gdb} and @code{gdb-inferior} processes do not
2843 belong to the same process group on the remote host, there will be a
2844 warning, which can be ignored:
2846 @example
2847 &"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
2848 @end example
2850 @noindent
2851 As consequence, there will be restrictions in I/O of the process to be
2852 debugged.
2854 Relative file names are based on the remote default directory.  When
2855 @file{myprog.pl} exists in @file{@trampfn{ssh,host,/home/user}}, valid
2856 calls include:
2858 @example
2859 @group
2860 @kbd{M-x perldb @key{RET}}
2861 @b{Run perldb (like this):} perl -d myprog.pl @key{RET}
2862 @end group
2863 @end example
2865 Just the local part of a remote file name, such as @kbd{perl -d
2866 /home/user/myprog.pl}, is not possible.
2868 Arguments of the program to be debugged must be literal, can take
2869 relative or absolute paths, but not remote paths.
2872 @subsection Running remote processes on MS Windows hosts
2873 @cindex @command{winexe}
2874 @cindex @command{powershell}
2876 @command{winexe} runs processes on a remote MS Windows host, and
2877 @value{tramp} can use it for @code{process-file} and
2878 @code{start-file-process}.
2880 @code{tramp-smb-winexe-program} specifies the local @command{winexe}
2881 command.  Powershell V2.0 on the remote host is required to run
2882 processes triggered from @value{tramp}.
2884 @option{explicit-shell-file-name} and @option{explicit-*-args} have to
2885 be set properly so @kbd{M-x shell} can open a proper remote shell on a
2886 MS Windows host.  To open @command{cmd}, set it as follows:
2888 @lisp
2889 @group
2890 (setq explicit-shell-file-name "cmd"
2891       explicit-cmd-args '("/q"))
2892 @end group
2893 @end lisp
2895 @noindent
2896 To open @command{powershell} as a remote shell, use this:
2898 @lisp
2899 @group
2900 (setq explicit-shell-file-name "powershell"
2901       explicit-powershell-args '("-file" "-"))
2902 @end group
2903 @end lisp
2906 @node Cleanup remote connections
2907 @section Cleanup remote connections
2908 @cindex cleanup
2910 @value{tramp} provides several ways to flush remote connections.
2912 @deffn Command tramp-cleanup-connection vec
2913 This command flushes all connection related objects.  @option{vec} is
2914 the internal representation of a remote connection.  When called
2915 interactively, this command lists active remote connections in the
2916 minibuffer.  Each connection is of the format
2917 @file{@trampfn{method,user@@host,}}.  Flushing remote connections also
2918 cleans the password cache (@pxref{Password handling}), file cache,
2919 connection cache (@pxref{Connection caching}), and connection buffers.
2920 @end deffn
2922 @deffn Command tramp-cleanup-this-connection
2923 Flushes only the current buffer's remote connection objects, the same
2924 as in @code{tramp-cleanup-connection}.
2925 @end deffn
2927 @deffn Command tramp-cleanup-all-connections
2928 Flushes all active remote connection objects, the same as in
2929 @code{tramp-cleanup-connection}.
2930 @end deffn
2932 @deffn Command tramp-cleanup-all-buffers
2933 Just as for @code{tramp-cleanup-all-connections}, all remote
2934 connections are cleaned up in addition to killing buffers related to
2935 that remote connection.
2936 @end deffn
2939 @node Archive file names
2940 @section Archive file names
2941 @cindex file archives
2942 @cindex archive file names
2943 @cindex method archive
2944 @cindex archive method
2946 @value{tramp} offers also transparent access to files inside file
2947 archives.  This is possible only on machines which have installed the
2948 virtual file system for the @acronym{GNOME} Desktop (GVFS), @ref{GVFS
2949 based methods}.  Internally, file archives are mounted via the GVFS
2950 @option{archive} method.
2952 A file archive is a regular file of kind @file{/path/to/dir/file.EXT}.
2953 The extension @samp{.EXT} identifies the type of the file archive.  A
2954 file inside a file archive, called archive file name, has the name
2955 @file{/path/to/dir/file.EXT/dir/file}.
2957 Most of the @ref{Magic File Names, , magic file name operations,
2958 elisp}, are implemented for archive file names, exceptions are all
2959 operations which write into a file archive, and process related
2960 operations.  Therefore, functions like
2962 @lisp
2963 (copy-file "/path/to/dir/file.tar/dir/file" "/somewhere/else")
2964 @end lisp
2966 @noindent
2967 work out of the box.  This is also true for file name completion, and
2968 for libraries like @code{dired} or @code{ediff}, which accept archive
2969 file names as well.
2971 @vindex tramp-archive-suffixes
2972 File archives are identified by the file name extension @samp{.EXT}.
2973 Since GVFS uses internally the library @code{libarchive(3)}, all
2974 suffixes, which are accepted by this library, work also for archive
2975 file names.  Accepted suffixes are listed in the constant
2976 @code{tramp-archive-suffixes}.  They are
2978 @itemize
2979 @item @samp{.7z} ---
2980 7-Zip archives
2981 @cindex @file{7z} file archive suffix
2982 @cindex file archive suffix @file{7z}
2984 @item @samp{.apk} ---
2985 Android package kits
2986 @cindex @file{apk} file archive suffix
2987 @cindex file archive suffix @file{apk}
2989 @item @samp{.ar} ---
2990 UNIX archiver formats
2991 @cindex @file{ar} file archive suffix
2992 @cindex file archive suffix @file{ar}
2994 @item @samp{.cab}, @samp{.CAB} ---
2995 Microsoft Windows cabinets
2996 @cindex @file{cab} file archive suffix
2997 @cindex @file{CAB} file archive suffix
2998 @cindex file archive suffix @file{cab}
2999 @cindex file archive suffix @file{CAB}
3001 @item @samp{.cpio} ---
3002 CPIO archives
3003 @cindex @file{cpio} file archive suffix
3004 @cindex file archive suffix @file{cpio}
3006 @item @samp{.deb} ---
3007 Debian packages
3008 @cindex @file{deb} file archive suffix
3009 @cindex file archive suffix @file{deb}
3011 @item @samp{.depot} ---
3012 HP-UX SD depots
3013 @cindex @file{depot} file archive suffix
3014 @cindex file archive suffix @file{depot}
3016 @item @samp{.exe} ---
3017 Self extracting Microsoft Windows EXE files
3018 @cindex @file{exe} file archive suffix
3019 @cindex file archive suffix @file{exe}
3021 @item @samp{.iso} ---
3022 ISO 9660 images
3023 @cindex @file{iso} file archive suffix
3024 @cindex file archive suffix @file{iso}
3026 @item @samp{.jar} ---
3027 Java archives
3028 @cindex @file{jar} file archive suffix
3029 @cindex file archive suffix @file{jar}
3031 @item @samp{.lzh}, @samp{LZH} ---
3032 Microsoft Windows compressed LHA archives
3033 @cindex @file{lzh} file archive suffix
3034 @cindex @file{LZH} file archive suffix
3035 @cindex file archive suffix @file{lzh}
3036 @cindex file archive suffix @file{LZH}
3038 @item @samp{.mtree} ---
3039 BSD mtree format
3040 @cindex @file{mtree} file archive suffix
3041 @cindex file archive suffix @file{mtree}
3043 @item @samp{.pax} ---
3044 Posix archives
3045 @cindex @file{pax} file archive suffix
3046 @cindex file archive suffix @file{pax}
3048 @item @samp{.rar} ---
3049 RAR archives
3050 @cindex @file{rar} file archive suffix
3051 @cindex file archive suffix @file{rar}
3053 @item @samp{.rpm} ---
3054 Red Hat packages
3055 @cindex @file{rpm} file archive suffix
3056 @cindex file archive suffix @file{rpm}
3058 @item @samp{.shar} ---
3059 Shell archives
3060 @cindex @file{shar} file archive suffix
3061 @cindex file archive suffix @file{shar}
3063 @item @samp{.tar}, @samp{tbz}, @samp{tgz}, @samp{tlz}, @samp{txz} ---
3064 (Compressed) tape archives
3065 @cindex @file{tar} file archive suffix
3066 @cindex @file{tbz} file archive suffix
3067 @cindex @file{tgz} file archive suffix
3068 @cindex @file{tlz} file archive suffix
3069 @cindex @file{txz} file archive suffix
3070 @cindex file archive suffix @file{tar}
3071 @cindex file archive suffix @file{tbz}
3072 @cindex file archive suffix @file{tgz}
3073 @cindex file archive suffix @file{tlz}
3074 @cindex file archive suffix @file{txz}
3076 @item @samp{.warc} ---
3077 Web archives
3078 @cindex @file{warc} file archive suffix
3079 @cindex file archive suffix @file{warc}
3081 @item @samp{.xar} ---
3082 macOS XAR archives
3083 @cindex @file{xar} file archive suffix
3084 @cindex file archive suffix @file{xar}
3086 @item @samp{.xps} ---
3087 Open XML Paper Specification (OpenXPS) documents
3088 @cindex @file{xps} file archive suffix
3089 @cindex file archive suffix @file{xps}
3091 @item @samp{.zip}, @samp{.ZIP} ---
3092 ZIP archives
3093 @cindex @file{zip} file archive suffix
3094 @cindex @file{ZIP} file archive suffix
3095 @cindex file archive suffix @file{zip}
3096 @cindex file archive suffix @file{ZIP}
3097 @end itemize
3099 @vindex tramp-archive-compression-suffixes
3100 File archives could also be compressed, identified by an additional
3101 compression suffix.  Valid compression suffixes are listed in the
3102 constant @code{tramp-archive-compression-suffixes}.  They are
3103 @samp{.bz2}, @samp{.gz}, @samp{.lrz}, @samp{.lz}, @samp{.lz4},
3104 @samp{.lzma}, @samp{.lzo}, @samp{.uu}, @samp{.xz} and @samp{.Z}.  A
3105 valid archive file name would be
3106 @file{/path/to/dir/file.tar.gz/dir/file}.  Even several suffixes in a
3107 row are possible, like @file{/path/to/dir/file.tar.gz.uu/dir/file}.
3109 @vindex tramp-archive-all-gvfs-methods
3110 An archive file name could be a remote file name, as in
3111 @file{/ftp:anonymous@@ftp.gnu.org:/gnu/tramp/tramp-2.3.2.tar.gz/INSTALL}.
3112 Since all file operations are mapped internally to GVFS operations,
3113 remote file names supported by @code{tramp-gvfs} perform better,
3114 because no local copy of the file archive must be downloaded first.
3115 For example, @samp{/sftp:user@@host:...} performs better than the
3116 similar @samp{/scp:user@@host:...}.  See the constant
3117 @code{tramp-archive-all-gvfs-methods} for a complete list of
3118 @code{tramp-gvfs} supported method names.
3120 If @value{tramp} is loaded and @code{url-handler-mode} is enabled,
3121 archives could be visited via URLs, like
3122 @file{https://ftp.gnu.org/gnu/tramp/tramp-2.3.2.tar.gz/INSTALL}.  This
3123 allows complex file operations like
3125 @lisp
3126 @group
3127 (progn
3128   (require 'tramp)
3129   (url-handler-mode 1)
3130   (ediff-directories
3131    "https://ftp.gnu.org/gnu/tramp/tramp-2.3.1.tar.gz/tramp-2.3.1"
3132    "https://ftp.gnu.org/gnu/tramp/tramp-2.3.2.tar.gz/tramp-2.3.2" ""))
3133 @end group
3134 @end lisp
3136 It is even possible to access file archives in file archives, as
3138 @lisp
3139 @group
3140 (find-file
3141  "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control")
3142 @end group
3143 @end lisp
3146 @node Bug Reports
3147 @chapter Reporting Bugs and Problems
3148 @cindex bug reports
3150 @value{tramp}'s development team is actively engaged in solving bugs
3151 and problems and looks to feature requests and suggestions.
3153 @value{tramp}'s mailing list is the place for more advice and
3154 information on working with @value{tramp}, solving problems,
3155 discussing, and general discussions about @value{tramp}.
3157 @value{tramp}'s mailing list is moderated but even non-subscribers can
3158 post for moderator approval.  Sometimes this approval step may take as
3159 long as 48 hours due to public holidays.
3161 @email{tramp-devel@@gnu.org} is the mailing list.  Messages sent to
3162 this address go to all the subscribers.  This is @emph{not} the
3163 address to send subscription requests to.
3165 To subscribe to the mailing list, visit:
3166 @uref{https://lists.gnu.org/mailman/listinfo/tramp-devel/, the
3167 @value{tramp} Mail Subscription Page}.
3169 @ifset installchapter
3170 Before sending a bug report, run the test suite first @ref{Testing}.
3171 @end ifset
3173 @findex tramp-bug
3174 Check if the bug or problem is already addressed in @xref{Frequently
3175 Asked Questions}.
3177 Run @kbd{M-x tramp-bug} to generate a buffer with details of the
3178 system along with the details of the @value{tramp}
3179 installation.  Please include these details with the bug report.
3181 The bug report must describe in as excruciating detail as possible the
3182 steps required to reproduce the problem.  These details must include
3183 the setup of the remote host and any special or unique conditions that
3184 exist.
3186 Include a minimal test case that reproduces the problem.  This will
3187 help the development team find the best solution and avoid unrelated
3188 detours.
3190 To exclude cache-related problems, flush all caches before running the
3191 test, @ref{Cleanup remote connections}.
3193 When including @value{tramp}'s messages in the bug report, increase
3194 the verbosity level to 6 (@pxref{Traces and Profiles, Traces}) in the
3195 @file{~/.emacs} file before repeating steps to the bug.  Include the
3196 contents of the @file{*tramp/foo*} and @file{*debug tramp/foo*}
3197 buffers with the bug report.
3199 @strong{Note} that a verbosity level greater than 6 is not necessary
3200 at this stage.  Also note that a verbosity level of 6 or greater, the
3201 contents of files and directories will be included in the debug
3202 buffer.  Passwords typed in @value{tramp} will never be included
3203 there.
3206 @node Frequently Asked Questions
3207 @chapter Frequently Asked Questions
3208 @cindex frequently asked questions
3209 @cindex FAQ
3211 @itemize @bullet
3212 @item
3213 Where is the latest @value{tramp}?
3215 @value{tramp} is available at the GNU URL:
3217 @noindent
3218 @uref{https://ftp.gnu.org/gnu/tramp/}
3220 @noindent
3221 @value{tramp}'s GNU project page is located here:
3223 @noindent
3224 @uref{https://savannah.gnu.org/projects/tramp/}
3227 @item
3228 Which systems does it work on?
3230 The package works successfully on Emacs 24, Emacs 25, Emacs 26, and
3231 Emacs 27.
3233 While Unix and Unix-like systems are the primary remote targets,
3234 @value{tramp} has equal success connecting to other platforms, such as
3235 MS Windows 7/8/10.
3238 @item
3239 How to speed up @value{tramp}?
3241 @value{tramp} does many things in the background, some of which
3242 depends on network speeds, response speeds of remote hosts, and
3243 authentication delays.  During these operations, @value{tramp}'s
3244 responsiveness slows down.  Some suggestions within the scope of
3245 @value{tramp}'s settings include:
3247 Use an external method, such as @option{scp}, which are faster than
3248 internal methods.
3250 Keep the file @option{tramp-persistency-file-name}, which is where
3251 @value{tramp} caches remote information about hosts and files.  Caching
3252 is enabled by default.  Don't disable it.
3254 Set @code{remote-file-name-inhibit-cache} to @code{nil} if remote
3255 files are not independently updated outside @value{tramp}'s control.
3256 That cache cleanup will be necessary if the remote directories or
3257 files are updated independent of @value{tramp}.
3259 Set @option{tramp-completion-reread-directory-timeout} to @code{nil} to
3260 speed up completions, @ref{File name completion}.
3262 Disable version control to avoid delays:
3264 @lisp
3265 @group
3266 (setq vc-ignore-dir-regexp
3267       (format "\\(%s\\)\\|\\(%s\\)"
3268               vc-ignore-dir-regexp
3269               tramp-file-name-regexp))
3270 @end group
3271 @end lisp
3273 If this is too radical, because you want to use version control
3274 remotely, trim @code{vc-handled-backends} to just those you care
3275 about, for example:
3277 @lisp
3278 (setq vc-handled-backends '(SVN Git))
3279 @end lisp
3281 Disable excessive traces.  Set @code{tramp-verbose} to 3 or lower,
3282 default being 3.  Increase trace levels temporarily when hunting for
3283 bugs.
3285 @item
3286 @value{tramp} does not connect to the remote host
3288 Three main reasons for why @value{tramp} does not connect to the remote host:
3290 @itemize @minus
3291 @item
3292 Unknown characters in the prompt
3294 @value{tramp} needs a clean recognizable prompt on the remote host for
3295 accurate parsing.  Shell prompts that contain escape sequences for
3296 coloring cause parsing problems.  @ref{Remote shell setup} for
3297 customizing prompt detection using regular expressions.
3299 To check if the remote host's prompt is being recognized, use this
3300 test: switch to @value{tramp} connection buffer @file{*tramp/foo*},
3301 put the cursor at the top of the buffer, and then apply the following
3302 expression:
3304 @example
3305 @kbd{M-: (re-search-forward (concat tramp-shell-prompt-pattern "$"))}
3306 @end example
3308 If the cursor has not moved to the prompt at the bottom of the buffer,
3309 then @value{tramp} has failed to recognize the prompt.
3311 When using zsh on remote hosts, disable zsh line editor because zsh
3312 uses left-hand side and right-hand side prompts in parallel.  Add the
3313 following line to @file{~/.zshrc}:
3315 @example
3316 [ $TERM = "dumb" ] && unsetopt zle && PS1='$ '
3317 @end example
3319 When using fish shell on remote hosts, disable fancy formatting by
3320 adding the following to @file{~/.config/fish/config.fish}:
3322 @example
3323 @group
3324 function fish_prompt
3325   if test $TERM = "dumb"
3326      echo "\$ "
3327   else
3328      @dots{}
3329   end
3331 @end group
3332 @end example
3334 When using WinSSHD on remote hosts, @value{tramp} does not recognize
3335 the strange prompt settings.
3337 A similar problem exist with the iTerm2 shell integration, which sends
3338 proprietary escape codes when starting a shell.  This can be
3339 suppressed by changing the respective integration snippet in your
3340 @file{~/.profile} like this:
3342 @example
3343 @group
3344 [ $TERM = "dumb" ] || \
3345 test -e "$@{HOME@}/.iterm2_shell_integration.bash" && \
3346 source "$@{HOME@}/.iterm2_shell_integration.bash"
3347 @end group
3348 @end example
3350 @item
3351 Echoed characters after login
3353 @value{tramp} suppresses echos from remote hosts with the
3354 @command{stty -echo} command.  But sometimes it is too late to suppress
3355 welcome messages from the remote host containing harmful control
3356 characters.  Using @option{sshx} or @option{scpx} methods can avoid
3357 this problem because they allocate a pseudo tty.  @xref{Inline
3358 methods}.
3360 @item
3361 @value{tramp} stops transferring strings longer than 500 characters
3363 Set @code{tramp-chunksize} to 500 to get around this problem, which is
3364 related to faulty implementation of @code{process-send-string} on
3365 HP-UX, FreeBSD and Tru64 Unix systems.  Consult the documentation for
3366 @code{tramp-chunksize} to see when this is necessary.
3368 Set @code{file-precious-flag} to @code{t} for files accessed by
3369 @value{tramp} so the file contents are checked using checksum by
3370 first saving to a temporary file.
3371 @ifinfo
3372 @pxref{Saving Buffers, , , elisp}
3373 @end ifinfo
3375 @lisp
3376 @group
3377 (add-hook
3378  'find-file-hook
3379  (lambda ()
3380    (when (file-remote-p default-directory)
3381      (set (make-local-variable 'file-precious-flag) t))))
3382 @end group
3383 @end lisp
3384 @end itemize
3387 @item
3388 @value{tramp} does not recognize if a @command{ssh} session hangs
3390 @command{ssh} sessions on the local host hang when the network is
3391 down.  @value{tramp} cannot safely detect such hangs.  The network
3392 configuration for @command{ssh} can be configured to kill such hangs
3393 with the following command in the @file{~/.ssh/config}:
3395 @example
3396 @group
3397 Host *
3398      ServerAliveInterval 5
3399 @end group
3400 @end example
3403 @item
3404 @value{tramp} does not use default @command{ssh} @code{ControlPath}
3406 @value{tramp} overwrites @code{ControlPath} settings when initiating
3407 @command{ssh} sessions.  @value{tramp} does this to fend off a stall
3408 if a master session opened outside the Emacs session is no longer
3409 open.  That is why @value{tramp} prompts for the password again even
3410 if there is an @command{ssh} already open.
3412 @vindex tramp-ssh-controlmaster-options
3413 Some @command{ssh} versions support a @code{ControlPersist} option,
3414 which allows you to set the @code{ControlPath} provided the variable
3415 @code{tramp-ssh-controlmaster-options} is customized as follows:
3417 @lisp
3418 @group
3419 (customize-set-variable
3420  'tramp-ssh-controlmaster-options
3421  (concat
3422    "-o ControlPath=/tmp/ssh-ControlPath-%%r@@%%h:%%p "
3423    "-o ControlMaster=auto -o ControlPersist=yes"))
3424 @end group
3425 @end lisp
3427 Note how "%r", "%h" and "%p" must be encoded as "%%r", "%%h" and
3428 "%%p".
3430 @vindex tramp-use-ssh-controlmaster-options
3431 If the @file{~/.ssh/config} is configured appropriately for the above
3432 behavior, then any changes to @command{ssh} can be suppressed with
3433 this @code{nil} setting:
3435 @lisp
3436 (customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
3437 @end lisp
3440 @item
3441 File name completion does not work with @value{tramp}
3443 @acronym{ANSI} escape sequences from the remote shell may cause errors
3444 in @value{tramp}'s parsing of remote buffers.
3446 To test if this is the case, open a remote shell and check if the output
3447 of @command{ls} is in color.
3449 To disable @acronym{ANSI} escape sequences from the remote hosts,
3450 disable @samp{--color=yes} or @samp{--color=auto} in the remote host's
3451 @file{.bashrc} or @file{.profile}.  Turn this alias on and off to see
3452 if file name completion works.
3454 @item
3455 File name completion does not work in directories with large number of
3456 files
3458 This may be related to globbing, which is the use of shell's ability
3459 to expand wild card specifications, such as @samp{*.c}.  For
3460 directories with large number of files, globbing might exceed the
3461 shell's limit on length of command lines and hang.  @value{tramp} uses
3462 globbing.
3464 To test if globbing hangs, open a shell on the remote host and then
3465 run @command{ls -d * ..?* > /dev/null}.
3467 When testing, ensure the remote shell is the same shell
3468 (@command{/bin/sh}, @command{ksh} or @command{bash}), that
3469 @value{tramp} uses when connecting to that host.
3472 @item
3473 How to get notified after @value{tramp} completes file transfers?
3475 Make Emacs beep after reading from or writing to the remote host with
3476 the following code in @file{~/.emacs} file.
3478 @lisp
3479 @group
3480 (defadvice tramp-handle-write-region
3481   (after tramp-write-beep-advice activate)
3482   "Make tramp beep after writing a file."
3483   (interactive)
3484   (beep))
3485 @end group
3487 @group
3488 (defadvice tramp-handle-do-copy-or-rename-file
3489   (after tramp-copy-beep-advice activate)
3490   "Make tramp beep after copying a file."
3491   (interactive)
3492   (beep))
3493 @end group
3495 @group
3496 (defadvice tramp-handle-insert-file-contents
3497   (after tramp-insert-beep-advice activate)
3498   "Make tramp beep after inserting a file."
3499   (interactive)
3500   (beep))
3501 @end group
3502 @end lisp
3505 @item
3506 How to get a Visual Warning when working with @samp{root} privileges?
3507 Host indication in the mode line?
3509 Install @file{tramp-theme} from GNU ELPA via Emacs' Package Manager.
3510 Enable it via @kbd{M-x load-theme @key{RET} tramp}.  Further
3511 customization is explained in user option
3512 @option{tramp-theme-face-remapping-alist}.
3515 @item
3516 Remote host does not understand default options for directory listing
3518 Emacs computes the @command{dired} options based on the local host but
3519 if the remote host cannot understand the same @command{ls} command,
3520 then set them with a hook as follows:
3522 @lisp
3523 @group
3524 (add-hook
3525  'dired-before-readin-hook
3526  (lambda ()
3527    (when (file-remote-p default-directory)
3528      (setq dired-actual-switches "-al"))))
3529 @end group
3530 @end lisp
3533 @item
3534 Why is @file{~/.sh_history} file on the remote host growing?
3536 Due to the remote shell saving tilde expansions triggered by
3537 @value{tramp}, the history file is probably growing rapidly.
3538 @value{tramp} can suppress this behaviour with the user option
3539 @code{tramp-histfile-override}.  When set to @code{t}, environment
3540 variable @env{HISTFILE} is unset, and environment variables
3541 @env{HISTFILESIZE} @env{HISTSIZE} are set to 0.
3543 Alternatively, @code{tramp-histfile-override} could be a string.
3544 Environment variable @env{HISTFILE} is set to this file name then.  Be
3545 careful when setting to @file{/dev/null}; this might result in
3546 undesired results when using @command{bash} as remote shell.
3548 Another approach is to disable @value{tramp}'s handling of the
3549 @env{HISTFILE} at all by setting @code{tramp-histfile-override} to
3550 @code{nil}.  In this case, saving history could be turned off by
3551 putting this shell code in the @file{.bashrc} or @file{.kshrc} file:
3553 @example
3554 @group
3555 if [ -f $HOME/.sh_history ] ; then
3556    /bin/rm $HOME/.sh_history
3558 if [ "$@{HISTFILE-unset@}" != "unset" ] ; then
3559    unset HISTFILE
3561 if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then
3562    unset HISTSIZE
3564 @end group
3565 @end example
3567 For @option{ssh}-based method, add the following line to your
3568 @file{~/.ssh/environment} file:
3570 @example
3571 HISTFILE=/dev/null
3572 @end example
3575 @item
3576 How to shorten long file names when typing in @value{tramp}?
3578 Adapt several of these approaches to reduce typing.  If the full name
3579 is @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, then:
3581 @enumerate
3583 @item
3584 Use default values for method name and user name:
3586 You can define default methods and user names for hosts,
3587 (@pxref{Default Method}, @pxref{Default User}):
3589 @lisp
3590 @group
3591 (custom-set-variables
3592  '(tramp-default-method "ssh")
3593  '(tramp-default-user "news"))
3594 @end group
3595 @end lisp
3597 The reduced typing: @kbd{C-x C-f @trampfn{-,news.my.domain,/opt/news/etc}}.
3599 @strong{Note} that there are some useful shortcuts already.  Accessing
3600 your local host as @samp{root} user, is possible just by @kbd{C-x C-f
3601 @trampfn{su,,}}.
3603 @item
3604 Use configuration options of the access method:
3606 Programs used for access methods already offer powerful configurations
3607 (@pxref{Customizing Completion}).  For @option{ssh}, configure the
3608 file @file{~/.ssh/config}:
3610 @example
3611 @group
3612 Host xy
3613      HostName news.my.domain
3614      User news
3615 @end group
3616 @end example
3618 The reduced typing: @kbd{C-x C-f @trampfn{ssh,xy,/opt/news/etc}}.
3620 Depending on the number of files in the directories, host names
3621 completion can further reduce key strokes: @kbd{C-x C-f
3622 @value{prefix}ssh@value{postfixhop}x @key{TAB}}.
3624 @item
3625 Use environment variables to expand long strings
3627 For long file names, set up environment variables that are expanded in
3628 the minibuffer.  Environment variables are set either outside Emacs or
3629 inside Emacs with Lisp:
3631 @lisp
3632 (setenv "xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")
3633 @end lisp
3635 The reduced typing: @kbd{C-x C-f $xy @key{RET}}.
3637 @strong{Note} that file name cannot be edited here because the
3638 environment variables are not expanded during editing in the
3639 minibuffer.
3641 @item Define own keys:
3643 Redefine another key sequence in Emacs for @kbd{C-x C-f}:
3645 @lisp
3646 @group
3647 (global-set-key
3648  [(control x) (control y)]
3649  (lambda ()
3650    (interactive)
3651    (find-file
3652     (read-file-name
3653      "Find @value{tramp} file: "
3654      "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))))
3655 @end group
3656 @end lisp
3658 Simply typing @kbd{C-x C-y} would prepare minibuffer editing of file
3659 name.
3661 See @uref{https://www.emacswiki.org/emacs/TrampMode, the Emacs Wiki}
3662 for a more comprehensive example.
3664 @item
3665 Define own abbreviation (1):
3667 Abbreviation list expansion can be used to reduce typing long file names:
3669 @lisp
3670 @group
3671 (add-to-list
3672  'directory-abbrev-alist
3673  '("^/xy" . "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
3674 @end group
3675 @end lisp
3677 The reduced typing: @kbd{C-x C-f /xy @key{RET}}.
3679 @strong{Note} that file name cannot be edited here because the
3680 environment variables are not expanded during editing in the
3681 minibuffer.
3683 @item
3684 Define own abbreviation (2):
3686 The @code{abbrev-mode} gives additional flexibility for editing in the
3687 minibuffer:
3689 @lisp
3690 @group
3691 (define-abbrev-table 'my-tramp-abbrev-table
3692   '(("xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")))
3693 @end group
3695 @group
3696 (add-hook
3697  'minibuffer-setup-hook
3698  (lambda ()
3699    (abbrev-mode 1)
3700    (setq local-abbrev-table my-tramp-abbrev-table)))
3701 @end group
3703 @group
3704 (defadvice minibuffer-complete
3705   (before my-minibuffer-complete activate)
3706   (expand-abbrev))
3707 @end group
3709 @group
3710 ;; If you use partial-completion-mode
3711 (defadvice PC-do-completion
3712   (before my-PC-do-completion activate)
3713   (expand-abbrev))
3714 @end group
3715 @end lisp
3717 The reduced typing: @kbd{C-x C-f xy @key{TAB}}.
3719 The minibuffer expands for further editing.
3721 @item Use bookmarks:
3723 Use bookmarks to save @value{tramp} file names.
3724 @ifinfo
3725 @pxref{Bookmarks, , , emacs}.
3726 @end ifinfo
3728 Upon visiting a location with @value{tramp}, save it as a bookmark with
3729 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{set}}.
3731 To revisit that bookmark:
3732 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{jump}}.
3734 @item Use recent files:
3736 @file{recentf} remembers visited places.
3737 @ifinfo
3738 @pxref{File Conveniences, , , emacs}.
3739 @end ifinfo
3741 Keep remote file names in the recent list without have to check for
3742 their accessibility through remote access:
3744 @lisp
3745 (recentf-mode 1)
3746 @end lisp
3748 Reaching recently opened files: @kbd{@key{menu-bar} @key{file}
3749 @key{Open Recent}}.
3751 @item Use filecache:
3753 Since @file{filecache} remembers visited places, add the remote
3754 directory to the cache:
3756 @lisp
3757 @group
3758 @c `with-eval-after-load' has been introduced with Emacs 24.4.  Shall
3759 @c be used when appropriate.
3760 (eval-after-load "filecache"
3761   '(file-cache-add-directory
3762     "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
3763 @end group
3764 @end lisp
3766 Then use directory completion in the minibuffer with @kbd{C-x C-f
3767 C-@key{TAB}}.
3769 @item Use bbdb:
3771 @file{bbdb} has a built-in feature for Ange FTP files, which also
3772 works for @value{tramp} file names.
3773 @ifinfo
3774 @pxref{bbdb-ftp, Storing FTP sites in the BBDB, , bbdb}.
3775 @end ifinfo
3777 Load @file{bbdb} in Emacs:
3779 @lisp
3780 @group
3781 (require 'bbdb)
3782 (bbdb-initialize)
3783 @end group
3784 @end lisp
3786 Create a BBDB entry with @kbd{M-x bbdb-create-ftp-site}.  Then specify
3787 a method and user name where needed.  Examples:
3789 @example
3790 @group
3791 @kbd{M-x bbdb-create-ftp-site @key{RET}}
3792 @b{Ftp Site:} news.my.domain @key{RET}
3793 @b{Ftp Directory:} /opt/news/etc/ @key{RET}
3794 @b{Ftp Username:} ssh@value{postfixhop}news @key{RET}
3795 @b{Company:} @key{RET}
3796 @b{Additional Comments:} @key{RET}
3797 @end group
3798 @end example
3800 In BBDB buffer, access an entry by pressing the key @key{F}.
3802 @end enumerate
3804 Thanks to @value{tramp} users for contributing to these recipes.
3806 @item
3807 Why saved multi-hop file names do not work in a new Emacs session?
3809 When saving ad-hoc multi-hop @value{tramp} file names (@pxref{Ad-hoc
3810 multi-hops}) via bookmarks, recent files, filecache, bbdb, or another
3811 package, use the full ad-hoc file name including all hops, like
3812 @file{@trampfn{ssh,bird@@bastion|ssh@value{postfixhop}news.my.domain,/opt/news/etc}}.
3814 Alternatively, when saving abbreviated multi-hop file names
3815 @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, the user
3816 option @option{tramp-save-ad-hoc-proxies} must be set non-@code{nil}
3817 value.
3820 @item
3821 How to connect to a remote Emacs session using @value{tramp}?
3823 Configure Emacs Client
3824 @ifinfo
3825 (@pxref{Emacs Server, , , emacs}).
3826 @end ifinfo
3828 Then on the remote host, start the Emacs Server:
3830 @lisp
3831 @group
3832 (require 'server)
3833 (setq server-host (system-name)
3834       server-use-tcp t)
3835 (server-start)
3836 @end group
3837 @end lisp
3839 If @code{(system-name)} of the remote host cannot be resolved on the
3840 local host, use IP address instead.
3842 Copy from the remote host the resulting file
3843 @file{~/.emacs.d/server/server} to the local host, to the same
3844 location.
3846 Then start Emacs Client from the command line:
3848 @example
3849 emacsclient @trampfn{ssh,user@@host,/file/to/edit}
3850 @end example
3852 @code{user} and @code{host} refer to the local host.
3854 To make Emacs Client an editor for other programs, use a wrapper
3855 script @file{emacsclient.sh}:
3857 @example
3858 @group
3859 #!/bin/sh
3860 emacsclient @trampfn{ssh,$(whoami)@@$(hostname --fqdn),$1}
3861 @end group
3862 @end example
3864 Then change the environment variable @env{EDITOR} to point to the
3865 wrapper script:
3867 @example
3868 export EDITOR=/path/to/emacsclient.sh
3869 @end example
3872 @item
3873 How to disable other packages from calling @value{tramp}?
3875 There are packages that call @value{tramp} without the user ever
3876 entering a remote file name.  Even without applying a remote file
3877 syntax, some packages enable @value{tramp} on their own.  How can users
3878 disable such features.
3880 @itemize @minus
3881 @item
3882 @file{ido.el}
3884 Disable @value{tramp} file name completion:
3886 @lisp
3887 (customize-set-variable 'ido-enable-tramp-completion nil)
3888 @end lisp
3890 @item
3891 @file{rlogin.el}
3893 Disable remote directory tracking mode:
3895 @lisp
3896 (rlogin-directory-tracking-mode -1)
3897 @end lisp
3898 @end itemize
3901 @item
3902 How to disable @value{tramp}?
3904 @itemize @minus
3905 @item
3906 To keep Ange FTP as default the remote files access package, set this
3907 in @file{.emacs}:
3909 @lisp
3910 (customize-set-variable 'tramp-default-method "ftp")
3911 @end lisp
3913 @item
3914 To disable both @value{tramp} (and Ange FTP), set @code{tramp-mode} to
3915 @code{nil} in @file{.emacs}.  @strong{Note}, that we don't use
3916 @code{customize-set-variable}, in order to avoid loading @value{tramp}.
3918 @lisp
3919 (setq tramp-mode nil)
3920 @end lisp
3922 @item
3923 To unload @value{tramp}, type @kbd{M-x tramp-unload-tramp}.  Unloading
3924 @value{tramp} resets Ange FTP plugins also.
3925 @end itemize
3926 @end itemize
3929 @c For the developer
3930 @node Files directories and localnames
3931 @chapter How file names, directories and localnames are mangled and managed.
3933 @menu
3934 * Localname deconstruction::    Splitting a localname into its component parts.
3935 * External packages::           Integrating with external Lisp packages.
3936 @end menu
3939 @node Localname deconstruction
3940 @section Splitting a localname into its component parts
3942 @value{tramp} package redefines lisp functions
3943 @code{file-name-directory} and @code{file-name-nondirectory} to
3944 accommodate the unique file naming syntax that @value{tramp} requires.
3946 The replacements dissect the file name, use the original handler for
3947 the localname, take that result, and then re-build the @value{tramp}
3948 file name.  By relying on the original handlers for localnames,
3949 @value{tramp} benefits from platform specific hacks to the original
3950 handlers.
3953 @node External packages
3954 @section Integrating with external Lisp packages
3955 @subsection File name completion.
3957 Sometimes, it is not convenient to open a new connection to a remote
3958 host, including entering the password and alike.  For example, this is
3959 nasty for packages providing file name completion. Such a package
3960 could signal to @value{tramp}, that they don't want it to establish a
3961 new connection.  Use the variable @code{non-essential} temporarily and
3962 bind it to non-@code{nil} value.
3964 @lisp
3965 @group
3966 (let ((non-essential t))
3967   @dots{})
3968 @end group
3969 @end lisp
3972 @subsection File attributes cache.
3974 Keeping a local cache of remote file attributes in sync with the
3975 remote host is a time-consuming operation.  Flushing and re-querying
3976 these attributes can tax @value{tramp} to a grinding halt on busy
3977 remote servers.
3979 To get around these types of slow-downs in @value{tramp}'s
3980 responsiveness, set the @code{process-file-side-effects} to @code{nil}
3981 to stop @value{tramp} from flushing the cache.  This is helpful in
3982 situations where callers to @code{process-file} know there are no file
3983 attribute changes.  The let-bind form to accomplish this:
3985 @lisp
3986 @group
3987 (let (process-file-side-effects)
3988   @dots{})
3989 @end group
3990 @end lisp
3992 For asynchronous processes, @value{tramp} uses a process sentinel to
3993 flush file attributes cache.  When callers to @code{start-file-process}
3994 know beforehand no file attribute changes are expected, then the
3995 process sentinel should be set to the default state.  In cases where
3996 the caller defines its own process sentinel, @value{tramp}'s process
3997 sentinel is overwritten.  The caller can still flush the file
3998 attributes cache in its process sentinel with this code:
4000 @lisp
4001 @group
4002 (unless (memq (process-status proc) '(run open))
4003   (dired-uncache remote-directory))
4004 @end group
4005 @end lisp
4007 Since @value{tramp} traverses subdirectories starting with the
4008 root-directory, it is most likely sufficient to make the
4009 @code{default-directory} of the process buffer as the root directory.
4012 @node Traces and Profiles
4013 @chapter How to Customize Traces
4015 @value{tramp} messages are raised with verbosity levels ranging from 0
4016 to 10.  @value{tramp} does not display all messages; only those with a
4017 verbosity level less than or equal to @code{tramp-verbose}.
4019 The verbosity levels are
4021           @w{ 0}  silent (no @value{tramp} messages at all)
4022 @*@indent @w{ 1}  errors
4023 @*@indent @w{ 2}  warnings
4024 @*@indent @w{ 3}  connection to remote hosts (default verbosity)
4025 @*@indent @w{ 4}  activities
4026 @*@indent @w{ 5}  internal
4027 @*@indent @w{ 6}  sent and received strings
4028 @*@indent @w{ 7}  file caching
4029 @*@indent @w{ 8}  connection properties
4030 @*@indent @w{ 9}  test commands
4031 @*@indent @w{10}  traces (huge)
4033 With @code{tramp-verbose} greater than or equal to 4, messages are
4034 also written to a @value{tramp} debug buffer.  Such debug buffers are
4035 essential to bug and problem analyses.  For @value{tramp} bug reports,
4036 set the @code{tramp-verbose} level to 6 (@pxref{Bug Reports}).
4038 The debug buffer is in
4039 @ifinfo
4040 @ref{Outline Mode, , , emacs}.
4041 @end ifinfo
4042 @ifnotinfo
4043 Outline Mode.
4044 @end ifnotinfo
4045 In this buffer, messages can be filtered by their level.  To see
4046 messages up to verbosity level 5, enter @kbd{C-u 6 C-c C-q}.
4047 @ifinfo
4048 Other navigation keys are described in
4049 @ref{Outline Visibility, , , emacs}.
4050 @end ifinfo
4052 @value{tramp} handles errors internally.  But to get a Lisp backtrace,
4053 both the error and the signal have to be set as follows:
4055 @lisp
4056 @group
4057 (setq debug-on-error t
4058       debug-on-signal t)
4059 @end group
4060 @end lisp
4062 If @code{tramp-verbose} is greater than or equal to 10, Lisp
4063 backtraces are also added to the @value{tramp} debug buffer in case of
4064 errors.
4066 To enable stepping through @value{tramp} function call traces, they
4067 have to be specifically enabled as shown in this code:
4069 @lisp
4070 @group
4071 (require 'trace)
4072 (dolist (elt (all-completions "tramp-" obarray 'functionp))
4073   (trace-function-background (intern elt)))
4074 (untrace-function 'tramp-read-passwd)
4075 @end group
4076 @end lisp
4078 The buffer @file{*trace-output*} contains the output from the function
4079 call traces.  Disable @code{tramp-read-passwd} to stop password
4080 strings from being written to @file{*trace-output*}.
4083 @node GNU Free Documentation License
4084 @appendix GNU Free Documentation License
4085 @include doclicense.texi
4088 @node Function Index
4089 @unnumbered Function Index
4090 @printindex fn
4093 @node Variable Index
4094 @unnumbered Variable Index
4095 @printindex vr
4098 @node Concept Index
4099 @unnumbered Concept Index
4100 @printindex cp
4102 @bye
4104 @c TODO
4106 @c * Say something about the .login and .profile files of the remote
4107 @c   shells.
4108 @c * Explain how tramp.el works in principle: open a shell on a remote
4109 @c   host and then send commands to it.
4110 @c * Consistent small or capitalized words especially in menus.