Format shell commands in tramp.texi
[emacs.git] / doc / misc / tramp.texi
blob47055793b730462567ab99ad50a7109a08c2e08e
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--2017 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/archive/html/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.
168 How file names, directories and localnames are mangled and managed
170 * Localname deconstruction::    Breaking a localname into its components.
171 * External packages::           Integration with external Lisp packages.
173 @end detailmenu
174 @end menu
177 @node Overview
178 @chapter An overview of @value{tramp}
179 @cindex overview
181 @value{tramp} is for transparently accessing remote files from within
182 Emacs.  @value{tramp} enables an easy, convenient, and consistent
183 interface to remote files as if they are local files.  @value{tramp}'s
184 transparency extends to editing, version control, and @code{dired}.
186 @value{tramp} can access remote hosts using any number of access
187 methods, such as @command{rsh}, @command{rlogin}, @command{telnet},
188 and related programs.  If these programs can successfully pass
189 @acronym{ASCII} characters, @value{tramp} can use them.
190 @value{tramp} does not require or mandate 8-bit clean connections.
192 @value{tramp}'s most common access method is through @command{ssh}, a
193 more secure alternative to @command{ftp} and other older access
194 methods.
196 @value{tramp} on MS Windows operating systems is integrated with the
197 PuTTY package, and uses the @command{plink} program.
199 @value{tramp} mostly operates transparently in the background using
200 the connection programs.  As long as these programs enable remote login
201 and can use the terminal, @value{tramp} can adapt them for seamless
202 and transparent access.
204 @value{tramp} temporarily transfers a remote file's contents to the
205 local host editing and related operations.  @value{tramp} can also
206 transfer files between hosts using standard Emacs interfaces, a
207 benefit of direct integration of @value{tramp} in Emacs.
209 @value{tramp} can transfer files using any number of available host
210 programs for remote files, such as @command{rcp}, @command{scp},
211 @command{rsync} or (under MS Windows) @command{pscp}.  @value{tramp}
212 provides easy ways to specify these programs and customize them to
213 specific files, hosts, or access methods.
215 For faster small-size file transfers, @value{tramp} supports encoded
216 transfers directly through the shell using @command{mimencode} or
217 @command{uuencode} provided such tools are available on the remote
218 host.
221 @subsubheading @value{tramp} behind the scenes
222 @cindex behind the scenes
223 @cindex details of operation
224 @cindex how it works
226 Accessing a remote file through @value{tramp} entails a series of
227 actions, many of which are transparent to the user.  Yet some actions
228 may require user response (such as entering passwords or completing
229 file names).  One typical scenario, opening a file on a remote host, is
230 presented here to illustrate the steps involved:
232 @kbd{C-x C-f} to initiate find-file, enter part of the @value{tramp}
233 file name, then hit @kbd{@key{TAB}} for completion.  If this is the
234 first time connection to that host, here's what happens:
236 @itemize
237 @item
238 @value{tramp} invokes @samp{telnet @var{host}} or @samp{rsh @var{host}
239 -l @var{user}} and establishes an external process to connect to the
240 remote host.  @value{tramp} communicates with the process through an
241 Emacs buffer, which also shows output from the remote host.
243 @item
244 The remote host may prompt for a login name (for @command{telnet}, for
245 example) in the buffer.  If on the other hand, the login name was
246 included in the file name portion, @value{tramp} sends the login name
247 followed by a newline.
249 @item
250 The remote host may then prompt for a password or pass phrase (for
251 @command{rsh} or for @command{telnet}).  @value{tramp} displays the
252 password prompt in the minibuffer.  @value{tramp} then sends whatever
253 is entered to the remote host, followed by a newline.
255 @item
256 @value{tramp} now waits for either the shell prompt or a failed login
257 message.
259 If @value{tramp} does not receive any messages within a timeout period
260 (a minute, for example), then @value{tramp} responds with an error
261 message about not finding the remote shell prompt.  If any messages
262 from the remote host, @value{tramp} displays them in the buffer.
264 For any @samp{login failed} message from the remote host,
265 @value{tramp} aborts the login attempt, and repeats the login steps
266 again.
268 @item
269 Upon successful login and @value{tramp} recognizes the shell prompt
270 from the remote host, @value{tramp} prepares the shell environment by
271 turning off echoing, setting shell prompt, and other housekeeping
272 chores.
274 @strong{Note} that for the remote shell, @value{tramp} invokes
275 @command{/bin/sh}.  The remote host must recognize @samp{exec /bin/sh}
276 and execute the appropriate shell.  This shell must support Bourne
277 shell syntax.
279 @item
280 @value{tramp} executes @command{cd} and @command{ls} commands to find
281 which files exist on the remote host.  @value{tramp} sometimes uses
282 @command{echo} with globbing.  @value{tramp} checks if a file or
283 directory is writable with @command{test}.  After each command,
284 @value{tramp} parses the output from the remote host for completing
285 the next operation.
287 @item
288 After remote file name completion, @value{tramp} transfers the file
289 contents from the remote host.
291 For inline transfers, @value{tramp} sends a command, such as
292 @samp{mimencode -b /path/to/remote/file}, waits until the output has
293 accumulated in the buffer, decodes that output to produce the file's
294 contents.
296 For external transfers, @value{tramp} sends a command as follows:
297 @example
298 rcp user@@host:/path/to/remote/file /tmp/tramp.4711
299 @end example
300 @value{tramp} reads the local temporary file @file{/tmp/tramp.4711}
301 into a buffer, and then deletes the temporary file.
303 @item
304 Edit, modify, change the buffer contents as normal, and then save the
305 buffer wth @kbd{C-x C-s}.
307 @item
308 @value{tramp} transfers the buffer contents to the remote host in
309 a reverse of the process using the appropriate inline or external
310 program.
311 @end itemize
313 I hope this has provided you with a basic overview of what happens
314 behind the scenes when you open a file with @value{tramp}.
317 @c For the end user
318 @node Obtaining @value{tramp}
319 @chapter Obtaining @value{tramp}
320 @cindex obtaining @value{tramp}
322 @value{tramp} is included as part of Emacs (since Emacs version 22.1).
324 @value{tramp} is also freely packaged for download on the Internet at
325 @uref{https://ftp.gnu.org/gnu/tramp/}.
327 @value{tramp} development versions are available on Git servers.
328 Development versions contain new and incomplete features.
330 One way to obtain from Git server is to visit the Savannah project
331 page at the following URL and then clicking on the Git link in the
332 navigation bar at the top.
334 @noindent
335 @uref{https://savannah.gnu.org/projects/tramp/}
337 @noindent
338 Another way is to follow the terminal session below:
340 @example
341 @group
342 $ cd ~/emacs
343 $ git clone git://git.savannah.gnu.org/tramp.git
344 @end group
345 @end example
347 @noindent
348 From behind a firewall:
350 @example
351 @group
352 $ git config --global http.proxy http://user:pwd@@proxy.server.com:8080
353 $ git clone https://git.savannah.gnu.org/r/tramp.git
354 @end group
355 @end example
357 @noindent
358 @value{tramp} developers:
360 @example
361 $ git clone login@@git.sv.gnu.org:/srv/git/tramp.git
362 @end example
364 @noindent
365 After one of the above commands, @file{~/emacs/tramp} will
366 containing the latest version of @value{tramp}.
368 @noindent
369 To fetch updates from the repository, use git pull:
371 @example
372 @group
373 $ cd ~/emacs/tramp
374 $ git pull
375 @end group
376 @end example
378 @noindent
379 Run @command{autoconf} as follows to generate an up-to-date
380 @file{configure} script:
382 @example
383 @group
384 $ cd ~/emacs/tramp
385 $ autoconf
386 @end group
387 @end example
390 @node History
391 @chapter History of @value{tramp}
392 @cindex history
393 @cindex development history
395 @value{tramp} development started at the end of November 1998 as
396 @file{rssh.el}.  It provided only one method of access.  It used
397 @command{ssh} for login and @command{scp} to transfer file contents.
398 The name was changed to @file{rcp.el} before it got its present name
399 @value{tramp}.  New methods of remote access were added, so was support
400 for version control.
402 April 2000 was the first time when multi-hop methods were added.  In
403 July 2002, @value{tramp} unified file names with Ange FTP@.  In July
404 2004, proxy hosts replaced multi-hop methods.  Running commands on
405 remote hosts was introduced in December 2005.  Support for gateways
406 since April 2007 (and removed in December 2016).  GVFS integration
407 started in February 2009.  Remote commands on MS Windows hosts since
408 September 2011.  Ad-hoc multi-hop methods (with a changed syntax)
409 re-enabled in November 2011.  In November 2012, added Juergen
410 Hoetzel's @file{tramp-adb.el}.
412 XEmacs support was stopped in January 2016.  Since March 2017,
413 @value{tramp} syntax mandates a method.
415 @c Installation chapter is necessary only in case of standalone
416 @c installation.  Text taken from trampinst.texi.
417 @ifset installchapter
418 @include trampinst.texi
419 @end ifset
422 @node Quick Start Guide
423 @chapter Short introduction how to use @value{tramp}
424 @cindex quick start guide
426 @value{tramp} extends the Emacs file name syntax by a remote
427 component.  A remote file name looks always like
428 @file{@trampfn{method,user@@host,/path/to/file}}.
430 You can use remote files exactly like ordinary files, that means you
431 could open a file or directory by @kbd{C-x C-f
432 @trampfn{method,user@@host,/path/to/file} @key{RET}}, edit the file,
433 and save it.  You can also mix local files and remote files in file
434 operations with two arguments, like @code{copy-file} or
435 @code{rename-file}.  And finally, you can run even processes on a
436 remote host, when the buffer you call the process from has a remote
437 @code{default-directory}.
440 @anchor{Quick Start Guide: File name syntax}
441 @section File name syntax
442 @cindex file name syntax
444 Remote file names are prepended by the @code{method}, @code{user} and
445 @code{host} parts.  All of them, and also the local file name part,
446 are optional, in case of a missing part a default value is assumed.
447 The default value for an empty local file name part is the remote
448 user's home directory.  The shortest remote file name is
449 @file{@trampfn{-,,}}, therefore.  The @samp{-} notation for the
450 default host is used for syntactical reasons, @ref{Default Host}.
452 The @code{method} part describes the connection method used to reach
453 the remote host, see below.
455 The @code{user} part is the user name for accessing the remote host.
456 For the @option{smb} method, this could also require a domain name, in
457 this case it is written as @code{user%domain}.
459 The @code{host} part must be a host name which could be resolved on
460 your local host.  It could be a short host name, a fully qualified
461 domain name, an IPv4 or IPv6 address, @ref{File name syntax}.  Some
462 connection methods support also a notation of the port to be used, in
463 this case it is written as @code{host#port}.
466 @anchor{Quick Start Guide: @option{ssh} and @option{plink} methods}
467 @section Using @option{ssh} and @option{plink}
468 @cindex method ssh
469 @cindex ssh method
470 @cindex method plink
471 @cindex plink method
473 If your local host runs an SSH client, and the remote host runs an SSH
474 server, the most simple remote file name is
475 @file{@trampfn{ssh,user@@host,/path/to/file}}.  The remote file name
476 @file{@trampfn{ssh,,}} opens a remote connection to yourself on the
477 local host, and is taken often for testing @value{tramp}.
479 On MS Windows, PuTTY is often used as SSH client.  Its @command{plink}
480 method can be used there to open a connection to a remote host running
481 an @command{ssh} server:
482 @file{@trampfn{plink,user@@host,/path/to/file}}.
485 @anchor{Quick Start Guide: @option{su}, @option{sudo} and @option{sg} methods}
486 @section Using @option{su}, @option{sudo} and @option{sg}
487 @cindex method su
488 @cindex su method
489 @cindex method sudo
490 @cindex sudo method
491 @cindex method sg
492 @cindex sg method
494 Sometimes, it is necessary to work on your local host under different
495 permissions.  For this, you could use the @option{su} or @option{sudo}
496 connection method.  Both methods use @samp{root} as default user name
497 and the return value of @code{(system-name)} as default host name.
498 Therefore, it is convenient to open a file as
499 @file{@trampfn{sudo,,/path/to/file}}.
501 The method @option{sg} stands for ``switch group''; the changed group
502 must be used here as user name.  The default host name is the same.
505 @anchor{Quick Start Guide: @option{smb} method}
506 @section Using @command{smbclient}
507 @cindex method smb
508 @cindex smb method
509 @cindex ms windows (with smb method)
510 @cindex smbclient
512 In order to access a remote MS Windows host or Samba server, the
513 @command{smbclient} client is used.  The remote file name syntax is
514 @file{@trampfn{smb,user%domain@@host,/path/to/file}}.  The first part
515 of the local file name is the share exported by the remote host,
516 @samp{path} in this example.
519 @anchor{Quick Start Guide: GVFS-based methods}
520 @section Using GVFS-based methods
521 @cindex methods, gvfs
522 @cindex gvfs based methods
523 @cindex method sftp
524 @cindex sftp method
525 @cindex method afp
526 @cindex afp method
527 @cindex method dav
528 @cindex method davs
529 @cindex dav method
530 @cindex davs method
532 On systems, which have installed the virtual file system for the Gnome
533 Desktop (GVFS), its offered methods could be used by @value{tramp}.
534 Examples are @file{@trampfn{sftp,user@@host,/path/to/file}},
535 @file{@trampfn{afp,user@@host,/path/to/file}} (accessing Apple's AFP
536 file system), @file{@trampfn{dav,user@@host,/path/to/file}} and
537 @file{@trampfn{davs,user@@host,/path/to/file}} (for WebDAV shares).
540 @anchor{Quick Start Guide: Google Drive}
541 @section Using Google Drive
542 @cindex method gdrive
543 @cindex gdrive method
544 @cindex google drive
546 Another GVFS-based method allows to access a Google Drive file system.
547 The file name syntax is here always
548 @file{@trampfn{gdrive,john.doe@@gmail.com,/path/to/file}}.
549 @samp{john.doe@@gmail.com} stands here for your Google Drive account.
552 @anchor{Quick Start Guide: Android}
553 @section Using Android
554 @cindex method adb
555 @cindex adb method
556 @cindex android
558 An Android device, which is connected via USB to your local host, can
559 be accessed via the @command{adb} command.  No user or host name is
560 needed.  The file name syntax is @file{@trampfn{adb,,/path/to/file}}.
563 @node Configuration
564 @chapter Configuring @value{tramp}
565 @cindex configuration
566 @cindex default configuration
568 @value{tramp} is initially configured to use the @command{scp} program
569 to connect to the remote host.  Just type @kbd{C-x C-f} and then enter
570 file name @file{@trampfn{scp,user@@host,/path/to/file}}.  For details,
571 @xref{Default Method}, @xref{Default User}, @xref{Default Host}.
573 For problems related to the behavior of the remote shell, @xref{Remote
574 shell setup}.
576 For changing the connection type and file access method from the
577 defaults to one of several other options, @xref{Connection types}.
579 @strong{Note} that some user options described in these examples are
580 not auto loaded by Emacs.  All examples require @value{tramp} is
581 installed and loaded:
583 @lisp
584 @group
585 (custom-set-variables
586  '(tramp-verbose 6 nil (tramp) "Enable remote command traces"))
587 @end group
588 @end lisp
591 @menu
592 * Connection types::            Types of connections to remote hosts.
593 * Inline methods::              Inline methods.
594 * External methods::            External methods.
595 * GVFS based methods::          GVFS based external methods.
596 * Default Method::              Selecting a default method.
597                                   Here we also try to help those who
598                                   don't have the foggiest which method
599                                   is right for them.
600 * Default User::                Selecting a default user.
601 * Default Host::                Selecting a default host.
602 * Multi-hops::                  Connecting to a remote host using multiple hops.
603 * Firewalls::                   Passing firewalls.
604 * Customizing Methods::         Using Non-Standard Methods.
605 * Customizing Completion::      Selecting config files for user/host name completion.
606 * Password handling::           Reusing passwords for several connections.
607 * Connection caching::          Reusing connection related information.
608 * Predefined connection information::
609                                 Setting own connection related information.
610 * Remote programs::             How @value{tramp} finds and uses programs on the remote host.
611 * Remote shell setup::          Remote shell setup hints.
612 * Android shell setup::         Android shell setup hints.
613 * Auto-save and Backup::        Auto-save and Backup.
614 * Windows setup hints::         Issues with Cygwin ssh.
615 @end menu
618 @node Connection types
619 @section Types of connections to remote hosts
620 @cindex connection types, overview
622 @dfn{Inline method} and @dfn{external method} are the two basic types
623 of access methods.  While they both use the same remote shell access
624 programs, such as @command{rsh}, @command{ssh}, or @command{telnet},
625 they differ in the file access methods.  Choosing the right method
626 becomes important for editing files, transferring large files, or
627 operating on a large number of files.
629 The performance of the external methods is generally better than that
630 of the inline methods, at least for large files.  This is caused by
631 the need to encode and decode the data when transferring inline.
633 The one exception to this rule are the @option{scp}-based access
634 methods.  While these methods do see better performance when actually
635 transferring files, the overhead of the cryptographic negotiation at
636 startup may drown out the improvement in file transfer times.
638 External methods should be configured such a way that they don't
639 require a password (with @command{ssh-agent}, or such alike).  Modern
640 @command{scp} implementations offer options to reuse existing
641 @command{ssh} connections, which will be enabled by default if
642 available.  If it isn't possible, you should consider @ref{Password
643 handling}, otherwise you will be prompted for a password every copy
644 action.
647 @node Inline methods
648 @section Inline methods
649 @cindex inline methods
650 @cindex methods, inline
652 Inline methods use the same login connection to transfer file
653 contents.  Inline methods are quick and easy for small files.  They
654 depend on the availability of suitable encoding and decoding programs
655 on the remote host.  For local source and destination, @value{tramp}
656 may use built-in equivalents of such programs in Emacs.
658 Inline methods can work in situations where an external transfer
659 program is unavailable.  Inline methods also work when transferring
660 files between different @emph{user identities} on the same host.
662 @cindex uuencode
663 @cindex mimencode
664 @cindex base-64 encoding
666 @value{tramp} checks the remote host for the availability and
667 usability of @command{mimencode} (part of the @command{metamail}
668 package) or @command{uuencode}.  @value{tramp} uses the first reliable
669 command it finds.  @value{tramp}'s search path can be customized, see
670 @ref{Remote programs}.
672 In case both @command{mimencode} and @command{uuencode} are
673 unavailable, @value{tramp} first transfers a small Perl program to the
674 remote host, and then tries that program for encoding and decoding.
676 To increase transfer speeds for large text files, use compression
677 before encoding.  The user option
678 @option{tramp-inline-compress-start-size} specifies the file size for
679 such optimization.
681 @table @asis
682 @item @option{rsh}
683 @cindex method rsh
684 @cindex rsh method
686 @command{rsh} is an option for connecting to hosts within local
687 networks since @command{rsh} is not as secure as other methods.
689 @item @option{ssh}
690 @cindex method ssh
691 @cindex ssh method
693 @command{ssh} is a more secure option than others to connect to a
694 remote host.
696 @command{ssh} can also take extra parameters as port numbers.  For
697 example, a host on port 42 is specified as @file{host#42} (the real
698 host name, a hash sign, then a port number).  It is the same as passing
699 @samp{-p 42} to the @command{ssh} command.
701 @item @option{telnet}
702 @cindex method telnet
703 @cindex telnet method
705 Connecting to a remote host with @command{telnet} is as insecure
706 as the @option{rsh} method.
708 @item @option{su}
709 @cindex method su
710 @cindex su method
712 Instead of connecting to a remote host, @command{su} program allows
713 editing as another user.  The host can be either @samp{localhost} or
714 the host returned by the function @command{(system-name)}.  See
715 @ref{Multi-hops} for an exception to this behavior.
717 @item @option{sudo}
718 @cindex method sudo
719 @cindex sudo method
721 Similar to @option{su} method, @option{sudo} uses @command{sudo}.
722 @command{sudo} must have sufficient rights to start a shell.
724 @item @option{doas}
725 @cindex method doas
726 @cindex doas method
728 This method is used on OpenBSD like the @command{sudo} command.
730 @item @option{sg}
731 @cindex method sg
732 @cindex sg method
734 The @command{sg} program allows editing as different group.  The host
735 can be either @samp{localhost} or the host returned by the function
736 @command{(system-name)}.  The user name must be specified, but it
737 denotes a group name.  See @ref{Multi-hops} for an exception to this
738 behavior.
740 @item @option{sshx}
741 @cindex method sshx
742 @cindex sshx method
744 Works like @option{ssh} but without the extra authentication prompts.
745 @option{sshx} uses @samp{ssh -t -t @var{host} -l @var{user} /bin/sh}
746 to open a connection with a ``standard'' login shell.
748 @strong{Note} that @option{sshx} does not bypass authentication
749 questions.  For example, if the host key of the remote host is not
750 known, @option{sshx} will still ask ``Are you sure you want to
751 continue connecting?''.  @value{tramp} cannot handle such questions.
752 Connections will have to be setup where logins can proceed without
753 such questions.
755 @option{sshx} is useful for MS Windows users when @command{ssh}
756 triggers an error about allocating a pseudo tty.  This happens due to
757 missing shell prompts that confuses @value{tramp}.
759 @option{sshx} supports the @samp{-p} argument.
761 @item @option{krlogin}
762 @cindex method krlogin
763 @cindex krlogin method
764 @cindex kerberos (with krlogin method)
766 This method is also similar to @option{ssh}.  It uses the
767 @command{krlogin -x} command only for remote host login.
769 @item @option{ksu}
770 @cindex method ksu
771 @cindex ksu method
772 @cindex kerberos (with ksu method)
774 This is another method from the Kerberos suite.  It behaves like @option{su}.
776 @item @option{plink}
777 @cindex method plink
778 @cindex plink method
780 @option{plink} method is for MS Windows users with the PuTTY
781 implementation of SSH@.  It uses @samp{plink -ssh} to log in to the
782 remote host.
784 Check the @samp{Share SSH connections if possible} control for that
785 session.
787 @option{plink} method supports the @samp{-P} argument.
789 @item @option{plinkx}
790 @cindex method plinkx
791 @cindex plinkx method
793 Another method using PuTTY on MS Windows with session names instead of
794 host names.  @option{plinkx} calls @samp{plink -load @var{session}
795 -t}.  User names and port numbers must be defined in the session.
797 Check the @samp{Share SSH connections if possible} control for that
798 session.
800 @end table
803 @node External methods
804 @section External methods
805 @cindex methods, external
806 @cindex external methods
808 External methods operate over multiple channels, using the remote
809 shell connection for some actions while delegating file transfers to
810 an external transfer program.
812 External methods save on the overhead of encoding and decoding of
813 inline methods.
815 Since external methods have the overhead of opening a new channel,
816 files smaller than @var{tramp-copy-size-limit} still use inline
817 methods.
819 @table @asis
820 @item @option{rcp}
821 @cindex method rcp
822 @cindex rcp method
823 @cindex rcp (with rcp method)
824 @cindex rsh (with rcp method)
826 This method uses the @command{rsh} and @command{rcp} commands to
827 connect to the remote host and transfer files.  This is the fastest
828 access method available.
830 The alternative method @option{remcp} uses the @command{remsh} and
831 @command{rcp} commands.
833 @item @option{scp}
834 @cindex method scp
835 @cindex scp method
836 @cindex scp (with scp method)
837 @cindex ssh (with scp method)
839 Using a combination of @command{ssh} to connect and @command{scp} to
840 transfer is the most secure.  While the performance is good, it is
841 slower than the inline methods for smaller files.  Though there is no
842 overhead of encoding and decoding of the inline methods,
843 @command{scp}'s cryptographic handshake negates those speed gains.
845 @option{ssh}-based methods support @samp{-p} feature for specifying
846 port numbers.  For example, @file{host#42} passes @samp{-p 42} in the
847 argument list to @command{ssh}, and @samp{-P 42} in the argument list
848 to @command{scp}.
850 @item @option{rsync}
851 @cindex method rsync
852 @cindex rsync method
853 @cindex rsync (with rsync method)
854 @cindex ssh (with rsync method)
856 @command{ssh} command to connect in combination with @command{rsync}
857 command to transfer is similar to the @option{scp} method.
859 @command{rsync} performs much better than @command{scp} when
860 transferring files that exist on both hosts.  However, this advantage
861 is lost if the file exists only on one side of the connection.
863 This method supports the @samp{-p} argument.
865 @item @option{scpx}
866 @cindex method scpx
867 @cindex scpx method
868 @cindex scp (with scpx method)
869 @cindex ssh (with scpx method)
871 @option{scpx} is useful to avoid login shell questions.  It is similar
872 in performance to @option{scp}.  @option{scpx} uses @samp{ssh -t -t
873 @var{host} -l @var{user} /bin/sh} to open a connection.
875 @option{scpx} is useful for MS Windows users when @command{ssh}
876 triggers an error about allocating a pseudo tty.  This happens due to
877 missing shell prompts that confuses @value{tramp}.
879 This method supports the @samp{-p} argument.
881 @item @option{pscp}
882 @item @option{psftp}
883 @cindex method pscp
884 @cindex pscp method
885 @cindex pscp (with pscp method)
886 @cindex plink (with pscp method)
887 @cindex putty (with pscp method)
888 @cindex method psftp
889 @cindex psftp method
890 @cindex pscp (with psftp method)
891 @cindex plink (with psftp method)
892 @cindex putty (with psftp method)
894 These methods are similar to @option{scp} or @option{sftp}, but they
895 use the @command{plink} command to connect to the remote host, and
896 they use @command{pscp} or @command{psftp} for transferring the files.
897 These programs are part of PuTTY, an SSH implementation for MS Windows.
899 Check the @samp{Share SSH connections if possible} control for that
900 session.
902 These methods support the @samp{-P} argument.
904 @item @option{fcp}
905 @cindex method fcp
906 @cindex fcp method
907 @cindex fsh (with fcp method)
908 @cindex fcp (with fcp method)
910 This method is similar to @option{scp}, but uses @command{fsh} to
911 connect and @command{fcp} to transfer files.  @command{fsh/fcp}, a
912 front-end for @command{ssh}, reuse @command{ssh} session by
913 submitting several commands.  This avoids the startup overhead due to
914 @command{scp}'s secure connection.  Inline methods have similar
915 benefits.
917 The command used for this connection is: @samp{fsh @var{host} -l
918 @var{user} /bin/sh -i}
920 @cindex method fsh
921 @cindex fsh method
923 @option{fsh} has no inline method since the multiplexing it offers is
924 not useful for @value{tramp}.  @command{fsh} connects to remote host
925 and @value{tramp} keeps that one connection open.
927 @item @option{nc}
928 @cindex method nc
929 @cindex nc method
930 @cindex nc (with nc method)
931 @cindex telnet (with 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 ftp
941 @cindex 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 smb
949 @cindex smb method
950 @cindex ms windows (with smb method)
951 @cindex 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 adb
1023 @cindex adb method
1024 @cindex android (with 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 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 afp
1077 @cindex 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 dav
1087 @cindex method davs
1088 @cindex dav method
1089 @cindex 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 gdrive
1097 @cindex 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 obex
1113 @cindex 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{sftp}
1119 @cindex method sftp
1120 @cindex sftp method
1122 This method uses @command{sftp} in order to securely access remote
1123 hosts.  @command{sftp} is a more secure option for connecting to hosts
1124 that for security reasons refuse @command{ssh} connections.
1126 @item @option{synce}
1127 @cindex method synce
1128 @cindex synce method
1130 @option{synce} method allows connecting to MS Windows Mobile devices.
1131 It uses GVFS for mounting remote files and directories via FUSE and
1132 requires the SYNCE-GVFS plugin.
1134 @end table
1136 @defopt tramp-gvfs-methods
1137 This user option is a list of external methods for GVFS@.  By default,
1138 this list includes @option{afp}, @option{dav}, @option{davs},
1139 @option{gdrive}, @option{obex}, @option{sftp} and @option{synce}.
1140 Other methods to include are: @option{ftp} and @option{smb}.
1141 @end defopt
1144 @node Default Method
1145 @section Selecting a default method
1146 @cindex default method
1148 In a remote file name, the use of a default method is indicated by the
1149 pseudo method @option{-}, @ref{File name syntax}.
1151 @defopt tramp-default-method
1152 Default method is for transferring files.  The user option
1153 @option{tramp-default-method} sets it.  @value{tramp} uses this user
1154 option to determine the default method for remote file names that do
1155 not have one specified.
1157 @lisp
1158 (custom-set-variables '(tramp-default-method "ssh" nil (tramp)))
1159 @end lisp
1160 @end defopt
1162 @defopt tramp-default-method-alist
1163 Default methods for transferring files can be customized for specific
1164 user and host combinations through the user option
1165 @option{tramp-default-method-alist}.
1167 For example, the following two lines specify to use the @option{ssh}
1168 method for all user names matching @samp{john} and the @option{rsync}
1169 method for all host names matching @samp{lily}.  The third line
1170 specifies to use the @option{su} method for the user @samp{root} on
1171 the host @samp{localhost}.
1173 @lisp
1174 @group
1175 (add-to-list 'tramp-default-method-alist '("" "john" "ssh"))
1176 (add-to-list 'tramp-default-method-alist '("lily" "" "rsync"))
1177 (add-to-list 'tramp-default-method-alist
1178              '("\\`localhost\\'" "\\`root\\'" "su"))
1179 @end group
1180 @end lisp
1181 @end defopt
1183 @noindent
1184 External methods performance faster for large files.  @pxref{Inline
1185 methods}.  @pxref{External methods}.
1187 Choosing the access method also depends on the security environment.
1188 For example, @option{rsh} and @option{telnet} methods that use clear
1189 text password transfers are inappropriate for over the Internet
1190 connections.  Secure remote connections should use @option{ssh} that
1191 provide encryption.
1194 @subsection Which method to use?
1195 @cindex choosing the right method
1197 @value{tramp} provides maximum number of choices for maximum
1198 flexibility.  Choosing which method depends on the hosts, clients,
1199 network speeds, and the security context.
1201 Start by using an inline method.
1203 External methods might be more efficient for large files, but most
1204 @value{tramp} users edit small files more often than large files.
1206 Enable compression, @var{tramp-inline-compress-start-size}, for a
1207 performance boost for large files.
1209 Since @command{ssh} has become the most common method of remote host
1210 access and it has the most reasonable security protocols, use
1211 @option{ssh} method.  Typical @option{ssh} usage to edit the
1212 @file{/etc/motd} file on the otherhost:
1214 @example
1215 @kbd{C-x C-f @trampfn{ssh,root@@otherhost,/etc/motd} @key{RET}}
1216 @end example
1218 If @option{ssh} is unavailable for whatever reason, look for other
1219 obvious options.  For MS Windows, try the @option{plink} method.  For
1220 Kerberos, try @option{krlogin}.
1222 For editing local files as @option{su} or @option{sudo} methods, try
1223 the shortened syntax of @samp{root}:
1225 @example
1226 @kbd{C-x C-f @trampfn{su,,/etc/motd} @key{RET}}
1227 @end example
1229 For editing large files, @option{scp} is faster than @option{ssh}.
1230 @option{pscp} is faster than @option{plink}.  But this speed
1231 improvement is not always true.
1234 @node Default User
1235 @section Selecting a default user
1236 @cindex default user
1238 @defopt tramp-default-user
1239 @value{tramp} file name can omit the user name part since
1240 @value{tramp} substitutes the currently logged-in user name.  However
1241 this substitution can be overridden with @option{tramp-default-user}.
1242 For example:
1244 @lisp
1245 (custom-set-variables'(tramp-default-user "root" nil (tramp)))
1246 @end lisp
1247 @end defopt
1249 @defopt tramp-default-user-alist
1250 Instead of a single default user, @option{tramp-default-user-alist}
1251 allows multiple default user values based on access method or host
1252 name combinations.  The alist can hold multiple values.  For example, to
1253 use the @samp{john} as the default user for the domain
1254 @samp{somewhere.else} only:
1256 @lisp
1257 @group
1258 (add-to-list 'tramp-default-user-alist
1259              '("ssh" ".*\\.somewhere\\.else\\'" "john"))
1260 @end group
1261 @end lisp
1263 A Caution: @value{tramp} will override any default user specified in
1264 the configuration files outside Emacs, such as @file{~/.ssh/config}.
1265 To stop @value{tramp} from applying the default value, set the
1266 corresponding alist entry to nil:
1268 @lisp
1269 @group
1270 (add-to-list 'tramp-default-user-alist
1271              '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
1272 @end group
1273 @end lisp
1275 The last entry in @option{tramp-default-user-alist} should be reserved
1276 for catch-all or most often used login.
1278 @lisp
1279 @group
1280 (add-to-list 'tramp-default-user-alist
1281              '(nil nil "jonas") t)
1282 @end group
1283 @end lisp
1284 @end defopt
1287 @node Default Host
1288 @section Selecting a default host
1289 @cindex default host
1291 @defopt tramp-default-host
1292 When host name is omitted, @value{tramp} substitutes the value from
1293 the @option{tramp-default-host} user option.  It is initially
1294 populated with the local host name where Emacs is running.  The
1295 default method, default user and default host can be overridden as
1296 follows:
1298 @lisp
1299 @group
1300 (custom-set-variables
1301  '(tramp-default-method "ssh" nil (tramp))
1302  '(tramp-default-user "john" nil (tramp))
1303  '(tramp-default-host "target" nil (tramp)))
1304 @end group
1305 @end lisp
1307 With all defaults set, @samp{@trampfn{-,,}} will connect @value{tramp}
1308 to John's home directory on @code{target} via @code{ssh}.
1309 @end defopt
1311 @defopt tramp-default-host-alist
1312 Instead of a single default host, @option{tramp-default-host-alist}
1313 allows multiple default host values based on access method or user
1314 name combinations.  The alist can hold multiple values.  While
1315 @option{tramp-default-host} is sufficient in most cases, some methods,
1316 like @option{adb}, require defaults overwritten.
1317 @end defopt
1320 @node Multi-hops
1321 @section Connecting to a remote host using multiple hops
1322 @cindex multi-hop
1323 @cindex proxy hosts
1325 Multi-hops are methods to reach hosts behind firewalls or to reach the
1326 outside world from inside a bastion host.  With multi-hops,
1327 @value{tramp} can negotiate these hops with the appropriate user/host
1328 authentication at each hop.  All methods until now have been the single
1329 hop kind, where the start and end points of the connection did not
1330 have intermediate check points.
1332 @defopt tramp-default-proxies-alist
1333 @option{tramp-default-proxies-alist} specifies proxy hosts to pass
1334 through.  This user option is list of triples consisting of
1335 @code{(@var{host} @var{user} @var{proxy})}.
1337 The first match is the proxy host through which passes the file name
1338 and the target host matching @var{user}@@@var{host}.  @var{host} and
1339 @var{user} are regular expressions or @code{nil}, interpreted as a
1340 regular expression which always matches.
1342 @var{proxy} is a literal @value{tramp} file name whose local name part
1343 is ignored, and the method and user name parts are optional.
1345 The method must be an inline method (@pxref{Inline methods}).  If
1346 @var{proxy} is @code{nil}, no additional hop is required reaching
1347 @var{user}@@@var{host}.
1349 For example, to pass through the host @samp{bastion.your.domain} as
1350 user @samp{bird} to reach remote hosts outside the local domain:
1352 @lisp
1353 @group
1354 (add-to-list 'tramp-default-proxies-alist
1355              '("\\." nil "@trampfn{ssh,bird@@bastion.your.domain,}"))
1356 (add-to-list 'tramp-default-proxies-alist
1357              '("\\.your\\.domain\\'" nil nil))
1358 @end group
1359 @end lisp
1361 @strong{Note}: @code{add-to-list} adds elements at the beginning of a
1362 list.  Therefore, most relevant rules must come last in the list.
1364 Proxy hosts can be cascaded in the alist.  If there is another host
1365 called @samp{jump.your.domain}, which is the only host allowed to
1366 connect to @samp{bastion.your.domain}, then:
1368 @lisp
1369 @group
1370 (add-to-list 'tramp-default-proxies-alist
1371              '("\\`bastion\\.your\\.domain\\'"
1372                "\\`bird\\'"
1373                "@trampfn{ssh,jump.your.domain,}"))
1374 @end group
1375 @end lisp
1377 @var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
1378 @var{user} respectively.
1380 To login as @samp{root} on remote hosts in the domain
1381 @samp{your.domain}, but login as @samp{root} is disabled for non-local
1382 access, then use this alist entry:
1384 @lisp
1385 @group
1386 (add-to-list 'tramp-default-proxies-alist
1387              '("\\.your\\.domain\\'" "\\`root\\'" "@trampfn{ssh,%h,}"))
1388 @end group
1389 @end lisp
1391 Opening @file{@trampfn{sudo,randomhost.your.domain,}} first connects
1392 to @samp{randomhost.your.domain} via @code{ssh} under your account
1393 name, and then performs @code{sudo -u root} on that host.
1395 It is key for the sudo method in the above example to be applied on
1396 the host after reaching it and not on the local host.
1398 @var{host}, @var{user} and @var{proxy} can also take Lisp forms.  These
1399 forms when evaluated must return either a string or @code{nil}.
1401 To generalize (from the previous example): For all hosts, except my
1402 local one, first connect via @command{ssh}, and then apply
1403 @command{sudo -u root}:
1405 @lisp
1406 @group
1407 (add-to-list 'tramp-default-proxies-alist
1408              '(nil "\\`root\\'" "@trampfn{ssh,%h,}"))
1409 (add-to-list 'tramp-default-proxies-alist
1410              '((regexp-quote (system-name)) nil nil))
1411 @end group
1412 @end lisp
1413 @end defopt
1415 Passing through hops involves dealing with restricted shells, such as
1416 @command{rbash}.  If @value{tramp} is made aware, then it would use
1417 them for proxies only.
1419 @defopt tramp-restricted-shell-hosts-alist
1420 An alist of regular expressions of hosts running restricted shells,
1421 such as @command{rbash}.  @value{tramp} will then use them only as
1422 proxies.
1424 To specify the bastion host from the example above as running a
1425 restricted shell:
1427 @lisp
1428 @group
1429 (add-to-list 'tramp-restricted-shell-hosts-alist
1430              "\\`bastion\\.your\\.domain\\'")
1431 @end group
1432 @end lisp
1433 @end defopt
1436 @node Firewalls
1437 @section Passing firewalls
1438 @cindex http tunnel
1439 @cindex proxy hosts, http tunnel
1441 Sometimes, it is not possible to reach a remote host directly.  A
1442 firewall might be in the way, which could be passed via a proxy
1443 server.
1445 Both ssh and PuTTY support such proxy settings, using an HTTP tunnel
1446 via the @command{CONNECT} command (conforming to RFC 2616, 2817
1447 specifications).  Proxy servers using HTTP version 1.1 or later
1448 protocol support this command.
1450 @subsection Tunneling with ssh
1452 With ssh, you could use the @code{ProxyCommand} entry in the
1453 @file{~/.ssh/config}:
1455 @example
1456 @group
1457 Host host.other.domain
1458      ProxyCommand nc -X connect -x proxy.your.domain:3128 %h %p
1459 @end group
1460 @end example
1462 @code{nc} is BSD's netcat program, which establishes HTTP tunnels. Any
1463 other program with such a feature could be used as well.
1465 In the example, opening @file{@trampfn{ssh,host.your.domain,}} passes
1466 the HTTP proxy server @samp{proxy.your.domain} on port 3128.
1468 @subsection Tunneling with PuTTY
1470 PuTTY does not need an external program, HTTP tunnel support is
1471 built-in.  In the PuTTY config program, create a session for
1472 @samp{host.your.domain}.  In the @option{Connection/Data} entry,
1473 select the @option{HTTP} option, and add @samp{proxy.your.domain} as
1474 @option{Proxy hostname}, and 3128 as @option{Port}.
1476 Opening @file{@trampfn{plinkx,host.your.domain,}} passes the HTTP
1477 proxy server @samp{proxy.your.domain} on port 3128.
1480 @node Customizing Methods
1481 @section Using Non-Standard Methods
1482 @cindex customizing methods
1483 @cindex using non-standard methods
1484 @cindex create your own methods
1486 The @code{tramp-methods} variable currently has an exhaustive list of
1487 predefined methods.  Any part of this list can be modified with more
1488 suitable settings.  Refer to the Lisp documentation of that variable,
1489 accessible with @kbd{C-h v tramp-methods @key{RET}}.
1492 @node Customizing Completion
1493 @section Selecting config files for user/host name completion
1494 @cindex customizing completion
1495 @cindex selecting config files
1496 @vindex tramp-completion-function-alist
1498 @code{tramp-completion-function-alist} uses predefined files for user
1499 and host name completion (@pxref{File name completion}).  For each
1500 method, it keeps a set of configuration files and a function that can
1501 parse that file.  Each entry in @code{tramp-completion-function-alist}
1502 is of the form (@var{method} @var{pair1} @var{pair2} @dots{}).
1504 Each @var{pair} is composed of (@var{function} @var{file}).
1505 @var{function} is responsible for extracting user names and host names
1506 from @var{file} for completion.  There are two functions which access
1507 this variable:
1509 @defun tramp-get-completion-function method
1510 This function returns the list of completion functions for @var{method}.
1512 Example:
1513 @example
1514 @group
1515 (tramp-get-completion-function "rsh")
1517      @result{} ((tramp-parse-rhosts "/etc/hosts.equiv")
1518          (tramp-parse-rhosts "~/.rhosts"))
1519 @end group
1520 @end example
1521 @end defun
1523 @defun tramp-set-completion-function method function-list
1524 This function sets @var{function-list} as list of completion functions
1525 for @var{method}.
1527 Example:
1528 @example
1529 @group
1530 (tramp-set-completion-function "ssh"
1531  '((tramp-parse-sconfig "/etc/ssh_config")
1532    (tramp-parse-sconfig "~/.ssh/config")))
1534      @result{} ((tramp-parse-sconfig "/etc/ssh_config")
1535          (tramp-parse-sconfig "~/.ssh/config"))
1536 @end group
1537 @end example
1538 @end defun
1540 The following predefined functions parsing configuration files exist:
1542 @table @asis
1543 @item @code{tramp-parse-rhosts}
1544 @findex tramp-parse-rhosts
1546 This function parses files which are syntactical equivalent to
1547 @file{~/.rhosts}.  It returns both host names and user names, if
1548 specified.
1550 @item @code{tramp-parse-shosts}
1551 @findex tramp-parse-shosts
1553 This function parses files which are syntactical equivalent to
1554 @file{~/.ssh/known_hosts}.  Since there are no user names specified
1555 in such files, it can return host names only.
1557 @item @code{tramp-parse-sconfig}
1558 @findex tramp-parse-sconfig
1560 This function returns the host nicknames defined by @code{Host} entries
1561 in @file{~/.ssh/config} style files.
1563 @item @code{tramp-parse-shostkeys}
1564 @findex tramp-parse-shostkeys
1566 SSH2 parsing of directories @file{/etc/ssh2/hostkeys/*} and
1567 @file{~/ssh2/hostkeys/*}.  Hosts are coded in file names
1568 @file{hostkey_@var{portnumber}_@var{host-name}.pub}.  User names
1569 are always @code{nil}.
1571 @item @code{tramp-parse-sknownhosts}
1572 @findex tramp-parse-sknownhosts
1574 Another SSH2 style parsing of directories like
1575 @file{/etc/ssh2/knownhosts/*} and @file{~/ssh2/knownhosts/*}.  This
1576 case, hosts names are coded in file names
1577 @file{@var{host-name}.@var{algorithm}.pub}.  User names are always @code{nil}.
1579 @item @code{tramp-parse-hosts}
1580 @findex tramp-parse-hosts
1582 A function dedicated to @file{/etc/hosts} for host names.
1584 @item @code{tramp-parse-passwd}
1585 @findex tramp-parse-passwd
1587 A function which parses @file{/etc/passwd} files for user names.
1589 @item @code{tramp-parse-etc-group}
1590 @findex tramp-parse-etc-group
1592 A function which parses @file{/etc/group} files for group names.
1594 @item @code{tramp-parse-netrc}
1595 @findex tramp-parse-netrc
1597 A function which parses @file{~/.netrc} and @file{~/.authinfo}-style files.
1599 @end table
1601 To keep a custom file with custom data in a custom structure, a custom
1602 function has to be provided.  This function must meet the following
1603 conventions:
1605 @defun my-tramp-parse file
1606 @var{file} must be either a file on the host, or @code{nil}.  The
1607 function must return a list of (@var{user} @var{host}), which are
1608 taken as candidates for completion for user and host names.
1610 Example:
1611 @example
1612 @group
1613 (my-tramp-parse "~/.my-tramp-hosts")
1615      @result{} ((nil "toto") ("daniel" "melancholia"))
1616 @end group
1617 @end example
1618 @end defun
1621 @node Password handling
1622 @section Reusing passwords for several connections
1623 @cindex passwords
1625 To avoid repeated prompts for passwords, consider native caching
1626 mechanisms, such as @command{ssh-agent} for @option{ssh}-like
1627 methods, or @command{pageant} for @option{plink}-like methods.
1629 @value{tramp} offers alternatives when native solutions cannot meet
1630 the need.
1633 @anchor{Using an authentication file}
1634 @subsection Using an authentication file
1635 @vindex auth-sources
1637 The package @file{auth-source.el}, originally developed for No Gnus,
1638 reads passwords from different sources, @xref{Help for users, ,
1639 auth-source, auth}.  The default authentication file is
1640 @file{~/.authinfo.gpg}, but this can be changed via the variable
1641 @code{auth-sources}.
1643 @noindent
1644 A typical entry in the authentication file:
1646 @example
1647 machine melancholia port scp login daniel password geheim
1648 @end example
1650 The port can take any @value{tramp} method (@pxref{Inline methods},
1651 @pxref{External methods}).  Omitting port values matches all
1652 @value{tramp} methods.  Domain and ports, as used in @value{tramp}
1653 file name syntax, must be appended to the machine and login items:
1655 @example
1656 machine melancholia#4711 port davs login daniel%BIZARRE password geheim
1657 @end example
1659 @vindex auth-source-debug
1660 Set @code{auth-source-debug} to @code{t} to debug messages.
1663 @anchor{Caching passwords}
1664 @subsection Caching passwords
1666 @value{tramp} can cache passwords as entered and reuse when needed for
1667 the same user or host name independent of the access method.
1669 @vindex password-cache-expiry
1670 @code{password-cache-expiry} sets the duration (in seconds) the
1671 passwords are remembered.  Passwords are never saved permanently nor
1672 can they extend beyond the lifetime of the current Emacs session.  Set
1673 @code{password-cache-expiry} to @code{nil} to disable expiration.
1675 @vindex password-cache
1676 Set @code{password-cache} to @code{nil} to disable password caching.
1679 @node Connection caching
1680 @section Reusing connection related information
1681 @cindex caching
1682 @vindex tramp-persistency-file-name
1684 For faster initial connection times, @value{tramp} stores previous
1685 connection properties in a file specified by the user option
1686 @option{tramp-persistency-file-name}.
1688 The default file name for @option{tramp-persistency-file-name} is
1689 @file{~/.emacs.d/tramp}.
1691 @value{tramp} reads this file during Emacs startup, and writes to it
1692 when exiting Emacs.  Delete this file for @value{tramp} to recreate a
1693 new one on next Emacs startup.
1695 Set @option{tramp-persistency-file-name} to @code{nil} to disable
1696 storing connections persistently.
1698 When @value{tramp} detects a change in the operating system version in
1699 a remote host (via the command @command{uname -sr}), it flushes all
1700 connection related information for that host and creates a new entry.
1703 @node Predefined connection information
1704 @section Setting own connection related information
1705 @vindex tramp-connection-properties
1707 For more precise customization, parameters specified by
1708 @code{tramp-methods} can be overwritten manually.
1710 Set @option{tramp-connection-properties} to manually override
1711 @code{tramp-methods}.  Properties in this list are in the form
1712 @code{(@var{regexp} @var{property} @var{value})}.  @var{regexp}
1713 matches remote file names.  Use @code{nil} to match all.
1714 @var{property} is the property's name, and @var{value} is the
1715 property's value.
1717 @var{property} is any method specific parameter contained in
1718 @code{tramp-methods}.  The parameter key in @code{tramp-methods} is a
1719 symbol name @code{tramp-<foo>}.  To overwrite that property, use the
1720 string @samp{<foo>} for @var{property}.  For example, this changes the
1721 remote shell:
1723 @lisp
1724 @group
1725 (add-to-list 'tramp-connection-properties
1726              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1727                    "remote-shell" "/bin/ksh"))
1728 @end group
1730 @group
1731 (add-to-list 'tramp-connection-properties
1732              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1733                    "remote-shell-login" '("-")))
1734 @end group
1735 @end lisp
1737 The parameters @code{tramp-remote-shell} and
1738 @code{tramp-remote-shell-login} in @code{tramp-methods} now have new
1739 values for the remote host.
1741 @var{property} could also be any property found in
1742 @option{tramp-persistency-file-name}.
1744 To get around how restricted shells randomly drop connections, set the
1745 special property @samp{busybox}.  For example:
1747 @lisp
1748 @group
1749 (add-to-list 'tramp-connection-properties
1750              (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1751                    "busybox" t))
1752 @end group
1753 @end lisp
1756 @node Remote programs
1757 @section How @value{tramp} finds and uses programs on the remote host
1759 @value{tramp} requires access to and rights to several commands on
1760 remote hosts: @command{ls}, @command{test}, @command{find} and
1761 @command{cat}.
1763 Besides there are other required programs for @ref{Inline methods} and
1764 @ref{External methods} of connection.
1766 To improve performance and accuracy of remote file access,
1767 @value{tramp} uses @command{perl} (or @command{perl5}) and
1768 @command{grep} when available.
1770 @defopt tramp-remote-path
1771 @option{tramp-remote-path} specifies which remote directory paths
1772 @value{tramp} can search for @ref{Remote programs}.
1774 @vindex tramp-default-remote-path
1775 @value{tramp} uses standard defaults, such as @file{/bin} and
1776 @file{/usr/bin}, which are reasonable for most hosts.  To accommodate
1777 differences in hosts and paths, for example, @file{/bin:/usr/bin} on
1778 Debian GNU/Linux or
1779 @file{/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin} on
1780 Solaris, @value{tramp} queries the remote host with @command{getconf
1781 PATH} and updates the symbol @code{tramp-default-remote-path}.
1783 For instances where hosts keep obscure locations for paths for
1784 security reasons, manually add such paths to local @file{.emacs} as
1785 shown below for @value{tramp} to use when connecting.
1787 @lisp
1788 (add-to-list 'tramp-remote-path "/usr/local/perl/bin")
1789 @end lisp
1791 @vindex tramp-own-remote-path
1792 Another way to find the remote path is to use the path assigned to the
1793 remote user by the remote host.  @value{tramp} does not normally retain
1794 this remote path after login.  However, @code{tramp-own-remote-path}
1795 preserves the path value, which can be used to update
1796 @option{tramp-remote-path}.
1798 @lisp
1799 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
1800 @end lisp
1802 @strong{Note} that this works only if your remote @command{/bin/sh}
1803 shell supports the login argument @samp{-l}.
1804 @end defopt
1806 When remote search paths are changed, local @value{tramp} caches must
1807 be recomputed.  To force @value{tramp} to recompute afresh, exit
1808 Emacs, remove the persistent file (@pxref{Connection caching}), and
1809 restart Emacs.
1812 @node Remote shell setup
1813 @section Remote shell setup hints
1814 @cindex remote shell setup
1815 @cindex @file{.profile} file
1816 @cindex @file{.login} file
1817 @cindex shell init files
1819 @value{tramp} checks for the availability of standard programs in the
1820 usual locations.  Common tactics include successively trying
1821 @command{test -e}, @command{/usr/bin/test -e}, and @command{/bin/test
1822 -e}.  @command{ls -d} is another approach.  But these approaches do not
1823 help with these new login patterns.
1825 When @value{tramp} encounters two-factor logins or additional challenge
1826 questions, such as entering birth date or security code or passphrase,
1827 @value{tramp} needs a few more configuration steps to accommodate
1828 them.
1830 The difference between a password prompt and a passphrase prompt is
1831 that the password for completing the login while the passphrase is
1832 for authorizing access to local authentication information, such as
1833 the ssh key.
1835 There is no one configuration to accommodate all the variations in
1836 login security, especially not the exotic ones.  However, @value{tramp}
1837 provides a few tweaks to address the most common ones.
1839 @table @asis
1840 @item @option{tramp-shell-prompt-pattern}
1841 @vindex tramp-shell-prompt-pattern
1843 @option{tramp-shell-prompt-pattern} is for remote login shell prompt,
1844 which may not be the same as the local login shell prompt,
1845 @code{shell-prompt-pattern}.  Since most hosts use identical prompts,
1846 @value{tramp} sets a similar default value for both prompts.
1848 @item @option{tramp-password-prompt-regexp}
1849 @item @option{tramp-wrong-passwd-regexp}
1850 @vindex tramp-password-prompt-regexp
1851 @vindex tramp-wrong-passwd-regexp
1853 @value{tramp} uses @option{tramp-password-prompt-regexp} to
1854 distinguish between prompts for passwords and prompts for passphrases.
1855 By default, @option{tramp-password-prompt-regexp} handles the
1856 detection in English language environments.  See a localization
1857 example below:
1859 @lisp
1860 @group
1861 (custom-set-variables
1862  '(tramp-password-prompt-regexp
1863    (concat
1864     "^.*"
1865     (regexp-opt
1866      '("passphrase" "Passphrase"
1867        ;; English
1868        "password" "Password"
1869        ;; Deutsch
1870        "passwort" "Passwort"
1871        ;; Français
1872        "mot de passe" "Mot de passe")
1873      t)
1874     ".*:\0? *")
1875    nil (tramp)))
1876 @end group
1877 @end lisp
1879 Similar localization may be necessary for handling wrong password
1880 prompts, for which @value{tramp} uses @option{tramp-wrong-passwd-regexp}.
1882 @item @command{tset} and other questions
1883 @cindex unix command tset
1884 @cindex tset unix command
1885 @vindex tramp-terminal-type
1887 To suppress inappropriate prompts for terminal type, @value{tramp}
1888 sets the @env{TERM} to @code{dumb} before the remote login process
1889 begins via the user option @option{tramp-terminal-type}.  This will
1890 silence common @command{tset} related prompts.
1892 @value{tramp}'s strategy for handling such prompts (commonly triggered
1893 from login scripts on remote hosts) is to set the environment
1894 variables so that no prompts interrupt the shell initialization
1895 process.
1897 @vindex tramp-actions-before-shell
1898 An alternative approach is to configure @value{tramp} with strings
1899 that can identify such questions using
1900 @code{tramp-actions-before-shell}.  Example:
1902 @lisp
1903 @group
1904 (defconst my-tramp-prompt-regexp
1905   (concat (regexp-opt '("Enter the birth date of your mother:") t)
1906           "\\s-*")
1907   "Regular expression matching my login prompt question.")
1908 @end group
1910 @group
1911 (defun my-tramp-action (proc vec)
1912   "Enter \"19000101\" in order to give a correct answer."
1913   (save-window-excursion
1914     (with-current-buffer (tramp-get-connection-buffer vec)
1915       (tramp-message vec 6 "\n%s" (buffer-string))
1916       (tramp-send-string vec "19000101"))))
1917 @end group
1919 @group
1920 (add-to-list 'tramp-actions-before-shell
1921              '(my-tramp-prompt-regexp my-tramp-action))
1922 @end group
1923 @end lisp
1926 @item Conflicting names for users and variables in @file{.profile}
1928 When a user name is the same as a variable name in a local file, such
1929 as @file{.profile}, then @value{tramp} may send incorrect values for
1930 environment variables.  To avoid incorrect values, change the local
1931 variable name to something different from the user name.  For example,
1932 if the user name is @env{FRUMPLE}, then change the variable name to
1933 @env{FRUMPLE_DIR}.
1936 @item Non-Bourne commands in @file{.profile}
1938 When the remote host's @file{.profile} is also used for shells other
1939 than Bourne shell, then some incompatible syntaxes for commands in
1940 @file{.profile} may trigger errors in Bourne shell on the host and may
1941 not complete client's @value{tramp} connections.
1943 One example of a Bourne shell incompatible syntax in @file{.profile}:
1944 using @command{export FOO=bar} instead of @command{FOO=bar; export
1945 FOO}.  After remote login, @value{tramp} will trigger an error during
1946 its execution of @command{/bin/sh} on the remote host because Bourne
1947 shell does not recognize the export command as entered in
1948 @file{.profile}.
1950 Likewise, (@code{~}) character in paths will cause errors because
1951 Bourne shell does not do (@code{~}) character expansions.
1953 One approach to avoiding these incompatibilities is to make all
1954 commands in @file{~/.shrc} and @file{~/.profile} Bourne shell
1955 compatible so @value{tramp} can complete connections to that remote.
1956 To accommodate using non-Bourne shells on that remote, use other
1957 shell-specific config files.  For example, bash can use
1958 @file{~/.bash_profile} and ignore @file{.profile}.
1961 @item Interactive shell prompt
1963 @value{tramp} redefines the remote shell prompt internally for robust
1964 parsing.  This redefinition affects the looks of a prompt in an
1965 interactive remote shell through commands, such as @kbd{M-x
1966 shell}.  Such prompts, however, can be reset to something more readable
1967 and recognizable using these @value{tramp} variables.
1969 @value{tramp} sets the @env{INSIDE_EMACS} variable in the startup
1970 script file @file{~/.emacs_SHELLNAME}.
1972 @env{SHELLNAME} is @code{bash} or equivalent shell names.  Change it by
1973 setting the environment variable @env{ESHELL} in the @file{.emacs} as
1974 follows:
1976 @lisp
1977 (setenv "ESHELL" "bash")
1978 @end lisp
1980 Then re-set the prompt string in @file{~/.emacs_SHELLNAME} as follows:
1982 @example
1983 @group
1984 # Reset the prompt for remote @value{tramp} shells.
1985 if [ "$@{INSIDE_EMACS/*tramp*/tramp@}" == "tramp" ] ; then
1986    PS1="[\u@@\h \w]$ "
1988 @end group
1989 @end example
1991 @ifinfo
1992 @xref{Interactive Shell, , , emacs}.
1993 @end ifinfo
1995 @item @command{busybox} / @command{nc}
1996 @cindex unix command nc
1997 @cindex nc unix command
1999 @value{tramp}'s @option{nc} method uses the @command{nc} command to
2000 install and execute a listener as follows (see @code{tramp-methods}):
2002 @example
2003 $ nc -l -p 42
2004 @end example
2006 The above command-line syntax has changed with @command{busybox}
2007 versions.  If @command{nc} refuses the @samp{-p} parameter, then
2008 overwrite as follows:
2010 @lisp
2011 @group
2012 (add-to-list
2013  'tramp-connection-properties
2014  `(,(regexp-quote "192.168.0.1")
2015    "remote-copy-args" (("-l") ("%r"))))
2016 @end group
2017 @end lisp
2019 @noindent
2020 where @samp{192.168.0.1} is the remote host IP address
2021 (@pxref{Predefined connection information}).
2023 @end table
2026 @node Android shell setup
2027 @section Android shell setup hints
2028 @cindex android shell setup for ssh
2030 @value{tramp} uses the @option{adb} method to access Android devices.
2031 Android devices provide a restricted shell access through an USB
2032 connection.  The local host must have the @command{adb} program
2033 installed.  Usually, it is sufficient to open the file
2034 @file{@trampfn{adb,,/}}.  Then you can navigate in the filesystem via
2035 @code{dired}.
2037 Alternatively, applications such as @code{SSHDroid} that run
2038 @command{sshd} process on the Android device can accept any
2039 @option{ssh}-based methods provided these settings are adjusted:
2041 @itemize
2042 @item
2043 @command{sh} must be specified for remote shell since Android devices
2044 do not provide @command{/bin/sh}.  @command{sh} will then invoke
2045 whatever shell is installed on the device with this setting:
2047 @lisp
2048 @group
2049 (add-to-list 'tramp-connection-properties
2050              (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))
2051 @end group
2052 @end lisp
2054 @noindent
2055 where @samp{192.168.0.26} is the Android device's IP address.
2056 (@pxref{Predefined connection information}).
2058 @item
2059 @value{tramp} requires preserving @env{PATH} environment variable from
2060 user settings.  Android devices prefer @file{/system/xbin} path over
2061 @file{/system/bin}.  Both of these are set as follows:
2063 @lisp
2064 @group
2065 (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
2066 (add-to-list 'tramp-remote-path "/system/xbin")
2067 @end group
2068 @end lisp
2070 @item
2071 When the Android device is not @samp{rooted}, specify a writable
2072 directory for temporary files:
2074 @lisp
2075 (add-to-list 'tramp-remote-process-environment "TMPDIR=$HOME")
2076 @end lisp
2078 @item
2079 Open a remote connection with the command @kbd{C-x C-f
2080 @trampfn{ssh,192.168.0.26#2222,}}, where @command{sshd} is listening
2081 on port @samp{2222}.
2083 To add a corresponding entry to the @file{~/.ssh/config} file
2084 (recommended), use this:
2086 @example
2087 @group
2088 Host android
2089      HostName 192.168.0.26
2090      User root
2091      Port 2222
2092 @end group
2093 @end example
2095 @noindent
2096 To use the host name @samp{android} instead of the IP address shown in
2097 the previous example, fix the connection properties as follows:
2099 @lisp
2100 @group
2101 (add-to-list 'tramp-connection-properties
2102              (list (regexp-quote "android") "remote-shell" "sh"))
2103 @end group
2104 @end lisp
2106 @noindent
2107 Open a remote connection with a more concise command @kbd{C-x C-f
2108 @trampfn{ssh,android,}}.
2109 @end itemize
2112 @node Auto-save and Backup
2113 @section Auto-save and Backup configuration
2114 @cindex auto-save
2115 @cindex backup
2116 @vindex backup-directory-alist
2118 To avoid @value{tramp} from saving backup files owned by @samp{root}
2119 to locations accessible to others, default backup settings in
2120 @option{backup-directory-alist} have to be altered.
2122 Here's a scenario where files could be inadvertently exposed.  Emacs
2123 by default writes backup files to the same directory as the original
2124 files unless changed to another location, such as
2125 @file{~/.emacs.d/backups/}.  Such a directory will also be used by
2126 default by @value{tramp} when using, say, a restricted file
2127 @file{@trampfn{su,root@@localhost,/etc/secretfile}}.  The backup file
2128 of the secretfile is now owned by the user logged in from
2129 @value{tramp} and not @samp{root}.
2131 When @option{backup-directory-alist} is @code{nil} (the default), such
2132 problems do not occur.
2134 To ``turn off'' the backup feature for @value{tramp} files and stop
2135 @value{tramp} from saving to the backup directory, use this:
2137 @lisp
2138 @group
2139 (add-to-list 'backup-directory-alist
2140              (cons tramp-file-name-regexp nil))
2141 @end group
2142 @end lisp
2144 @noindent
2145 Disabling backups can be targeted to just the @option{su} and
2146 @option{sudo} methods:
2148 @lisp
2149 @group
2150 (setq backup-enable-predicate
2151       (lambda (name)
2152         (and (normal-backup-enable-predicate name)
2153              (not
2154               (let ((method (file-remote-p name 'method)))
2155                 (when (stringp method)
2156                   (member method '("su" "sudo"))))))))
2157 @end group
2158 @end lisp
2160 Another option is to create better backup file naming with user and
2161 host names prefixed to the file name.  For example, transforming
2162 @file{/etc/secretfile} to
2163 @file{~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile}, set the
2164 @value{tramp} user option @option{tramp-backup-directory-alist} from
2165 the existing user option @option{backup-directory-alist}.
2167 Then @value{tramp} backs up to a file name that is transformed with a
2168 prefix consisting of the DIRECTORY name.  This file name prefixing
2169 happens only when the DIRECTORY is an absolute local file name.
2171 @noindent
2172 Example:
2174 @lisp
2175 @group
2176 (add-to-list 'backup-directory-alist
2177              (cons "." "~/.emacs.d/backups/"))
2178 (custom-set-variables
2179  '(tramp-backup-directory-alist backup-directory-alist 6 nil (tramp)))
2180 @end group
2181 @end lisp
2183 @noindent
2184 The backup file name of
2185 @file{@trampfn{su,root@@localhost,/etc/secretfile}} would be
2186 @ifset unified
2187 @file{@trampfn{su,root@@localhost,~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile~}}
2188 @end ifset
2189 @ifset separate
2190 @file{@trampfn{su,root@@localhost,~/.emacs.d/backups/![su!root@@localhost]!etc!secretfile~}}
2191 @end ifset
2193 Just as for backup files, similar issues of file naming affect
2194 auto-saving @value{tramp} files.  Auto-saved files are saved in the
2195 directory specified by the user option
2196 @option{auto-save-file-name-transforms}.  By default this is set to
2197 the local temporary directory.  But in some versions of Debian
2198 GNU/Linux, this points to the source directory where the Emacs was
2199 compiled.  Reset such values to a valid directory.
2201 Set @option{auto-save-file-name-transforms} to @code{nil} to save
2202 auto-saved files to the same directory as the original file.
2204 Alternatively, set the user option @option{tramp-auto-save-directory}
2205 to direct all auto saves to that location.
2207 @node Windows setup hints
2208 @section Issues with Cygwin ssh
2209 @cindex cygwin, issues
2211 This section is incomplete.  Please share your solutions.
2213 @cindex method sshx with cygwin
2214 @cindex sshx method with cygwin
2216 Cygwin's @command{ssh} works only with a Cygwin version of Emacs.  To
2217 check for compatibility: type @kbd{M-x eshell}, and start @kbd{ssh
2218 test.host}.  Incompatibilities trigger this message:
2220 @example
2221 Pseudo-terminal will not be allocated because stdin is not a terminal.
2222 @end example
2224 Some older versions of Cygwin's @command{ssh} work with the
2225 @option{sshx} access method.  Consult Cygwin's FAQ at
2226 @uref{https://cygwin.com/faq/} for details.
2228 @cindex cygwin and fakecygpty
2229 @cindex fakecygpty and cygwin
2231 On @uref{https://www.emacswiki.org/emacs/SshWithNTEmacs, the Emacs
2232 Wiki} it is explained how to use the helper program @code{fakecygpty}
2233 to fix this problem.
2235 @cindex method scpx with cygwin
2236 @cindex scpx method with cygwin
2238 When using the @option{scpx} access method, Emacs may call
2239 @command{scp} with MS Windows file naming, such as @code{c:/foo}.  But
2240 the version of @command{scp} that is installed with Cygwin does not
2241 know about MS Windows file naming, which causes it to incorrectly look
2242 for a host named @code{c}.
2244 A workaround: write a wrapper script for @option{scp} to convert
2245 Windows file names to Cygwin file names.
2247 @cindex cygwin and ssh-agent
2248 @cindex SSH_AUTH_SOCK and emacs on ms windows
2250 When using the @command{ssh-agent} on MS Windows for password-less
2251 interaction, @option{ssh} methods depend on the environment variable
2252 @env{SSH_AUTH_SOCK}.  But this variable is not set when Emacs is
2253 started from a Desktop shortcut and authentication fails.
2255 One workaround is to use an MS Windows based SSH Agent, such as
2256 Pageant.  It is part of the Putty Suite of tools.
2258 The fallback is to start Emacs from a shell.
2261 @node Usage
2262 @chapter Using @value{tramp}
2263 @cindex using @value{tramp}
2265 @value{tramp} operates transparently, accessing remote files as if
2266 they are local.  However, @value{tramp} employs a formalized remote
2267 file naming syntax to perform its functions transparently.  This
2268 syntax consists of many parts specifying access methods,
2269 authentication, host names, and file names.  Ange FTP uses a similar
2270 syntax.
2272 @cindex type-ahead
2274 Unlike opening local files in Emacs, which are instantaneous, opening
2275 remote files in @value{tramp} is slower at first.  Sometimes there is
2276 a noticeable delay before the prompts for passwords or authentication
2277 appear in the minibuffer.  Hitting @kbd{@key{RET}} or other keys
2278 during this gap will be processed by Emacs.  This type-ahead facility
2279 is a feature of Emacs that may cause missed prompts when using
2280 @value{tramp}.
2282 @menu
2283 * File name syntax::            @value{tramp} file name conventions.
2284 @ifset unified
2285 * Change file name syntax::     Alternative file name syntax.
2286 @end ifset
2287 * File name completion::        File name completion.
2288 * Ad-hoc multi-hops::           Declaring multiple hops in the file name.
2289 * Remote processes::            Integration with other Emacs packages.
2290 * Cleanup remote connections::  Cleanup remote connections.
2291 @end menu
2294 @node File name syntax
2295 @section @value{tramp} file name conventions
2296 @cindex file name syntax
2297 @cindex file name examples
2299 @file{@trampfn{method,host,/path/to/file}} opens file @var{/path/to/file}
2300 on the remote host @var{host}, using the method @var{method}.
2302 @table @file
2303 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}.emacs
2304 For the file @file{.emacs} located in the home directory, on the host
2305 @code{melancholia}, using method @code{ssh}.
2307 @item @value{prefix}ssh@value{postfixhop}melancholia.danann.net@value{postfix}.emacs
2308 For the file @file{.emacs} specified using the fully qualified domain name of
2309 the host.
2311 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~/.emacs
2312 For the file @file{.emacs} specified using the @file{~}, which is expanded.
2314 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~daniel/.emacs
2315 For the file @file{.emacs} located in @code{daniel}'s home directory
2316 on the host, @code{melancholia}.  The @file{~<user>} construct is
2317 expanded to the home directory of that user on the remote host.
2319 @item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}/etc/squid.conf
2320 For the file @file{/etc/squid.conf} on the host @code{melancholia}.
2322 @end table
2324 @var{host} can take IPv4 or IPv6 address, as in
2325 @file{@trampfn{ssh,127.0.0.1,.emacs}} or
2326 @file{@trampfn{ssh,@value{ipv6prefix}::1@value{ipv6postfix},.emacs}}.
2327 @ifset unified
2328 For syntactical reasons, IPv6 addresses must be embedded in square
2329 brackets @file{@value{ipv6prefix}} and @file{@value{ipv6postfix}}.
2330 @end ifset
2332 By default, @value{tramp} will use the current local user name as the
2333 remote user name for log in to the remote host.  Specifying a different
2334 name using the proper syntax will override this default behavior:
2336 @example
2337 @trampfn{method,user@@host,path/to/file}
2338 @end example
2340 @file{@trampfn{ssh,daniel@@melancholia,.emacs}} is for file
2341 @file{.emacs} in @code{daniel}'s home directory on the host,
2342 @code{melancholia}, accessing via method @code{ssh}.
2344 For specifying port numbers, affix @file{#<port>} to the host
2345 name.  For example: @file{@trampfn{ssh,daniel@@melancholia#42,.emacs}}.
2347 All method, user name, host name, port number and local name parts are
2348 optional, @xref{Default Method}, @xref{Default User}, @xref{Default Host}.
2349 @ifset unified
2350 For syntactical reasons, the default method must be indicated by the
2351 pseudo method @file{-}.
2352 @end ifset
2355 @ifset unified
2356 @node Change file name syntax
2357 @section Alternative file name syntax
2358 @cindex change file name syntax
2359 @cindex alternative file name syntax
2361 The syntax described in @ref{File name syntax} is the @code{default}
2362 syntax, which is active after Emacs startup.  However, this can be
2363 changed.
2365 @deffn Command tramp-change-syntax syntax
2366 This command changes the syntax @value{tramp} uses for remote file
2367 names.  Beside the @code{default} value, @var{syntax} can be
2369 @itemize
2370 @item @code{simplified}
2371 @cindex simplified syntax
2373 The remote file name syntax is similar to the syntax used by Ange FTP.
2374 A remote file name has the form
2375 @code{@value{prefix}user@@host@value{postfix}path/to/file}.  The
2376 @code{user@@} part is optional, and the method is determined by
2377 @ref{Default Method}.
2379 @item @code{separate}
2380 @cindex separate syntax
2382 @clear unified
2383 @set separate
2384 @include trampver.texi
2385 The remote file name syntax is similar to the syntax used by XEmacs.
2386 A remote file name has the form
2387 @code{@trampfn{method,user@@host,path/to/file}}.  The @code{method}
2388 and @code{user@@} parts are optional.
2389 @clear separate
2390 @set unified
2391 @include trampver.texi
2392 @end itemize
2393 @end deffn
2395 @defvar tramp-file-name-regexp
2396 This variable keeps a regexp which matches the selected remote file
2397 name syntax.  However, it is not recommended to use this variable in
2398 external packages, a call of @code{file-remote-p} is much more
2399 appropriate.
2400 @ifinfo
2401 @pxref{Magic File Names, , , elisp}
2402 @end ifinfo
2403 @end defvar
2404 @end ifset
2407 @node File name completion
2408 @section File name completion
2409 @cindex file name completion
2411 @value{tramp} can complete the following @value{tramp} file name
2412 components: method names, user names, host names, and file names
2413 located on remote hosts.  Enable this by activating partial completion
2414 in @file{.emacs}.
2415 @ifinfo
2416 @xref{Completion Options, , , emacs}.
2417 @end ifinfo
2419 For example, type @kbd{C-x C-f @value{prefixwithspace} s @key{TAB}},
2420 @value{tramp} completion choices show up as
2422 @example
2423 @group
2424 @multitable @columnfractions .2 .2 .2 .2 .2
2425 @item @c
2426   sbin/ @tab @c
2427   @value{prefixhop}scp@value{postfix} @tab @c
2428   @value{prefixhop}scpx@value{postfix} @tab @c
2429   @value{prefixhop}sftp@value{postfix} @tab @c
2430   @value{prefixhop}sg@value{postfix}
2431 @item @c
2432   @value{prefixhop}smb@value{postfix} @tab @c
2433   srv/ @tab @c
2434   @value{prefixhop}ssh@value{postfix} @tab @c
2435   @value{prefixhop}sshx@value{postfix} @tab @c
2436   @value{prefixhop}su@value{postfix}
2437 @item @c
2438   @value{prefixhop}sudo@value{postfix} @tab @c
2439   sys/
2440 @end multitable
2441 @end group
2442 @end example
2444 @samp{@value{prefixhop}ssh@value{postfixhop}} is a possible
2445 completion for the respective method, and @samp{sbin/} stands for the
2446 directory @file{/sbin} on your local host.
2448 Type @kbd{s h @value{postfixhop}} for the minibuffer completion to
2449 @samp{@value{prefix}ssh@value{postfixhop}}.  Typing @kbd{@key{TAB}}
2450 shows host names @value{tramp} extracts from @file{~/.ssh/config}
2451 file, for example.
2453 @example
2454 @group
2455 @multitable @columnfractions .5 .5
2456 @item @c
2457   @value{prefixhop}ssh@value{postfixhop}127.0.0.1@value{postfix} @tab @c
2458   @value{prefixhop}ssh@value{postfixhop}192.168.0.1@value{postfix}
2459 @item @c
2460   @value{prefixhop}ssh@value{postfixhop}@value{ipv6prefix}::1@value{ipv6postfix}@value{postfix} @tab @c
2461   @value{prefixhop}ssh@value{postfixhop}localhost@value{postfix}
2462 @item @c
2463   @value{prefixhop}ssh@value{postfixhop}melancholia.danann.net@value{postfix} @tab @c
2464   @value{prefixhop}ssh@value{postfixhop}melancholia@value{postfix}
2465 @end multitable
2466 @end group
2467 @end example
2469 Choose a host from the above list and then continue to complete file
2470 names on that host.
2472 When the configuration (@pxref{Customizing Completion}) includes user
2473 names, then the completion lists will account for the user names as well.
2475 Remote hosts previously visited or hosts whose connections are kept
2476 persistently (@pxref{Connection caching}) will be included in the
2477 completion lists.
2479 After remote host name completion comes completion of file names on
2480 the remote host.  It works the same as with local host file completion
2481 except that killing with double-slash @file{//} kills only the file
2482 name part of the @value{tramp} file name syntax.  A triple-slash
2483 stands for the default behavior.
2484 @ifinfo
2485 @xref{Minibuffer File, , , emacs}.
2486 @end ifinfo
2488 @noindent
2489 Example:
2491 @example
2492 @group
2493 @kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin//etc} @key{TAB}}
2494      @print{} @trampfn{ssh,melancholia,/etc}
2496 @kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}}
2497      @print{} /etc
2499 @kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}}
2500      @print{} /etc
2501 @end group
2502 @end example
2504 During file name completion, remote directory contents are re-read
2505 regularly to account for any changes in the filesystem that may affect
2506 the completion candidates.  Such re-reads can account for changes to
2507 the file system by applications outside Emacs (@pxref{Connection
2508 caching}).
2510 @defopt tramp-completion-reread-directory-timeout
2511 The timeout is number of seconds since last remote command for
2512 rereading remote directory contents.  A value of 0 re-reads
2513 immediately during file name completion, @code{nil} uses cached
2514 directory contents.
2515 @end defopt
2518 @node Ad-hoc multi-hops
2519 @section Declaring multiple hops in the file name
2520 @cindex multi-hop, ad-hoc
2521 @cindex proxy hosts, ad-hoc
2523 @value{tramp} file name syntax can accommodate ad hoc specification of
2524 multiple proxies without using @option{tramp-default-proxies-alist}
2525 configuration setup(@pxref{Multi-hops}).
2527 Each proxy is specified using the same syntax as the remote host
2528 specification minus the file name part.  Each hop is separated by a
2529 @samp{|}.  Chain the proxies from the starting host to the destination
2530 remote host name and file name.  For example, hopping over a single
2531 proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}:
2533 @example
2534 @c @kbd{C-x C-f @trampfn{ssh@value{postfixhop}bird@@bastion|ssh,you,remotehost,/path}}
2535 @kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path}
2536 @end example
2538 Proxies can take patterns @code{%h} or @code{%u}.
2540 @value{tramp} adds the ad-hoc definitions on the fly to
2541 @option{tramp-default-proxies-alist} and is available for re-use
2542 during that Emacs session.  Subsequent @value{tramp} connections to
2543 the same remote host can then use the shortcut form:
2544 @samp{@trampfn{ssh,you@@remotehost,/path}}.
2546 @defopt tramp-save-ad-hoc-proxies
2547 For ad-hoc definitions to be saved automatically in
2548 @option{tramp-default-proxies-alist} for future Emacs sessions, set
2549 @option{tramp-save-ad-hoc-proxies} to non-@code{nil}.
2551 @lisp
2552 (custom-set-variables '(tramp-save-ad-hoc-proxies t nil (tramp)))
2553 @end lisp
2554 @end defopt
2557 @node Remote processes
2558 @section Integration with other Emacs packages
2559 @cindex compile
2560 @cindex recompile
2562 @value{tramp} supports starting new running processes on the remote
2563 host for discovering remote file names.  Emacs packages on the remote
2564 host need no specific modifications for @value{tramp}'s use.
2566 This type of integration does not work with the @option{ftp} method,
2567 and does not support the pty association as specified in
2568 @code{start-file-process}.
2570 @code{process-file} and @code{start-file-process} work on the remote
2571 host when the variable @code{default-directory} is remote:
2573 @lisp
2574 @group
2575 (let ((default-directory "/ssh:remote.host:"))
2576   (start-file-process "grep" (get-buffer-create "*grep*")
2577                       "/bin/sh" "-c" "grep -e tramp *"))
2578 @end group
2579 @end lisp
2581 Remote processes do not apply to GVFS (see @ref{GVFS based methods})
2582 because the remote file system is mounted on the local host and
2583 @value{tramp} just accesses by changing the @code{default-directory}.
2585 @value{tramp} starts a remote process when a command is executed in a
2586 remote file or directory buffer.  As of now, these packages have been
2587 integrated to work with @value{tramp}: @file{compile.el} (commands
2588 like @code{compile} and @code{grep}) and @file{gud.el} (@code{gdb} or
2589 @code{perldb}).
2591 For @value{tramp} to find the command on the remote, it must be
2592 accessible through the default search path as setup by @value{tramp}
2593 upon first connection.  Alternatively, use an absolute path or extend
2594 @option{tramp-remote-path} (see @ref{Remote programs}):
2596 @lisp
2597 @group
2598 (add-to-list 'tramp-remote-path "~/bin")
2599 (add-to-list 'tramp-remote-path "/appli/pub/bin")
2600 @end group
2601 @end lisp
2603 Customize user option @option{tramp-remote-process-environment} to
2604 suit the remote program's environment for the remote host.
2605 @option{tramp-remote-process-environment} is a list of strings
2606 structured similar to @code{process-environment}, where each element
2607 is a string of the form @samp{ENVVARNAME=VALUE}.
2609 To avoid any conflicts with local host environment variables set
2610 through local configuration files, such as @file{~/.profile}, use
2611 @samp{ENVVARNAME=} to unset them for the remote environment.
2613 @noindent
2614 Use @code{add-to-list} to add entries:
2616 @lisp
2617 (add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java")
2618 @end lisp
2620 Modifying or deleting already existing values in the
2621 @option{tramp-remote-process-environment} list may not be feasible on
2622 restricted remote hosts.  For example, some system administrators
2623 disallow changing @env{HISTORY} environment variable.  To accommodate
2624 such restrictions when using @value{tramp}, fix the
2625 @option{tramp-remote-process-environment} by the following code in the
2626 local @file{.emacs} file:
2628 @lisp
2629 @group
2630 (let ((process-environment tramp-remote-process-environment))
2631   (setenv "HISTORY" nil)
2632   (setq tramp-remote-process-environment process-environment))
2633 @end group
2634 @end lisp
2636 Setting the @env{ENV} environment variable instructs some shells to
2637 read an initialization file.  Per default, @value{tramp} has disabled
2638 this.  You could overwrite this behavior by evaluating
2640 @lisp
2641 @group
2642 (let ((process-environment tramp-remote-process-environment))
2643   (setenv "ENV" "$HOME/.profile")
2644   (setq tramp-remote-process-environment process-environment))
2645 @end group
2646 @end lisp
2648 @value{tramp} does not use the defaults specified in
2649 @code{process-environment} for running @code{process-file} or
2650 @code{start-file-process} on remote hosts.  When values from
2651 @code{process-environment} are needed for remote processes, then set
2652 them as follows:
2654 @lisp
2655 @group
2656 (let ((process-environment (cons "HGPLAIN=1" process-environment)))
2657   (process-file @dots{}))
2658 @end group
2659 @end lisp
2661 This works only for environment variables not already set in the
2662 @code{process-environment}.
2664 For integrating other Emacs packages so @value{tramp} can execute
2665 remotely, please file a bug report.  @xref{Bug Reports}.
2668 @subsection Running remote programs that create local X11 windows
2670 To allow a remote program to create an X11 window on the local host,
2671 set the @env{DISPLAY} environment variable for the remote host as
2672 follows in the local @file{.emacs} file:
2674 @lisp
2675 @group
2676 (add-to-list 'tramp-remote-process-environment
2677              (format "DISPLAY=%s" (getenv "DISPLAY")))
2678 @end group
2679 @end lisp
2681 @noindent
2682 @code{(getenv "DISPLAY")} should return a recognizable name for the
2683 local host that the remote host can redirect X11 window
2684 interactions.  If querying for a recognizable name is not possible for
2685 whatever reason, then replace @code{(getenv "DISPLAY")} with a
2686 hard-coded, fixed name.  Note that using @code{:0} for X11 display name
2687 here will not work as expected.
2689 An alternate approach is specify @code{ForwardX11 yes} or
2690 @code{ForwardX11Trusted yes} in the file @file{~/.ssh/config} on the
2691 local host.
2694 @subsection Running @code{shell} on a remote host
2695 @cindex shell
2697 Set @option{explicit-shell-file-name} to the appropriate shell name
2698 when using @value{tramp} between two hosts with different operating
2699 systems, such as @samp{windows-nt} and @samp{gnu/linux}.  This option
2700 ensures the correct name of the remote shell program.
2702 When @option{explicit-shell-file-name} is equal to @code{nil}, calling
2703 @code{shell} interactively will prompt for a shell name.
2705 Starting with Emacs 26, you could use connection-local variables for
2706 setting different values of @option{explicit-shell-file-name} for
2707 different remote hosts.
2708 @ifinfo
2709 @pxref{Connection Local Variables, , , elisp}
2710 @end ifinfo
2712 @lisp
2713 @group
2714 (connection-local-set-profile-variables
2715   'remote-bash
2716   '((explicit-shell-file-name . "/bin/bash")
2717     (explicit-bash-args . ("-i"))))
2718 @end group
2720 @group
2721 (connection-local-set-profile-variables
2722   'remote-ksh
2723   '((explicit-shell-file-name . "/bin/ksh")
2724     (explicit-ksh-args . ("-i"))))
2725 @end group
2727 @group
2728 (connection-local-set-profiles
2729   '(:application tramp :protocol "ssh" :machine "localhost")
2730   'remote-bash)
2731 @end group
2733 @group
2734 (connection-local-set-profiles
2735   `(:application tramp :protocol "sudo"
2736     :user "root" :machine ,(system-name))
2737   'remote-ksh)
2738 @end group
2739 @end lisp
2742 @subsection Running @code{shell-command} on a remote host
2743 @cindex shell-command
2745 @code{shell-command} executes commands synchronously or asynchronously
2746 on remote hosts and displays output in buffers on the local
2747 host.  Example:
2749 @example
2750 @group
2751 @kbd{C-x C-f @trampfn{sudo,,} @key{RET}}
2752 @kbd{M-! tail -f /var/log/syslog.log & @key{RET}}
2753 @end group
2754 @end example
2756 @command{tail} command outputs continuously to the local buffer,
2757 @file{*Async Shell Command*}
2759 @kbd{M-x auto-revert-tail-mode} runs similarly showing continuous output.
2762 @subsection Running @code{eshell} on a remote host
2763 @cindex eshell
2765 @value{tramp} is integrated into @file{eshell.el}, which enables
2766 interactive eshell sessions on remote hosts at the command prompt.
2767 You must add the module @code{em-tramp} to @code{eshell-modules-list}.
2768 Here's a sample interaction after opening @kbd{M-x eshell} on a remote
2769 host:
2771 @example
2772 @group
2773 @b{~ $} cd @trampfn{sudo,,/etc} @key{RET}
2774 @b{@trampfn{sudo,root@@host,/etc} $} hostname @key{RET}
2775 host
2776 @b{@trampfn{sudo,root@@host,/etc} $} id @key{RET}
2777 uid=0(root) gid=0(root) groups=0(root)
2778 @b{@trampfn{sudo,root@@host,/etc} $} find-file shadow @key{RET}
2779 #<buffer shadow>
2780 @b{@trampfn{sudo,root@@host,/etc} $}
2781 @end group
2782 @end example
2784 @code{eshell} added custom @code{su} and @code{sudo} commands that set
2785 the default directory correctly for the @file{*eshell*} buffer.
2786 @value{tramp} silently updates @option{tramp-default-proxies-alist}
2787 with an entry for this directory (@pxref{Multi-hops}):
2789 @example
2790 @group
2791 @b{~ $} cd @trampfn{ssh,user@@remotehost,/etc} @key{RET}
2792 @b{@trampfn{ssh,user@@remotehost,/etc} $} find-file shadow @key{RET}
2793 File is not readable: @trampfn{ssh,user@@remotehost,/etc/shadow}
2794 @b{@trampfn{ssh,user@@remotehost,/etc} $} sudo find-file shadow @key{RET}
2795 #<buffer shadow>
2796 @end group
2798 @group
2799 @b{@trampfn{ssh,user@@remotehost,/etc} $} su - @key{RET}
2800 @b{@trampfn{su,root@@remotehost,/root} $} id @key{RET}
2801 uid=0(root) gid=0(root) groups=0(root)
2802 @b{@trampfn{su,root@@remotehost,/root} $}
2803 @end group
2804 @end example
2807 @anchor{Running a debugger on a remote host}
2808 @subsection Running a debugger on a remote host
2809 @cindex gud
2810 @cindex gdb
2811 @cindex perldb
2813 @file{gud.el} provides a unified interface to symbolic debuggers
2814 @ifinfo
2815 (@ref{Debuggers, , , emacs}).
2816 @end ifinfo
2817 @value{tramp} can run debug on remote hosts by calling @code{gdb}
2818 with a remote file name:
2820 @example
2821 @group
2822 @kbd{M-x gdb @key{RET}}
2823 @b{Run gdb (like this):} gdb -i=mi @trampfn{ssh,host,~/myprog} @key{RET}
2824 @end group
2825 @end example
2827 Since the remote @code{gdb} and @code{gdb-inferior} processes do not
2828 belong to the same process group on the remote host, there will be a
2829 warning, which can be ignored:
2831 @example
2832 &"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
2833 @end example
2835 Relative file names are based on the remote default directory.  When
2836 @file{myprog.pl} exists in @file{@trampfn{ssh,host,/home/user}}, valid
2837 calls include:
2839 @example
2840 @group
2841 @kbd{M-x perldb @key{RET}}
2842 @b{Run perldb (like this):} perl -d myprog.pl @key{RET}
2843 @end group
2844 @end example
2846 Just the local part of a remote file name, such as @kbd{perl -d
2847 /home/user/myprog.pl}, is not possible.
2849 Arguments of the program to be debugged must be literal, can take
2850 relative or absolute paths, but not remote paths.
2853 @subsection Running remote processes on MS Windows hosts
2854 @cindex winexe
2855 @cindex powershell
2857 @command{winexe} runs processes on a remote MS Windows host, and
2858 @value{tramp} can use it for @code{process-file} and
2859 @code{start-file-process}.
2861 @code{tramp-smb-winexe-program} specifies the local @command{winexe}
2862 command.  Powershell V2.0 on the remote host is required to run
2863 processes triggered from @value{tramp}.
2865 @option{explicit-shell-file-name} and @option{explicit-*-args} have to
2866 be set properly so @kbd{M-x shell} can open a proper remote shell on a
2867 MS Windows host.  To open @command{cmd}, set it as follows:
2869 @lisp
2870 @group
2871 (setq explicit-shell-file-name "cmd"
2872       explicit-cmd-args '("/q"))
2873 @end group
2874 @end lisp
2876 @noindent
2877 To open @command{powershell} as a remote shell, use this:
2879 @lisp
2880 @group
2881 (setq explicit-shell-file-name "powershell"
2882       explicit-powershell-args '("-file" "-"))
2883 @end group
2884 @end lisp
2887 @node Cleanup remote connections
2888 @section Cleanup remote connections
2889 @cindex cleanup
2891 @value{tramp} provides several ways to flush remote connections.
2893 @deffn Command tramp-cleanup-connection vec
2894 This command flushes all connection related objects.  @option{vec} is
2895 the internal representation of a remote connection.  When called
2896 interactively, this command lists active remote connections in the
2897 minibuffer.  Each connection is of the format
2898 @file{@trampfn{method,user@@host,}}.  Flushing remote connections also
2899 cleans the password cache (@pxref{Password handling}), file cache,
2900 connection cache (@pxref{Connection caching}), and connection buffers.
2901 @end deffn
2903 @deffn Command tramp-cleanup-this-connection
2904 Flushes only the current buffer's remote connection objects, the same
2905 as in @code{tramp-cleanup-connection}.
2906 @end deffn
2908 @deffn Command tramp-cleanup-all-connections
2909 Flushes all active remote connection objects, the same as in
2910 @code{tramp-cleanup-connection}.
2911 @end deffn
2913 @deffn Command tramp-cleanup-all-buffers
2914 Just as for @code{tramp-cleanup-all-connections}, all remote
2915 connections are cleaned up in addition to killing buffers related to
2916 that remote connection.
2917 @end deffn
2920 @node Bug Reports
2921 @chapter Reporting Bugs and Problems
2922 @cindex bug reports
2924 @value{tramp}'s development team is actively engaged in solving bugs
2925 and problems and looks to feature requests and suggestions.
2927 @value{tramp}'s mailing list is the place for more advice and
2928 information on working with @value{tramp}, solving problems,
2929 discussing, and general discussions about @value{tramp}.
2931 @value{tramp}'s mailing list is moderated but even non-subscribers can
2932 post for moderator approval.  Sometimes this approval step may take as
2933 long as 48 hours due to public holidays.
2935 @email{tramp-devel@@gnu.org} is the mailing list.  Messages sent to
2936 this address go to all the subscribers.  This is @emph{not} the
2937 address to send subscription requests to.
2939 To subscribe to the mailing list, visit:
2940 @uref{https://lists.gnu.org/mailman/listinfo/tramp-devel/, the
2941 @value{tramp} Mail Subscription Page}.
2943 @ifset installchapter
2944 Before sending a bug report, run the test suite first @ref{Testing}.
2945 @end ifset
2947 @findex tramp-bug
2948 Check if the bug or problem is already addressed in @xref{Frequently
2949 Asked Questions}.
2951 Run @kbd{M-x tramp-bug} to generate a buffer with details of the
2952 system along with the details of the @value{tramp}
2953 installation.  Please include these details with the bug report.
2955 The bug report must describe in as excruciating detail as possible the
2956 steps required to reproduce the problem.  These details must include
2957 the setup of the remote host and any special or unique conditions that
2958 exist.
2960 Include a minimal test case that reproduces the problem.  This will
2961 help the development team find the best solution and avoid unrelated
2962 detours.
2964 To exclude cache-related problems, flush all caches before running the
2965 test, @ref{Cleanup remote connections}.
2967 When including @value{tramp}'s messages in the bug report, increase
2968 the verbosity level to 6 (@pxref{Traces and Profiles, Traces}) in the
2969 @file{~/.emacs} file before repeating steps to the bug.  Include the
2970 contents of the @file{*tramp/foo*} and @file{*debug tramp/foo*}
2971 buffers with the bug report.
2973 @strong{Note} that a verbosity level greater than 6 is not necessary
2974 at this stage.  Also note that a verbosity level of 6 or greater, the
2975 contents of files and directories will be included in the debug
2976 buffer.  Passwords typed in @value{tramp} will never be included
2977 there.
2980 @node Frequently Asked Questions
2981 @chapter Frequently Asked Questions
2982 @cindex frequently asked questions
2983 @cindex FAQ
2985 @itemize @bullet
2986 @item
2987 Where is the latest @value{tramp}?
2989 @value{tramp} is available at the GNU URL:
2991 @noindent
2992 @uref{https://ftp.gnu.org/gnu/tramp/}
2994 @noindent
2995 @value{tramp}'s GNU project page is located here:
2997 @noindent
2998 @uref{https://savannah.gnu.org/projects/tramp/}
3001 @item
3002 Which systems does it work on?
3004 The package works successfully on Emacs 24, Emacs 25, and Emacs 26.
3006 While Unix and Unix-like systems are the primary remote targets,
3007 @value{tramp} has equal success connecting to other platforms, such as
3008 MS Windows 7/8/10.
3011 @item
3012 How to speed up @value{tramp}?
3014 @value{tramp} does many things in the background, some of which
3015 depends on network speeds, response speeds of remote hosts, and
3016 authentication delays.  During these operations, @value{tramp}'s
3017 responsiveness slows down.  Some suggestions within the scope of
3018 @value{tramp}'s settings include:
3020 Use an external method, such as @option{scp}, which are faster than
3021 internal methods.
3023 Keep the file @option{tramp-persistency-file-name}, which is where
3024 @value{tramp} caches remote information about hosts and files.  Caching
3025 is enabled by default.  Don't disable it.
3027 Set @code{remote-file-name-inhibit-cache} to @code{nil} if remote
3028 files are not independently updated outside @value{tramp}'s control.
3029 That cache cleanup will be necessary if the remote directories or
3030 files are updated independent of @value{tramp}.
3032 Set @option{tramp-completion-reread-directory-timeout} to @code{nil} to
3033 speed up completions, @ref{File name completion}.
3035 Disable version control to avoid delays:
3037 @lisp
3038 @group
3039 (setq vc-ignore-dir-regexp
3040       (format "\\(%s\\)\\|\\(%s\\)"
3041               vc-ignore-dir-regexp
3042               tramp-file-name-regexp))
3043 @end group
3044 @end lisp
3046 If this is too radical, because you want to use version control
3047 remotely, trim @code{vc-handled-backends} to just those you care
3048 about, for example:
3050 @lisp
3051 (setq vc-handled-backends '(SVN Git))
3052 @end lisp
3054 Disable excessive traces.  Set @code{tramp-verbose} to 3 or lower,
3055 default being 3.  Increase trace levels temporarily when hunting for
3056 bugs.
3058 @item
3059 @value{tramp} does not connect to the remote host
3061 Three main reasons for why @value{tramp} does not connect to the remote host:
3063 @itemize @minus
3064 @item
3065 Unknown characters in the prompt
3067 @value{tramp} needs a clean recognizable prompt on the remote host for
3068 accurate parsing.  Shell prompts that contain escape sequences for
3069 coloring cause parsing problems.  @ref{Remote shell setup} for
3070 customizing prompt detection using regular expressions.
3072 To check if the remote host's prompt is being recognized, use this
3073 test: switch to @value{tramp} connection buffer @file{*tramp/foo*},
3074 put the cursor at the top of the buffer, and then apply the following
3075 expression:
3077 @example
3078 @kbd{M-: (re-search-forward (concat tramp-shell-prompt-pattern "$"))}
3079 @end example
3081 If the cursor has not moved to the prompt at the bottom of the buffer,
3082 then @value{tramp} has failed to recognize the prompt.
3084 When using zsh on remote hosts, disable zsh line editor because zsh
3085 uses left-hand side and right-hand side prompts in parallel.  Add the
3086 following line to @file{~/.zshrc}:
3088 @example
3089 [ $TERM = "dumb" ] && unsetopt zle && PS1='$ '
3090 @end example
3092 When using fish shell on remote hosts, disable fancy formatting by
3093 adding the following to @file{~/.config/fish/config.fish}:
3095 @example
3096 @group
3097 function fish_prompt
3098   if test $TERM = "dumb"
3099      echo "\$ "
3100   else
3101      @dots{}
3102   end
3104 @end group
3105 @end example
3107 When using WinSSHD on remote hosts, @value{tramp} does not recognize
3108 the strange prompt settings.
3110 A similar problem exist with the iTerm2 shell integration, which sends
3111 proprietary escape codes when starting a shell.  This can be
3112 suppressed by changing the respective integration snippet in your
3113 @file{~/.profile} like this:
3115 @example
3116 @group
3117 [ $TERM = "dumb" ] || \
3118 test -e "$@{HOME@}/.iterm2_shell_integration.bash" && \
3119 source "$@{HOME@}/.iterm2_shell_integration.bash"
3120 @end group
3121 @end example
3123 @item
3124 Echoed characters after login
3126 @value{tramp} suppresses echos from remote hosts with the
3127 @command{stty -echo} command.  But sometimes it is too late to suppress
3128 welcome messages from the remote host containing harmful control
3129 characters.  Using @option{sshx} or @option{scpx} methods can avoid
3130 this problem because they allocate a pseudo tty.  @xref{Inline
3131 methods}.
3133 @item
3134 @value{tramp} stops transferring strings longer than 500 characters
3136 Set @code{tramp-chunksize} to 500 to get around this problem, which is
3137 related to faulty implementation of @code{process-send-string} on
3138 HP-UX, FreeBSD and Tru64 Unix systems.  Consult the documentation for
3139 @code{tramp-chunksize} to see when this is necessary.
3141 Set @code{file-precious-flag} to @code{t} for files accessed by
3142 @value{tramp} so the file contents are checked using checksum by
3143 first saving to a temporary file.
3144 @ifinfo
3145 @pxref{Saving Buffers, , , elisp}
3146 @end ifinfo
3148 @lisp
3149 @group
3150 (add-hook
3151  'find-file-hook
3152  (lambda ()
3153    (when (file-remote-p default-directory)
3154      (set (make-local-variable 'file-precious-flag) t))))
3155 @end group
3156 @end lisp
3157 @end itemize
3160 @item
3161 @value{tramp} does not recognize if a @command{ssh} session hangs
3163 @command{ssh} sessions on the local host hang when the network is
3164 down.  @value{tramp} cannot safely detect such hangs.  The network
3165 configuration for @command{ssh} can be configured to kill such hangs
3166 with the following command in the @file{~/.ssh/config}:
3168 @example
3169 @group
3170 Host *
3171      ServerAliveInterval 5
3172 @end group
3173 @end example
3176 @item
3177 @value{tramp} does not use default @command{ssh} @code{ControlPath}
3179 @value{tramp} overwrites @code{ControlPath} settings when initiating
3180 @command{ssh} sessions.  @value{tramp} does this to fend off a stall
3181 if a master session opened outside the Emacs session is no longer
3182 open.  That is why @value{tramp} prompts for the password again even
3183 if there is an @command{ssh} already open.
3185 @vindex tramp-ssh-controlmaster-options
3186 Some @command{ssh} versions support a @code{ControlPersist} option,
3187 which allows you to set the @code{ControlPath} provided the variable
3188 @code{tramp-ssh-controlmaster-options} is customized as follows:
3190 @lisp
3191 @group
3192 (setq tramp-ssh-controlmaster-options
3193       (concat
3194         "-o ControlPath=/tmp/ssh-ControlPath-%%r@@%%h:%%p "
3195         "-o ControlMaster=auto -o ControlPersist=yes"))
3196 @end group
3197 @end lisp
3199 Note how "%r", "%h" and "%p" must be encoded as "%%r", "%%h" and
3200 "%%p".
3202 @vindex tramp-use-ssh-controlmaster-options
3203 If the @file{~/.ssh/config} is configured appropriately for the above
3204 behavior, then any changes to @command{ssh} can be suppressed with
3205 this @code{nil} setting:
3207 @lisp
3208 @group
3209 (custom-set-variables
3210  '(tramp-use-ssh-controlmaster-options nil nil (tramp)))
3211 @end group
3212 @end lisp
3215 @item
3216 File name completion does not work with @value{tramp}
3218 @acronym{ANSI} escape sequences from the remote shell may cause errors
3219 in @value{tramp}'s parsing of remote buffers.
3221 To test if this is the case, open a remote shell and check if the output
3222 of @command{ls} is in color.
3224 To disable @acronym{ANSI} escape sequences from the remote hosts,
3225 disable @samp{--color=yes} or @samp{--color=auto} in the remote host's
3226 @file{.bashrc} or @file{.profile}.  Turn this alias on and off to see
3227 if file name completion works.
3229 @item
3230 File name completion does not work in directories with large number of
3231 files
3233 This may be related to globbing, which is the use of shell's ability
3234 to expand wild card specifications, such as @samp{*.c}.  For
3235 directories with large number of files, globbing might exceed the
3236 shell's limit on length of command lines and hang.  @value{tramp} uses
3237 globbing.
3239 To test if globbing hangs, open a shell on the remote host and then
3240 run @command{ls -d * ..?* > /dev/null}.
3242 When testing, ensure the remote shell is the same shell
3243 (@command{/bin/sh}, @command{ksh} or @command{bash}), that
3244 @value{tramp} uses when connecting to that host.
3247 @item
3248 How to get notified after @value{tramp} completes file transfers?
3250 Make Emacs beep after reading from or writing to the remote host with
3251 the following code in @file{~/.emacs} file.
3253 @lisp
3254 @group
3255 (defadvice tramp-handle-write-region
3256   (after tramp-write-beep-advice activate)
3257   "Make tramp beep after writing a file."
3258   (interactive)
3259   (beep))
3260 @end group
3262 @group
3263 (defadvice tramp-handle-do-copy-or-rename-file
3264   (after tramp-copy-beep-advice activate)
3265   "Make tramp beep after copying a file."
3266   (interactive)
3267   (beep))
3268 @end group
3270 @group
3271 (defadvice tramp-handle-insert-file-contents
3272   (after tramp-insert-beep-advice activate)
3273   "Make tramp beep after inserting a file."
3274   (interactive)
3275   (beep))
3276 @end group
3277 @end lisp
3280 @item
3281 How to get a Visual Warning when working with @samp{root} privileges?
3282 Host indication in the mode line?
3284 Install @file{tramp-theme} from GNU ELPA via Emacs' Package Manager.
3285 Enable it via @kbd{M-x load-theme @key{RET} tramp}.  Further
3286 customization is explained in user option
3287 @option{tramp-theme-face-remapping-alist}.
3290 @item
3291 Remote host does not understand default options for directory listing
3293 Emacs computes the @command{dired} options based on the local host but
3294 if the remote host cannot understand the same @command{ls} command,
3295 then set them with a hook as follows:
3297 @lisp
3298 @group
3299 (add-hook
3300  'dired-before-readin-hook
3301  (lambda ()
3302    (when (file-remote-p default-directory)
3303      (setq dired-actual-switches "-al"))))
3304 @end group
3305 @end lisp
3308 @item
3309 Why is @file{~/.sh_history} file on the remote host growing?
3311 Due to the remote shell saving tilde expansions triggered by
3312 @value{tramp}, the history file is probably growing rapidly.
3313 @value{tramp} can suppress this behaviour with the user option
3314 @code{tramp-histfile-override}.  When set to @code{t}, environment
3315 variable @env{HISTFILE} is unset, and environment variables
3316 @env{HISTFILESIZE} @env{HISTSIZE} are set to 0.
3318 Alternatively, @code{tramp-histfile-override} could be a string.
3319 Environment variable @env{HISTFILE} is set to this file name then.  Be
3320 careful when setting to @file{/dev/null}; this might result in
3321 undesired results when using @command{bash} as remote shell.
3323 Another approach is to disable @value{tramp}'s handling of the
3324 @env{HISTFILE} at all by setting @code{tramp-histfile-override} to
3325 @code{nil}.  In this case, saving history could be turned off by
3326 putting this shell code in the @file{.bashrc} or @file{.kshrc} file:
3328 @example
3329 @group
3330 if [ -f $HOME/.sh_history ] ; then
3331    /bin/rm $HOME/.sh_history
3333 if [ "$@{HISTFILE-unset@}" != "unset" ] ; then
3334    unset HISTFILE
3336 if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then
3337    unset HISTSIZE
3339 @end group
3340 @end example
3342 For @option{ssh}-based method, add the following line to your
3343 @file{~/.ssh/environment} file:
3345 @example
3346 HISTFILE=/dev/null
3347 @end example
3350 @item
3351 How to shorten long file names when typing in @value{tramp}?
3353 Adapt several of these approaches to reduce typing.  If the full name
3354 is @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, then:
3356 @enumerate
3358 @item
3359 Use default values for method name and user name:
3361 You can define default methods and user names for hosts,
3362 (@pxref{Default Method}, @pxref{Default User}):
3364 @lisp
3365 @group
3366 (custom-set-variables
3367  '(tramp-default-method "ssh" nil (tramp))
3368  '(tramp-default-user "news" nil (tramp)))
3369 @end group
3370 @end lisp
3372 The reduced typing: @kbd{C-x C-f @trampfn{-,news.my.domain,/opt/news/etc}}.
3374 @strong{Note} that there are some useful shortcuts already.  Accessing
3375 your local host as @samp{root} user, is possible just by @kbd{C-x C-f
3376 @trampfn{su,,}}.
3378 @item
3379 Use configuration options of the access method:
3381 Programs used for access methods already offer powerful configurations
3382 (@pxref{Customizing Completion}).  For @option{ssh}, configure the
3383 file @file{~/.ssh/config}:
3385 @example
3386 @group
3387 Host xy
3388      HostName news.my.domain
3389      User news
3390 @end group
3391 @end example
3393 The reduced typing: @kbd{C-x C-f @trampfn{ssh,xy,/opt/news/etc}}.
3395 Depending on the number of files in the directories, host names
3396 completion can further reduce key strokes: @kbd{C-x C-f
3397 @value{prefix}ssh@value{postfixhop}x @key{TAB}}.
3399 @item
3400 Use environment variables to expand long strings
3402 For long file names, set up environment variables that are expanded in
3403 the minibuffer.  Environment variables are set either outside Emacs or
3404 inside Emacs with Lisp:
3406 @lisp
3407 (setenv "xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")
3408 @end lisp
3410 The reduced typing: @kbd{C-x C-f $xy @key{RET}}.
3412 @strong{Note} that file name cannot be edited here because the
3413 environment variables are not expanded during editing in the
3414 minibuffer.
3416 @item Define own keys:
3418 Redefine another key sequence in Emacs for @kbd{C-x C-f}:
3420 @lisp
3421 @group
3422 (global-set-key
3423  [(control x) (control y)]
3424  (lambda ()
3425    (interactive)
3426    (find-file
3427     (read-file-name
3428      "Find @value{tramp} file: "
3429      "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))))
3430 @end group
3431 @end lisp
3433 Simply typing @kbd{C-x C-y} would prepare minibuffer editing of file
3434 name.
3436 See @uref{https://www.emacswiki.org/emacs/TrampMode, the Emacs Wiki}
3437 for a more comprehensive example.
3439 @item
3440 Define own abbreviation (1):
3442 Abbreviation list expansion can be used to reduce typing long file names:
3444 @lisp
3445 @group
3446 (add-to-list
3447  'directory-abbrev-alist
3448  '("^/xy" . "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
3449 @end group
3450 @end lisp
3452 The reduced typing: @kbd{C-x C-f /xy @key{RET}}.
3454 @strong{Note} that file name cannot be edited here because the
3455 environment variables are not expanded during editing in the
3456 minibuffer.
3458 @item
3459 Define own abbreviation (2):
3461 The @code{abbrev-mode} gives additional flexibility for editing in the
3462 minibuffer:
3464 @lisp
3465 @group
3466 (define-abbrev-table 'my-tramp-abbrev-table
3467   '(("xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")))
3468 @end group
3470 @group
3471 (add-hook
3472  'minibuffer-setup-hook
3473  (lambda ()
3474    (abbrev-mode 1)
3475    (setq local-abbrev-table my-tramp-abbrev-table)))
3476 @end group
3478 @group
3479 (defadvice minibuffer-complete
3480   (before my-minibuffer-complete activate)
3481   (expand-abbrev))
3482 @end group
3484 @group
3485 ;; If you use partial-completion-mode
3486 (defadvice PC-do-completion
3487   (before my-PC-do-completion activate)
3488   (expand-abbrev))
3489 @end group
3490 @end lisp
3492 The reduced typing: @kbd{C-x C-f xy @key{TAB}}.
3494 The minibuffer expands for further editing.
3496 @item Use bookmarks:
3498 Use bookmarks to save @value{tramp} file names.
3499 @ifinfo
3500 @pxref{Bookmarks, , , emacs}.
3501 @end ifinfo
3503 Upon visiting a location with @value{tramp}, save it as a bookmark with
3504 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{set}}.
3506 To revisit that bookmark:
3507 @kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{jump}}.
3509 @item Use recent files:
3511 @file{recentf} remembers visited places.
3512 @ifinfo
3513 @pxref{File Conveniences, , , emacs}.
3514 @end ifinfo
3516 Keep remote file names in the recent list without have to check for
3517 their accessibility through remote access:
3519 @lisp
3520 (recentf-mode 1)
3521 @end lisp
3523 Reaching recently opened files: @kbd{@key{menu-bar} @key{file}
3524 @key{Open Recent}}.
3526 @item Use filecache:
3528 Since @file{filecache} remembers visited places, add the remote
3529 directory to the cache:
3531 @lisp
3532 @group
3533 @c `with-eval-after-load' has been introduced with Emacs 24.4.  Shall
3534 @c be used when appropriate.
3535 (eval-after-load "filecache"
3536   '(file-cache-add-directory
3537     "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
3538 @end group
3539 @end lisp
3541 Then use directory completion in the minibuffer with @kbd{C-x C-f
3542 C-@key{TAB}}.
3544 @item Use bbdb:
3546 @file{bbdb} has a built-in feature for Ange FTP files, which also
3547 works for @value{tramp} file names.
3548 @ifinfo
3549 @pxref{bbdb-ftp, Storing FTP sites in the BBDB, , bbdb}.
3550 @end ifinfo
3552 Load @file{bbdb} in Emacs:
3554 @lisp
3555 @group
3556 (require 'bbdb)
3557 (bbdb-initialize)
3558 @end group
3559 @end lisp
3561 Create a BBDB entry with @kbd{M-x bbdb-create-ftp-site}.  Then specify
3562 a method and user name where needed.  Examples:
3564 @example
3565 @group
3566 @kbd{M-x bbdb-create-ftp-site @key{RET}}
3567 @b{Ftp Site:} news.my.domain @key{RET}
3568 @b{Ftp Directory:} /opt/news/etc/ @key{RET}
3569 @b{Ftp Username:} ssh@value{postfixhop}news @key{RET}
3570 @b{Company:} @key{RET}
3571 @b{Additional Comments:} @key{RET}
3572 @end group
3573 @end example
3575 In BBDB buffer, access an entry by pressing the key @key{F}.
3577 @end enumerate
3579 Thanks to @value{tramp} users for contributing to these recipes.
3581 @item
3582 Why saved multi-hop file names do not work in a new Emacs session?
3584 When saving ad-hoc multi-hop @value{tramp} file names (@pxref{Ad-hoc
3585 multi-hops}) via bookmarks, recent files, filecache, bbdb, or another
3586 package, use the full ad-hoc file name including all hops, like
3587 @file{@trampfn{ssh,bird@@bastion|ssh@value{postfixhop}news.my.domain,/opt/news/etc}}.
3589 Alternatively, when saving abbreviated multi-hop file names
3590 @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, the user
3591 option @option{tramp-save-ad-hoc-proxies} must be set non-@code{nil}
3592 value.
3595 @item
3596 How to connect to a remote Emacs session using @value{tramp}?
3598 Configure Emacs Client
3599 @ifinfo
3600 (@pxref{Emacs Server, , , emacs}).
3601 @end ifinfo
3603 Then on the remote host, start the Emacs Server:
3605 @lisp
3606 @group
3607 (require 'server)
3608 (setq server-host (system-name)
3609       server-use-tcp t)
3610 (server-start)
3611 @end group
3612 @end lisp
3614 If @code{(system-name)} of the remote host cannot be resolved on the
3615 local host, use IP address instead.
3617 Copy from the remote host the resulting file
3618 @file{~/.emacs.d/server/server} to the local host, to the same
3619 location.
3621 Then start Emacs Client from the command line:
3623 @example
3624 emacsclient @trampfn{ssh,user@@host,/file/to/edit}
3625 @end example
3627 @code{user} and @code{host} refer to the local host.
3629 To make Emacs Client an editor for other programs, use a wrapper
3630 script @file{emacsclient.sh}:
3632 @example
3633 @group
3634 #!/bin/sh
3635 emacsclient @trampfn{ssh,$(whoami)@@$(hostname --fqdn),$1}
3636 @end group
3637 @end example
3639 Then change the environment variable @env{EDITOR} to point to the
3640 wrapper script:
3642 @example
3643 export EDITOR=/path/to/emacsclient.sh
3644 @end example
3647 @item
3648 How to disable other packages from calling @value{tramp}?
3650 There are packages that call @value{tramp} without the user ever
3651 entering a remote file name.  Even without applying a remote file
3652 syntax, some packages enable @value{tramp} on their own.  How can users
3653 disable such features.
3655 @itemize @minus
3656 @item
3657 @file{ido.el}
3659 Disable @value{tramp} file name completion:
3661 @lisp
3662 (custom-set-variables '(ido-enable-tramp-completion nil))
3663 @end lisp
3665 @item
3666 @file{rlogin.el}
3668 Disable remote directory tracking mode:
3670 @lisp
3671 (rlogin-directory-tracking-mode -1)
3672 @end lisp
3673 @end itemize
3676 @item
3677 How to disable @value{tramp}?
3679 @itemize @minus
3680 @item
3681 To keep Ange FTP as default the remote files access package, set this
3682 in @file{.emacs}:
3684 @lisp
3685 (custom-set-variables '(tramp-default-method "ftp" nil (tramp)))
3686 @end lisp
3688 @item
3689 To disable both @value{tramp} (and Ange FTP), set @code{tramp-mode} to
3690 @code{nil} in @file{.emacs}.
3692 @lisp
3693 (custom-set-variables '(tramp-mode nil nil (tramp)))
3694 @end lisp
3696 @item
3697 To unload @value{tramp}, type @kbd{M-x tramp-unload-tramp}.  Unloading
3698 @value{tramp} resets Ange FTP plugins also.
3699 @end itemize
3700 @end itemize
3703 @c For the developer
3704 @node Files directories and localnames
3705 @chapter How file names, directories and localnames are mangled and managed.
3707 @menu
3708 * Localname deconstruction::    Splitting a localname into its component parts.
3709 * External packages::           Integrating with external Lisp packages.
3710 @end menu
3713 @node Localname deconstruction
3714 @section Splitting a localname into its component parts
3716 @value{tramp} package redefines lisp functions
3717 @code{file-name-directory} and @code{file-name-nondirectory} to
3718 accommodate the unique file naming syntax that @value{tramp} requires.
3720 The replacements dissect the file name, use the original handler for
3721 the localname, take that result, and then re-build the @value{tramp}
3722 file name.  By relying on the original handlers for localnames,
3723 @value{tramp} benefits from platform specific hacks to the original
3724 handlers.
3727 @node External packages
3728 @section Integrating with external Lisp packages
3729 @subsection File name completion.
3731 Sometimes, it is not convenient to open a new connection to a remote
3732 host, including entering the password and alike.  For example, this is
3733 nasty for packages providing file name completion. Such a package
3734 could signal to @value{tramp}, that they don't want it to establish a
3735 new connection.  Use the variable @code{non-essential} temporarily and
3736 bind it to non-@code{nil} value.
3738 @lisp
3739 @group
3740 (let ((non-essential t))
3741   @dots{})
3742 @end group
3743 @end lisp
3746 @subsection File attributes cache.
3748 Keeping a local cache of remote file attributes in sync with the
3749 remote host is a time-consuming operation.  Flushing and re-querying
3750 these attributes can tax @value{tramp} to a grinding halt on busy
3751 remote servers.
3753 To get around these types of slow-downs in @value{tramp}'s
3754 responsiveness, set the @code{process-file-side-effects} to @code{nil}
3755 to stop @value{tramp} from flushing the cache.  This is helpful in
3756 situations where callers to @code{process-file} know there are no file
3757 attribute changes.  The let-bind form to accomplish this:
3759 @lisp
3760 @group
3761 (let (process-file-side-effects)
3762   @dots{})
3763 @end group
3764 @end lisp
3766 For asynchronous processes, @value{tramp} uses a process sentinel to
3767 flush file attributes cache.  When callers to @code{start-file-process}
3768 know beforehand no file attribute changes are expected, then the
3769 process sentinel should be set to the default state.  In cases where
3770 the caller defines its own process sentinel, @value{tramp}'s process
3771 sentinel is overwritten.  The caller can still flush the file
3772 attributes cache in its process sentinel with this code:
3774 @lisp
3775 @group
3776 (unless (memq (process-status proc) '(run open))
3777   (dired-uncache remote-directory))
3778 @end group
3779 @end lisp
3781 Since @value{tramp} traverses subdirectories starting with the
3782 root-directory, it is most likely sufficient to make the
3783 @code{default-directory} of the process buffer as the root directory.
3786 @node Traces and Profiles
3787 @chapter How to Customize Traces
3789 @value{tramp} messages are raised with verbosity levels ranging from 0
3790 to 10.  @value{tramp} does not display all messages; only those with a
3791 verbosity level less than or equal to @code{tramp-verbose}.
3793 The verbosity levels are
3795           @w{ 0}  silent (no @value{tramp} messages at all)
3796 @*@indent @w{ 1}  errors
3797 @*@indent @w{ 2}  warnings
3798 @*@indent @w{ 3}  connection to remote hosts (default verbosity)
3799 @*@indent @w{ 4}  activities
3800 @*@indent @w{ 5}  internal
3801 @*@indent @w{ 6}  sent and received strings
3802 @*@indent @w{ 7}  file caching
3803 @*@indent @w{ 8}  connection properties
3804 @*@indent @w{ 9}  test commands
3805 @*@indent @w{10}  traces (huge)
3807 With @code{tramp-verbose} greater than or equal to 4, messages are
3808 also written to a @value{tramp} debug buffer.  Such debug buffers are
3809 essential to bug and problem analyses.  For @value{tramp} bug reports,
3810 set the @code{tramp-verbose} level to 6 (@pxref{Bug Reports}).
3812 The debug buffer is in
3813 @ifinfo
3814 @ref{Outline Mode, , , emacs}.
3815 @end ifinfo
3816 @ifnotinfo
3817 Outline Mode.
3818 @end ifnotinfo
3819 In this buffer, messages can be filtered by their level.  To see
3820 messages up to verbosity level 5, enter @kbd{C-u 6 C-c C-q}.
3821 @ifinfo
3822 Other navigation keys are described in
3823 @ref{Outline Visibility, , , emacs}.
3824 @end ifinfo
3826 @value{tramp} handles errors internally.  But to get a Lisp backtrace,
3827 both the error and the signal have to be set as follows:
3829 @lisp
3830 @group
3831 (setq debug-on-error t
3832       debug-on-signal t)
3833 @end group
3834 @end lisp
3836 If @code{tramp-verbose} is greater than or equal to 10, Lisp
3837 backtraces are also added to the @value{tramp} debug buffer in case of
3838 errors.
3840 To enable stepping through @value{tramp} function call traces, they
3841 have to be specifically enabled as shown in this code:
3843 @lisp
3844 @group
3845 (require 'trace)
3846 (dolist (elt (all-completions "tramp-" obarray 'functionp))
3847   (trace-function-background (intern elt)))
3848 (untrace-function 'tramp-read-passwd)
3849 @end group
3850 @end lisp
3852 The buffer @file{*trace-output*} contains the output from the function
3853 call traces.  Disable @code{tramp-read-passwd} to stop password
3854 strings from being written to @file{*trace-output*}.
3857 @node GNU Free Documentation License
3858 @appendix GNU Free Documentation License
3859 @include doclicense.texi
3862 @node Function Index
3863 @unnumbered Function Index
3864 @printindex fn
3867 @node Variable Index
3868 @unnumbered Variable Index
3869 @printindex vr
3872 @node Concept Index
3873 @unnumbered Concept Index
3874 @printindex cp
3876 @bye
3878 @c TODO
3880 @c * Say something about the .login and .profile files of the remote
3881 @c   shells.
3882 @c * Explain how tramp.el works in principle: open a shell on a remote
3883 @c   host and then send commands to it.
3884 @c * Consistent small or capitalized words especially in menus.