1\input texinfo   @c -*- mode: texinfo; coding: utf-8 -*-
2@setfilename ../../info/tramp.info
3@c %**start of header
4@include docstyle.texi
5@c In the Tramp GIT, the version number is auto-frobbed from tramp.el,
6@c and the bug report address is auto-frobbed from configure.ac.
7@include trampver.texi
8@settitle @value{tramp} @value{trampver} User Manual
9@c %**end of header
10
11@c This is *so* much nicer :)
12@footnotestyle end
13
14@copying
15Copyright @copyright{} 1999--2021 Free Software Foundation, Inc.
16
17@quotation
18Permission is granted to copy, distribute and/or modify this document
19under the terms of the GNU Free Documentation License, Version 1.3 or
20any later version published by the Free Software Foundation; with no
21Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
22and with the Back-Cover Texts as in (a) below.  A copy of the license
23is included in the section entitled ``GNU Free Documentation License''.
24
25(a) The FSF's Back-Cover Text is: ``You have the freedom to
26copy and modify this GNU manual.''
27@end quotation
28@end copying
29
30@c Entries for @command{install-info} to use.  We cannot use @value{tramp}.
31@dircategory Emacs network features
32@direntry
33* Tramp: (tramp).               Transparent Remote Access, Multiple Protocol
34                                  Emacs remote file access via ssh and scp.
35@end direntry
36
37@titlepage
38@title @value{tramp} @value{trampver} User Manual
39@author by Daniel Pittman
40@author based on documentation by Kai Großjohann
41@end titlepage
42
43@contents
44
45
46@node Top, Overview, (dir), (dir)
47@top @value{tramp} @value{trampver} User Manual
48
49This file documents @value{tramp} @value{trampver}, a remote file
50editing package for Emacs.
51
52@value{tramp} stands for ``Transparent Remote (file) Access, Multiple
53Protocol''.  This package provides remote file editing, similar to
54Ange FTP@.
55
56The difference is that Ange FTP uses FTP to transfer files between the
57local and the remote host, whereas @value{tramp} uses a combination of
58@command{rsh} and @command{rcp} or other work-alike programs, such as
59@command{ssh}/@command{scp}.
60
61You can find the latest version of this document on the web at
62@uref{https://www.gnu.org/software/tramp/}.
63
64@ifhtml
65The latest release of @value{tramp} is available for
66@uref{https://ftp.gnu.org/gnu/tramp/, download}, or you may see
67@ref{Obtaining @value{tramp}} for more details, including the Git
68server details.
69
70@value{tramp} also has a @uref{https://savannah.gnu.org/projects/tramp/,
71Savannah Project Page}.
72@end ifhtml
73
74There is a mailing list for @value{tramp}, available at
75@email{@value{tramp-bug-report-address}}, and archived at
76@uref{https://lists.gnu.org/r/tramp-devel/, the @value{tramp} Mail
77Archive}.
78
79@page
80@insertcopying
81
82@menu
83* Overview::                    What @value{tramp} can and cannot do.
84
85For the end user:
86
87* Obtaining @value{tramp}::             How to obtain @value{tramp}.
88@ifset installchapter
89* Installation::                Installing @value{tramp} with your Emacs.
90@end ifset
91* Quick Start Guide::           Short introduction how to use @value{tramp}.
92* Configuration::               Configuring @value{tramp} for use.
93* Usage::                       An overview of the operation of @value{tramp}.
94* Bug Reports::                 Reporting Bugs and Problems.
95* Frequently Asked Questions::  Questions and answers from the mailing list.
96
97For the developer:
98
99* Files directories and localnames::
100                                How file names, directories and localnames
101                                  are mangled and managed.
102* Traces and Profiles::         How to Customize Traces.
103
104* GNU Free Documentation License:: The license for this documentation.
105* Function Index::              @value{tramp} functions.
106* Variable Index::              User options and variables.
107* Concept Index::               An item for each concept.
108
109@detailmenu
110 --- The Detailed Node Listing ---
111@c
112@ifset installchapter
113
114Installing @value{tramp} with your Emacs
115
116* System Requirements::         Prerequisites for @value{tramp} installation.
117* Basic Installation::          Installation steps.
118* Installation parameters::     Parameters in order to control installation.
119* Testing::                     A test suite for @value{tramp}.
120* Load paths::                  How to plug-in @value{tramp} into your environment.
121@end ifset
122
123Configuring @value{tramp} for use
124
125* Connection types::            Types of connections to remote hosts.
126* Inline methods::              Inline methods.
127* External methods::            External methods.
128* GVFS-based methods::          @acronym{GVFS}-based external methods.
129* Default Method::              Selecting a default method.
130* Default User::                Selecting a default user.
131* Default Host::                Selecting a default host.
132* Multi-hops::                  Connecting to a remote host using multiple hops.
133* Firewalls::                   Passing firewalls.
134* Customizing Methods::         Using Non-Standard Methods.
135* Customizing Completion::      Selecting config files for user/host name completion.
136* Password handling::           Reusing passwords for several connections.
137* Connection caching::          Reusing connection related information.
138* Predefined connection information::
139                                Setting own connection related information.
140* Remote programs::             How @value{tramp} finds and uses programs on the remote host.
141* Remote shell setup::          Remote shell setup hints.
142* Android shell setup::         Android shell setup hints.
143* Auto-save and Backup::        Auto-save and Backup.
144* Windows setup hints::         Issues with Cygwin ssh.
145
146Using @value{tramp}
147
148* File name syntax::            @value{tramp} file name conventions.
149@ifset unified
150* Change file name syntax::     Alternative file name syntax.
151@end ifset
152* File name completion::        File name completion.
153* Ad-hoc multi-hops::           Declaring multiple hops in the file name.
154* Remote processes::            Integration with other Emacs packages.
155* Cleanup remote connections::  Cleanup remote connections.
156* Renaming remote files::       Renaming remote files.
157* Archive file names::          Access to files in file archives.
158
159How file names, directories and localnames are mangled and managed
160
161* Localname deconstruction::    Breaking a localname into its components.
162* External packages::           Integration with external Lisp packages.
163
164@end detailmenu
165@end menu
166
167
168@node Overview
169@chapter An overview of @value{tramp}
170@cindex overview
171
172@value{tramp} is for transparently accessing remote files from within
173Emacs.  @value{tramp} enables an easy, convenient, and consistent
174interface to remote files as if they are local files.  @value{tramp}'s
175transparency extends to editing, version control, and @code{dired}.
176
177@value{tramp} can access remote hosts using any number of access
178methods, such as @command{rsh}, @command{rlogin}, @command{telnet},
179and related programs.  If these programs can successfully pass
180@acronym{ASCII} characters, @value{tramp} can use them.
181@value{tramp} does not require or mandate 8-bit clean connections.
182
183@value{tramp}'s most common access method is through @command{ssh}, a
184more secure alternative to @command{ftp} and other older access
185methods.
186
187@value{tramp} on MS Windows operating systems is integrated with the
188PuTTY package, and uses the @command{plink} program.
189
190@value{tramp} mostly operates transparently in the background using
191the connection programs.  As long as these programs enable remote login
192and can use the terminal, @value{tramp} can adapt them for seamless
193and transparent access.
194
195@value{tramp} temporarily transfers a remote file's contents to the
196local host editing and related operations.  @value{tramp} can also
197transfer files between hosts using standard Emacs interfaces, a
198benefit of direct integration of @value{tramp} in Emacs.
199
200@value{tramp} can transfer files using any number of available host
201programs for remote files, such as @command{rcp}, @command{scp},
202@command{rsync} or (under MS Windows) @command{pscp}.  @value{tramp}
203provides easy ways to specify these programs and customize them to
204specific files, hosts, or access methods.
205
206For faster small-size file transfers, @value{tramp} supports encoded
207transfers directly through the shell using @command{mimencode} or
208@command{uuencode} provided such tools are available on the remote
209host.
210
211
212@subsubheading @value{tramp} behind the scenes
213@cindex behind the scenes
214@cindex details of operation
215@cindex how it works
216
217Accessing a remote file through @value{tramp} entails a series of
218actions, many of which are transparent to the user.  Yet some actions
219may require user response (such as entering passwords or completing
220file names).  One typical scenario, opening a file on a remote host, is
221presented here to illustrate the steps involved:
222
223@kbd{C-x C-f} to initiate find-file, enter part of the @value{tramp}
224file name, then hit @kbd{@key{TAB}} for completion.  If this is the
225first time connection to that host, here's what happens:
226
227@itemize
228@item
229@value{tramp} invokes @samp{telnet @var{host}} or @samp{rsh @var{host}
230-l @var{user}} and establishes an external process to connect to the
231remote host.  @value{tramp} communicates with the process through an
232Emacs buffer, which also shows output from the remote host.
233
234@item
235The remote host may prompt for a login name (for @command{telnet}, for
236example) in the buffer.  If on the other hand, the login name was
237included in the file name portion, @value{tramp} sends the login name
238followed by a newline.
239
240@item
241The remote host may then prompt for a password or pass phrase (for
242@command{rsh} or for @command{telnet}).  @value{tramp} displays the
243password prompt in the minibuffer.  @value{tramp} then sends whatever
244is entered to the remote host, followed by a newline.
245
246@item
247@value{tramp} now waits for either the shell prompt or a failed login
248message.
249
250If @value{tramp} does not receive any messages within a timeout period
251(a minute, for example), then @value{tramp} responds with an error
252message about not finding the remote shell prompt.  If any messages
253from the remote host, @value{tramp} displays them in the buffer.
254
255For any @samp{login failed} message from the remote host,
256@value{tramp} aborts the login attempt, and repeats the login steps
257again.
258
259@item
260Upon successful login and @value{tramp} recognizes the shell prompt
261from the remote host, @value{tramp} prepares the shell environment by
262turning off echoing, setting shell prompt, and other housekeeping
263chores.
264
265@strong{Note} that for the remote shell, @value{tramp} invokes
266@command{/bin/sh}.  The remote host must recognize @samp{exec /bin/sh}
267and execute the appropriate shell.  This shell must support Bourne
268shell syntax.
269
270@item
271@value{tramp} executes @command{cd} and @command{ls} commands to find
272which files exist on the remote host.  @value{tramp} sometimes uses
273@command{echo} with globbing.  @value{tramp} checks if a file or
274directory is writable with @command{test}.  After each command,
275@value{tramp} parses the output from the remote host for completing
276the next operation.
277
278@item
279After remote file name completion, @value{tramp} transfers the file
280contents from the remote host.
281
282For inline transfers, @value{tramp} sends a command, such as
283@samp{mimencode -b /path/to/remote/file}, waits until the output has
284accumulated in the buffer, decodes that output to produce the file's
285contents.
286
287For external transfers, @value{tramp} sends a command as follows:
288@example
289rcp user@@host:/path/to/remote/file /tmp/tramp.4711
290@end example
291@value{tramp} reads the local temporary file @file{/tmp/tramp.4711}
292into a buffer, and then deletes the temporary file.
293
294@item
295Edit, modify, change the buffer contents as normal, and then save the
296buffer with @kbd{C-x C-s}.
297
298@item
299@value{tramp} transfers the buffer contents to the remote host in
300a reverse of the process using the appropriate inline or external
301program.
302@end itemize
303
304I hope this has provided you with a basic overview of what happens
305behind the scenes when you open a file with @value{tramp}.
306
307
308@c For the end user
309@node Obtaining @value{tramp}
310@chapter Obtaining @value{tramp}
311@cindex obtaining @value{tramp}
312@cindex GNU ELPA
313@vindex tramp-version
314
315@value{tramp} is included as part of Emacs (since Emacs 22.1).
316
317@value{tramp} is also freely packaged for download on the Internet at
318@uref{https://ftp.gnu.org/gnu/tramp/}.  The version number of
319@value{tramp} can be obtained by the variable @code{tramp-version}.
320For released @value{tramp} versions, this is a three-number string
321like ``2.4.5''.
322
323A @value{tramp} release, which is packaged with Emacs, could differ
324slightly from the corresponding standalone release.  This is because
325it isn't always possible to synchronize release dates between Emacs
326and @value{tramp}.  Such version numbers have the Emacs version number
327as suffix, like ``2.4.5.27.2''.  This means @value{tramp} 2.4.5 as
328integrated in Emacs 27.2.  A complete list of @value{tramp} versions
329packaged with Emacs can be retrieved by
330
331@vindex customize-package-emacs-version-alist
332@lisp
333(assoc 'Tramp customize-package-emacs-version-alist)
334@end lisp
335
336@value{tramp} is also available as @uref{https://elpa.gnu.org, GNU
337ELPA} package.  Besides the standalone releases, further minor version
338of @value{tramp} will appear on GNU ELPA, until the next @value{tramp}
339release appears.  These minor versions have a four-number string, like
340``2.4.5.1''.
341
342@value{tramp} development versions are available on Git servers.
343Development versions contain new and incomplete features.  The
344development version of @value{tramp} is always the version number of
345the next release, plus the suffix ``-pre'', like ``2.4.4-pre''.
346
347One way to obtain @value{tramp} from Git server is to visit the
348Savannah project page at the following URL and then clicking on the
349Git link in the navigation bar at the top.
350
351@noindent
352@uref{https://savannah.gnu.org/projects/tramp/}
353
354@noindent
355Another way is to follow the terminal session below:
356
357@example
358@group
359$ cd ~/emacs
360$ git clone git://git.savannah.gnu.org/tramp.git
361@end group
362@end example
363
364@noindent
365From behind a firewall:
366
367@example
368@group
369$ git config --global http.proxy http://user:pwd@@proxy.server.com:8080
370$ git clone https://git.savannah.gnu.org/r/tramp.git
371@end group
372@end example
373
374@noindent
375@value{tramp} developers:
376
377@example
378$ git clone login@@git.sv.gnu.org:/srv/git/tramp.git
379@end example
380
381@noindent
382After one of the above commands, @file{~/emacs/tramp} will
383containing the latest version of @value{tramp}.
384
385@noindent
386To fetch updates from the repository, use @code{git pull}:
387
388@example
389@group
390$ cd ~/emacs/tramp
391$ git pull
392@end group
393@end example
394
395@noindent
396Run @command{autoconf} as follows to generate an up-to-date
397@file{configure} script:
398
399@example
400@group
401$ cd ~/emacs/tramp
402$ autoconf
403@end group
404@end example
405
406@ifset installchapter
407@c Installation chapter is necessary only in case of standalone
408@c installation.
409@include trampinst.texi
410@end ifset
411@ifclear installchapter
412See the file @file{INSTALL} in that directory for further information
413how to install @value{tramp}.
414@end ifclear
415
416
417@node Quick Start Guide
418@chapter Short introduction how to use @value{tramp}
419@cindex quick start guide
420
421@value{tramp} extends the Emacs file name syntax by a remote
422component.  A remote file name looks always like
423@file{@trampfn{method,user@@host,/path/to/file}}.
424
425You can use remote files exactly like ordinary files, that means you
426could open a file or directory by @kbd{C-x C-f
427@trampfn{method,user@@host,/path/to/file} @key{RET}}, edit the file,
428and save it.  You can also mix local files and remote files in file
429operations with two arguments, like @code{copy-file} or
430@code{rename-file}.  And finally, you can run even processes on a
431remote host, when the buffer you call the process from has a remote
432@code{default-directory}.
433
434
435@anchor{Quick Start Guide: File name syntax}
436@section File name syntax
437@cindex file name syntax
438
439Remote file names are prepended by the @code{method}, @code{user} and
440@code{host} parts.  All of them, and also the local file name part,
441are optional, in case of a missing part a default value is assumed.
442The default value for an empty local file name part is the remote
443user's home directory.  The shortest remote file name is
444@file{@trampfn{-,,}}, therefore.  The @samp{-} notation for the
445default method is used for syntactical reasons, @ref{Default Method}.
446
447The @code{method} part describes the connection method used to reach
448the remote host, see below.
449
450The @code{user} part is the user name for accessing the remote host.
451For the @option{smb} method, this could also require a domain name, in
452this case it is written as @code{user%domain}.
453
454The @code{host} part must be a host name which could be resolved on
455your local host.  It could be a short host name, a fully qualified
456domain name, an IPv4 or IPv6 address, @ref{File name syntax}.  Some
457connection methods support also a notation of the port to be used, in
458this case it is written as @code{host#port}.
459
460
461@anchor{Quick Start Guide: @option{ssh} and @option{plink} methods}
462@section Using @option{ssh} and @option{plink}
463@cindex method @option{ssh}
464@cindex @option{ssh} method
465@cindex method @option{plink}
466@cindex @option{plink} method
467
468If your local host runs an SSH client, and the remote host runs an SSH
469server, the simplest remote file name is
470@file{@trampfn{ssh,user@@host,/path/to/file}}.  The remote file name
471@file{@trampfn{ssh,,}} opens a remote connection to yourself on the
472local host, and is taken often for testing @value{tramp}.
473
474On MS Windows, PuTTY is often used as SSH client.  Its @command{plink}
475method can be used there to open a connection to a remote host running
476an @command{ssh} server:
477@file{@trampfn{plink,user@@host,/path/to/file}}.
478
479
480@anchor{Quick Start Guide: @option{su}, @option{sudo} and @option{sg} methods}
481@section Using @option{su}, @option{sudo} and @option{sg}
482@cindex method @option{su}
483@cindex @option{su} method
484@cindex method @option{sudo}
485@cindex @option{sudo} method
486@cindex method @option{sg}
487@cindex @option{sg} method
488
489Sometimes, it is necessary to work on your local host under different
490permissions.  For this, you could use the @option{su} or @option{sudo}
491connection method.  Both methods use @samp{root} as default user name
492and the return value of @code{(system-name)} as default host name.
493Therefore, it is convenient to open a file as
494@file{@trampfn{sudo,,/path/to/file}}.
495
496The method @option{sg} stands for ``switch group''; the changed group
497must be used here as user name.  The default host name is the same.
498
499
500@anchor{Quick Start Guide: @option{ssh}, @option{plink}, @option{su}, @option{sudo} and @option{sg} methods}
501@section Combining @option{ssh} or @option{plink} with @option{su} or @option{sudo}
502@cindex method @option{ssh}
503@cindex @option{ssh} method
504@cindex method @option{plink}
505@cindex @option{plink} method
506@cindex method @option{su}
507@cindex @option{su} method
508@cindex method @option{sudo}
509@cindex @option{sudo} method
510
511If the @option{su} or @option{sudo} option shall be performed on
512another host, it could be comnbined with a leading @option{ssh} or
513@option{plink} option.  That means, @value{tramp} connects first to
514the other host with non-administrative credentials, and changes to
515administrative credentials on that host afterwards.  In a simple case,
516the syntax looks like
517@file{@value{prefix}ssh@value{postfixhop}user@@host|sudo@value{postfixhop}@value{postfix}/path/to/file}.
518@xref{Ad-hoc multi-hops}.
519
520
521@anchor{Quick Start Guide: @option{sudoedit} method}
522@section Using @command{sudoedit}
523@cindex method @option{sudoedit}
524@cindex @option{sudoedit} method
525
526The @option{sudoedit} method is similar to the @option{sudo} method.
527However, it is a different implementation: it does not keep an open
528session running in the background.  This is for security reasons; on
529the backside this method is less performant than the @option{sudo}
530method, it is restricted to the @samp{localhost} only, and it does not
531support external processes.
532
533
534@anchor{Quick Start Guide: @option{smb} method}
535@section Using @command{smbclient}
536@cindex method @option{smb}
537@cindex @option{smb} method
538@cindex ms windows (with @option{smb} method)
539@cindex @command{smbclient}
540
541In order to access a remote MS Windows host or Samba server, the
542@command{smbclient} client is used.  The remote file name syntax is
543@file{@trampfn{smb,user%domain@@host,/path/to/file}}.  The first part
544of the local file name is the share exported by the remote host,
545@samp{path} in this example.
546
547
548@anchor{Quick Start Guide: GVFS-based methods}
549@section Using @acronym{GVFS}-based methods
550@cindex methods, gvfs
551@cindex gvfs-based methods
552@cindex method @option{sftp}
553@cindex @option{sftp} method
554@cindex method @option{afp}
555@cindex @option{afp} method
556@cindex method @option{dav}
557@cindex method @option{davs}
558@cindex @option{dav} method
559@cindex @option{davs} method
560
561On systems, which have installed @acronym{GVFS, the GNOME Virtual File
562System}, its offered methods could be used by @value{tramp}.  Examples
563are @file{@trampfn{sftp,user@@host,/path/to/file}},
564@file{@trampfn{afp,user@@host,/path/to/file}} (accessing Apple's AFP
565file system), @file{@trampfn{dav,user@@host,/path/to/file}} and
566@file{@trampfn{davs,user@@host,/path/to/file}} (for WebDAV shares).
567
568
569@anchor{Quick Start Guide: GNOME Online Accounts based methods}
570@section Using @acronym{GNOME} Online Accounts based methods
571@cindex @acronym{GNOME} Online Accounts
572@cindex method @option{gdrive}
573@cindex @option{gdrive} method
574@cindex google drive
575@cindex method @option{nextcloud}
576@cindex @option{nextcloud} method
577@cindex nextcloud
578
579@acronym{GVFS}-based methods include also @acronym{GNOME} Online
580Accounts, which support the @option{Files} service.  These are the
581Google Drive file system, and the OwnCloud/NextCloud file system.  The
582file name syntax is here always
583@file{@trampfn{gdrive,john.doe@@gmail.com,/path/to/file}}
584(@samp{john.doe@@gmail.com} stands here for your Google Drive
585account), or @file{@trampfn{nextcloud,user@@host#8081,/path/to/file}}
586(@samp{8081} stands for the port number) for OwnCloud/NextCloud files.
587
588
589@anchor{Quick Start Guide: Android}
590@section Using Android
591@cindex method @option{adb}
592@cindex @option{adb} method
593@cindex android
594
595An Android device, which is connected via USB to your local host, can
596be accessed via the @command{adb} command.  No user or host name is
597needed.  The file name syntax is @file{@trampfn{adb,,/path/to/file}}.
598
599
600@anchor{Quick Start Guide: @option{rclone} method}
601@section Using @command{rclone}
602@cindex method @option{rclone}
603@cindex @option{rclone} method
604
605A convenient way to access system storages is the @command{rclone}
606program.  If you have configured a storage in @command{rclone} under a
607name @samp{storage} (for example), you could access it via the remote
608file name syntax @file{@trampfn{rclone,storage,/path/to/file}}.  User
609names are not needed.
610
611
612@node Configuration
613@chapter Configuring @value{tramp}
614@cindex configuration
615@cindex default configuration
616
617@value{tramp} is initially configured to use the @command{scp} program
618to connect to the remote host.  Just type @kbd{C-x C-f} and then enter
619file name @file{@trampfn{scp,user@@host,/path/to/file}}.  For details,
620@xref{Default Method}, @xref{Default User}, @xref{Default Host}.
621
622For problems related to the behavior of the remote shell, @xref{Remote
623shell setup}.
624
625For changing the connection type and file access method from the
626defaults to one of several other options, @xref{Connection types}.
627
628@strong{Note} that some user options described in these examples are
629not auto loaded by Emacs.  All examples require @value{tramp} is
630installed and loaded:
631
632@lisp
633(customize-set-variable 'tramp-verbose 6 "Enable remote command traces")
634@end lisp
635
636For functions used to configure @value{tramp}, the following clause
637might be used in your init file:
638
639@lisp
640(with-eval-after-load 'tramp (tramp-change-syntax 'simplified))
641@end lisp
642
643
644@menu
645* Connection types::            Types of connections to remote hosts.
646* Inline methods::              Inline methods.
647* External methods::            External methods.
648* GVFS-based methods::          @acronym{GVFS}-based external methods.
649* Default Method::              Selecting a default method.
650                                  Here we also try to help those who
651                                  don't have the foggiest which method
652                                  is right for them.
653* Default User::                Selecting a default user.
654* Default Host::                Selecting a default host.
655* Multi-hops::                  Connecting to a remote host using multiple hops.
656* Firewalls::                   Passing firewalls.
657* Customizing Methods::         Using Non-Standard Methods.
658* Customizing Completion::      Selecting config files for user/host name completion.
659* Password handling::           Reusing passwords for several connections.
660* Connection caching::          Reusing connection related information.
661* Predefined connection information::
662                                Setting own connection related information.
663* Remote programs::             How @value{tramp} finds and uses programs on the remote host.
664* Remote shell setup::          Remote shell setup hints.
665* Android shell setup::         Android shell setup hints.
666* Auto-save and Backup::        Auto-save and Backup.
667* Windows setup hints::         Issues with Cygwin ssh.
668@end menu
669
670
671@node Connection types
672@section Types of connections to remote hosts
673@cindex connection types, overview
674
675@dfn{Inline method} and @dfn{external method} are the two basic types
676of access methods.  While they both use the same remote shell access
677programs, such as @command{rsh}, @command{ssh}, or @command{telnet},
678they differ in the file access methods.  Choosing the right method
679becomes important for editing files, transferring large files, or
680operating on a large number of files.
681
682The performance of the external methods is generally better than that
683of the inline methods, at least for large files.  This is caused by
684the need to encode and decode the data when transferring inline.
685
686The one exception to this rule are the @option{scp}-based access
687methods.  While these methods do see better performance when actually
688transferring files, the overhead of the cryptographic negotiation at
689startup may drown out the improvement in file transfer times.
690
691External methods should be configured such a way that they don't
692require a password (with @command{ssh-agent}, or such alike).  Modern
693@command{scp} implementations offer options to reuse existing
694@command{ssh} connections, which will be enabled by default if
695available.  If it isn't possible, you should consider @ref{Password
696handling}, otherwise you will be prompted for a password every copy
697action.
698
699
700@node Inline methods
701@section Inline methods
702@cindex inline methods
703@cindex methods, inline
704
705Inline methods use the same login connection to transfer file
706contents.  Inline methods are quick and easy for small files.  They
707depend on the availability of suitable encoding and decoding programs
708on the remote host.  For local source and destination, @value{tramp}
709may use built-in equivalents of such programs in Emacs.
710
711Inline methods can work in situations where an external transfer
712program is unavailable.  Inline methods also work when transferring
713files between different @emph{user identities} on the same host.
714
715@cindex base-64 encoding
716@cindex base-64 encoding
717@cindex uu encoding
718@vindex tramp-remote-coding-commands
719@value{tramp} checks the remote host for the availability and
720usability of one of the commands defined in
721@code{tramp-remote-coding-commands}.  @value{tramp} uses the first
722reliable command it finds.  @value{tramp}'s search path can be
723customized, see @ref{Remote programs}.
724
725In case none of the commands are unavailable, @value{tramp} first
726transfers a small Perl program to the remote host, and then tries that
727program for encoding and decoding.
728
729@vindex tramp-inline-compress-start-size
730@vindex tramp-inline-compress-commands
731To increase transfer speeds for large text files, use compression
732before encoding.  The user option
733@code{tramp-inline-compress-start-size} specifies the file size for
734such optimization.  This feature depends on the availability and
735usability of one of the commands defined in
736@code{tramp-inline-compress-commands}.
737
738@table @asis
739@item @option{rsh}
740@cindex method @option{rsh}
741@cindex @option{rsh} method
742
743@command{rsh} is an option for connecting to hosts within local
744networks since @command{rsh} is not as secure as other methods.
745
746@item @option{ssh}
747@cindex method @option{ssh}
748@cindex @option{ssh} method
749
750@command{ssh} is a more secure option than others to connect to a
751remote host.
752
753@command{ssh} can also take extra parameters as port numbers.  For
754example, a host on port 42 is specified as @file{host#42} (the real
755host name, a hash sign, then a port number).  It is the same as passing
756@samp{-p 42} to the @command{ssh} command.
757
758@item @option{telnet}
759@cindex method @option{telnet}
760@cindex @option{telnet} method
761
762Connecting to a remote host with @command{telnet} is as insecure
763as the @option{rsh} method.
764
765@item @option{su}
766@cindex method @option{su}
767@cindex @option{su} method
768
769Instead of connecting to a remote host, @command{su} program allows
770editing as another user.  The host can be either @samp{localhost} or
771the host returned by the function @command{(system-name)}.  See
772@ref{Multi-hops} for an exception to this behavior.
773
774@item @option{sudo}
775@cindex method @option{sudo}
776@cindex @option{sudo} method
777
778Similar to @option{su} method, @option{sudo} uses @command{sudo}.
779@command{sudo} must have sufficient rights to start a shell.
780
781For security reasons, a @option{sudo} connection is disabled after a
782predefined timeout (5 minutes per default).  This can be changed, see
783@ref{Predefined connection information}.
784
785@item @option{doas}
786@cindex method @option{doas}
787@cindex @option{doas} method
788
789This method is used on OpenBSD like the @command{sudo} command.  Like
790the @option{sudo} method, a @option{doas} connection is disabled after
791a predefined timeout.
792
793@item @option{sg}
794@cindex method @option{sg}
795@cindex @option{sg} method
796
797The @command{sg} program allows editing as different group.  The host
798can be either @samp{localhost} or the host returned by the function
799@command{(system-name)}.  The user name must be specified, but it
800denotes a group name.  See @ref{Multi-hops} for an exception to this
801behavior.
802
803@item @option{sshx}
804@cindex method @option{sshx}
805@cindex @option{sshx} method
806
807Works like @option{ssh} but without the extra authentication prompts.
808@option{sshx} uses @samp{ssh -t -t @var{host} -l @var{user} /bin/sh}
809to open a connection with a ``standard'' login shell.  It supports
810changing the remote login shell @command{/bin/sh}.
811
812@strong{Note} that @option{sshx} does not bypass authentication
813questions.  For example, if the host key of the remote host is not
814known, @option{sshx} will still ask ``Are you sure you want to
815continue connecting?''.  @value{tramp} cannot handle such questions.
816Connections will have to be setup where logins can proceed without
817such questions.
818
819@option{sshx} is useful for MS Windows users when @command{ssh}
820triggers an error about allocating a pseudo tty.  This happens due to
821missing shell prompts that confuses @value{tramp}.
822
823@option{sshx} supports the @samp{-p} argument.
824
825@item @option{krlogin}
826@cindex method @option{krlogin}
827@cindex @option{krlogin} method
828@cindex kerberos (with @option{krlogin} method)
829
830This method is also similar to @option{ssh}.  It uses the
831@command{krlogin -x} command only for remote host login.
832
833@item @option{ksu}
834@cindex method @option{ksu}
835@cindex @option{ksu} method
836@cindex kerberos (with @option{ksu} method)
837
838This is another method from the Kerberos suite.  It behaves like @option{su}.
839
840@item @option{plink}
841@cindex method @option{plink}
842@cindex @option{plink} method
843
844@option{plink} method is for MS Windows users with the PuTTY
845implementation of SSH@.  It uses @samp{plink -ssh} to log in to the
846remote host.  It supports changing the remote login shell @command{/bin/sh}.
847
848Check the @samp{Share SSH connections if possible} control for that
849session.
850
851@option{plink} method supports the @samp{-P} argument.
852
853@item @option{plinkx}
854@cindex method @option{plinkx}
855@cindex @option{plinkx} method
856
857Another method using PuTTY on MS Windows with session names instead of
858host names.  @option{plinkx} calls @samp{plink -load @var{session}
859-t}.  User names and port numbers must be defined in the session.  It
860supports changing the remote login shell @command{/bin/sh}.
861
862Check the @samp{Share SSH connections if possible} control for that
863session.
864
865@end table
866
867
868@node External methods
869@section External methods
870@cindex methods, external
871@cindex external methods
872
873External methods operate over multiple channels, using the remote
874shell connection for some actions while delegating file transfers to
875an external transfer program.
876
877External methods save on the overhead of encoding and decoding of
878inline methods.
879
880Since external methods have the overhead of opening a new channel,
881files smaller than @code{tramp-copy-size-limit} still use inline
882methods.
883
884@table @asis
885@item @option{rcp}
886@cindex method @option{rcp}
887@cindex @option{rcp} method
888@cindex @command{rsh} (with @option{rcp} method)
889
890This method uses the @command{rsh} and @command{rcp} commands to
891connect to the remote host and transfer files.  This is the fastest
892access method available.
893
894The alternative method @option{remcp} uses the @command{remsh} and
895@command{rcp} commands.
896
897@item @option{scp}
898@cindex method @option{scp}
899@cindex @option{scp} method
900@cindex @command{ssh} (with @option{scp} method)
901
902Using a combination of @command{ssh} to connect and @command{scp} to
903transfer is the most secure.  While the performance is good, it is
904slower than the inline methods for smaller files.  Though there is no
905overhead of encoding and decoding of the inline methods,
906@command{scp}'s cryptographic handshake negates those speed gains.
907
908@option{ssh}-based methods support @samp{-p} feature for specifying
909port numbers.  For example, @file{host#42} passes @samp{-p 42} in the
910argument list to @command{ssh}, and @samp{-P 42} in the argument list
911to @command{scp}.
912
913@item @option{rsync}
914@cindex method @option{rsync}
915@cindex @option{rsync} method
916@cindex @command{ssh} (with @option{rsync} method)
917
918@command{ssh} command to connect in combination with @command{rsync}
919command to transfer is similar to the @option{scp} method.
920
921@command{rsync} performs much better than @command{scp} when
922transferring files that exist on both hosts.  However, this advantage
923is lost if the file exists only on one side of the connection.
924
925This method supports the @samp{-p} argument.
926
927@item @option{scpx}
928@cindex method @option{scpx}
929@cindex @option{scpx} method
930@cindex @command{ssh} (with @option{scpx} method)
931
932@option{scpx} is useful to avoid login shell questions.  It is similar
933in performance to @option{scp}.  @option{scpx} uses @samp{ssh -t -t
934@var{host} -l @var{user} /bin/sh} to open a connection.  It supports
935changing the remote login shell @command{/bin/sh}.
936
937@option{scpx} is useful for MS Windows users when @command{ssh}
938triggers an error about allocating a pseudo tty.  This happens due to
939missing shell prompts that confuses @value{tramp}.
940
941This method supports the @samp{-p} argument.
942
943@item @option{pscp}
944@item @option{psftp}
945@cindex method @option{pscp}
946@cindex @option{pscp} method
947@cindex @command{plink} (with @option{pscp} method)
948@cindex @command{putty} (with @option{pscp} method)
949@cindex method @option{psftp}
950@cindex @option{psftp} method
951@cindex @command{plink} (with @option{psftp} method)
952@cindex @command{putty} (with @option{psftp} method)
953
954These methods are similar to @option{scp} or @option{sftp}, but they
955use the @command{plink} command to connect to the remote host, and
956they use @command{pscp} or @command{psftp} for transferring the files.
957These programs are part of PuTTY, an SSH implementation for MS Windows.
958
959They support changing the remote login shell @command{/bin/sh}.
960
961Check the @samp{Share SSH connections if possible} control for that
962session.
963
964These methods support the @samp{-P} argument.
965
966@item @option{fcp}
967@cindex method @option{fcp}
968@cindex @option{fcp} method
969@cindex @command{fsh} (with @option{fcp} method)
970
971This method is similar to @option{scp}, but uses @command{fsh} to
972connect and @command{fcp} to transfer files.  @command{fsh/fcp}, a
973front-end for @command{ssh}, reuse @command{ssh} session by
974submitting several commands.  This avoids the startup overhead due to
975@command{scp}'s secure connection.  Inline methods have similar
976benefits.
977
978The command used for this connection is: @samp{fsh @var{host} -l
979@var{user} /bin/sh -i}
980
981@cindex method @option{fsh}
982@cindex @option{fsh} method
983
984@option{fsh} has no inline method since the multiplexing it offers is
985not useful for @value{tramp}.  @command{fsh} connects to remote host
986and @value{tramp} keeps that one connection open.
987
988@item @option{nc}
989@cindex method @option{nc}
990@cindex @option{nc} method
991@cindex @command{telnet} (with @option{nc} method)
992
993Using @command{telnet} to connect and @command{nc} to transfer files
994is sometimes the only combination suitable for accessing routers or
995NAS hosts.  These dumb devices have severely restricted local shells,
996such as the @command{busybox} and do not host any other encode or
997decode programs.
998
999@item @option{sudoedit}
1000@cindex method @option{sudoedit}
1001@cindex @option{sudoedit} method
1002
1003The @option{sudoedit} method allows to edit a file as a different user
1004on the local host.  You could regard this as @value{tramp}'s
1005implementation of the @command{sudoedit}.  Contrary to the
1006@option{sudo} method, all magic file name functions are implemented by
1007single @command{sudo @dots{}}  commands.  The purpose is to make
1008editing such a file as secure as possible; there must be no session
1009running in the Emacs background which could be attacked from inside
1010Emacs.
1011
1012Consequently, external processes are not implemented.
1013
1014The host name of such remote file names must represent the local host.
1015Since the default value is already proper, it is recommended not to
1016use any host name in the remote file name, like
1017@file{@trampfn{sudoedit,,/path/to/file}} or
1018@file{@trampfn{sudoedit,user@@,/path/to/file}}.
1019
1020Like the @option{sudo} method, a @option{sudoedit} password expires
1021after a predefined timeout.
1022
1023@item @option{ftp}
1024@cindex method @option{ftp}
1025@cindex @option{ftp} method
1026
1027When @value{tramp} uses @option{ftp}, it forwards requests to whatever
1028ftp program is specified by Ange FTP@.  This external program must be
1029capable of servicing requests from @value{tramp}.
1030
1031@item @option{smb}
1032@cindex method @option{smb}
1033@cindex @option{smb} method
1034@cindex ms windows (with @option{smb} method)
1035@cindex @command{smbclient}
1036
1037This non-native @value{tramp} method connects via the Server Message
1038Block (SMB) networking protocol to hosts running file servers that are
1039typically based on @url{https://www.samba.org/,,Samba} or MS Windows.
1040
1041Using @command{smbclient} requires a few tweaks when working with
1042@value{tramp}:
1043
1044The first directory in the localname must be a share name on the
1045remote host.
1046
1047Since some SMB share names end in the @code{$} character,
1048@value{tramp} must use @code{$$} when specifying those shares to avoid
1049environment variable substitutions.
1050
1051When @value{tramp} is not specific about the share name or uses the
1052generic remote directory @file{/}, @command{smbclient} returns all
1053available shares.
1054
1055Since SMB authentication is based on each SMB share, @value{tramp}
1056prompts for a password even when accessing a different share on the
1057same SMB host.  This prompting can be suppressed by @ref{Password
1058handling}.
1059
1060To accommodate user name/domain name syntax required by MS Windows
1061authorization, @value{tramp} provides for an extended syntax in
1062@code{user%domain} format (where @code{user} is the user name,
1063@code{%} is the percent symbol, and @code{domain} is the MS Windows
1064domain name).  An example:
1065
1066@example
1067@trampfn{smb,daniel%BIZARRE@@melancholia,/daniel$$/.emacs}
1068@end example
1069
1070where user @code{daniel} connects as a domain user to the SMB host
1071@code{melancholia} in the MS Windows domain @code{BIZARRE} to edit
1072@file{.emacs} located in the home directory (share @code{daniel$}).
1073
1074Alternatively, for local WINS users (as opposed to domain users),
1075substitute the domain name with the name of the local host in
1076UPPERCASE as shown here:
1077
1078@example
1079@trampfn{smb,daniel%MELANCHOLIA@@melancholia,/daniel$$/.emacs}
1080@end example
1081
1082where user @code{daniel} connects as local user to the SMB host
1083@code{melancholia} in the local domain @code{MELANCHOLIA} to edit
1084@file{.emacs} located in the home directory (share @code{daniel$}).
1085
1086The domain name and user name are optional for @command{smbclient}
1087authentication.  When user name is not specified, @command{smbclient}
1088uses the anonymous user (without prompting for password).  This
1089behavior is unlike other @value{tramp} methods, where local user name
1090is substituted.
1091
1092The @option{smb} method is unavailable if Emacs is run under a local
1093user authentication context in MS Windows.  However such users can
1094still access remote files using UNC file names instead of @value{tramp}:
1095
1096@example
1097//melancholia/daniel$$/.emacs
1098@end example
1099
1100UNC file name specification does not allow the specification of a
1101different user name for authentication like the @command{smbclient}
1102can.
1103
1104
1105@item @option{adb}
1106@cindex method @option{adb}
1107@cindex @option{adb} method
1108@cindex android (with @option{adb} method)
1109
1110@vindex tramp-adb-program
1111@vindex PATH@r{, environment variable}
1112This method uses Android Debug Bridge program for accessing Android
1113devices.  The Android Debug Bridge must be installed locally for
1114@value{tramp} to work.  Some GNU/Linux distributions provide Android
1115Debug Bridge as an installation package.  Alternatively, the program
1116is installed as part of the Android SDK@.  @value{tramp} finds the
1117@command{adb} program either via the @env{PATH} environment variable
1118or the absolute path set in the user option @code{tramp-adb-program}.
1119
1120@vindex tramp-adb-connect-if-not-connected
1121@value{tramp} connects to Android devices with @option{adb} only when
1122the user option @code{tramp-adb-connect-if-not-connected} is not
1123@code{nil}.  Otherwise, the connection must be established outside
1124Emacs.
1125
1126@value{tramp} does not require a host name part of the remote file
1127name when a single Android device is connected to @command{adb}.
1128@value{tramp} instead uses @file{@trampfn{adb,,}} as the default name.
1129@command{adb devices} shows available host names.
1130
1131@option{adb} method normally does not need user name to authenticate
1132on the Android device because it runs under the @command{adbd}
1133process.  But when a user name is specified, however, @value{tramp}
1134applies an @command{su} in the syntax.  When authentication does not
1135succeed, especially on un-rooted Android devices, @value{tramp}
1136displays login errors.
1137
1138For Android devices connected through TCP/IP, a port number can be
1139specified using @file{device#42} host name syntax or @value{tramp} can
1140use the default value as declared in @command{adb} command.  Port
1141numbers are not applicable to Android devices connected through USB@.
1142
1143
1144@item @option{rclone}
1145@cindex method @option{rclone}
1146@cindex @option{rclone} method
1147
1148@vindex tramp-rclone-program
1149The program @command{rclone} allows to access different system
1150storages in the cloud, see @url{https://rclone.org/} for a list of
1151supported systems.  If the @command{rclone} program isn't found in
1152your @env{PATH} environment variable, you can tell @value{tramp} its
1153absolute path via the user option @code{tramp-rclone-program}.
1154
1155A system storage must be configured via the @command{rclone config}
1156command, outside Emacs.  If you have configured a storage in
1157@command{rclone} under a name @samp{storage} (for example), you could
1158access it via the remote file name
1159
1160@example
1161@trampfn{rclone,storage,/path/to/file}
1162@end example
1163
1164User names are part of the @command{rclone} configuration, and not
1165needed in the remote file name.  If a user name is contained in the
1166remote file name, it is ignored.
1167
1168Internally, @value{tramp} mounts the remote system storage at location
1169@file{/tmp/tramp.rclone.storage}, with @file{storage} being the name
1170of the configured system storage.
1171
1172Optional flags to the different @option{rclone} operations could be
1173passed as connection property, @xref{Predefined connection
1174information}.  Supported properties are @t{"mount-args"},
1175@t{"copyto-args"} and @t{"moveto-args"}.
1176
1177Access via @option{rclone} is slow.  If you have an alternative method
1178for accessing the system storage, you shall prefer this.
1179@ref{GVFS-based methods} for example, methods @option{gdrive} and
1180@option{nextcloud}.
1181
1182@strong{Note}: The @option{rclone} method is experimental, don't use
1183it in production systems!
1184
1185@end table
1186
1187
1188@node GVFS-based methods
1189@section @acronym{GVFS}-based external methods
1190@cindex methods, gvfs
1191@cindex gvfs-based methods
1192@cindex dbus
1193
1194@acronym{GVFS} is the virtual file system for the @acronym{GNOME}
1195Desktop, @uref{https://en.wikipedia.org/wiki/GVFS}.  Remote files on
1196@acronym{GVFS} are mounted locally through FUSE and @value{tramp} uses
1197this locally mounted directory internally.
1198
1199Emacs uses the D-Bus mechanism to communicate with @acronym{GVFS}@.
1200Emacs must have the message bus system, D-Bus integration active,
1201@pxref{Top, , D-Bus, dbus}.
1202
1203@table @asis
1204@item @option{afp}
1205@cindex method @option{afp}
1206@cindex @option{afp} method
1207
1208This method is for connecting to remote hosts with the Apple Filing
1209Protocol for accessing files on macOS volumes.  @value{tramp} access
1210syntax requires a leading volume (share) name, for example:
1211@file{@trampfn{afp,user@@host,/volume}}.
1212
1213@item @option{dav}
1214@item @option{davs}
1215@cindex method @option{dav}
1216@cindex method @option{davs}
1217@cindex @option{dav} method
1218@cindex @option{davs} method
1219
1220@option{dav} method provides access to WebDAV files and directories
1221based on standard protocols, such as HTTP@.  @option{davs} does the same
1222but with SSL encryption.  Both methods support the port numbers.
1223
1224Paths being part of the WebDAV volume to be mounted by @acronym{GVFS},
1225as it is common for OwnCloud or NextCloud file names, are not
1226supported by these methods.  See method @option{nextcloud} for
1227handling them.
1228
1229@item @option{gdrive}
1230@cindex method @option{gdrive}
1231@cindex @option{gdrive} method
1232@cindex google drive
1233
1234Via the @option{gdrive} method it is possible to access your Google
1235Drive online storage.  User and host name of the remote file name are
1236your email address of the Google Drive credentials, like
1237@file{@trampfn{gdrive,john.doe@@gmail.com,/}}.  These credentials must
1238be populated in your @command{Online Accounts} application outside Emacs.
1239
1240Since Google Drive uses cryptic blob file names internally,
1241@value{tramp} works with the @code{display-name} of the files.  This
1242could produce unexpected behavior in case two files in the same
1243directory have the same @code{display-name}, such a situation must be avoided.
1244
1245@item @option{nextcloud}
1246@cindex @acronym{GNOME} Online Accounts
1247@cindex method @option{nextcloud}
1248@cindex @option{nextcloud} method
1249@cindex nextcloud
1250
1251As the name indicates, the method @option{nextcloud} allows you to
1252access OwnCloud or NextCloud hosted files and directories.  Like the
1253@option{gdrive} method, your credentials must be populated in your
1254@command{Online Accounts} application outside Emacs. The method
1255supports port numbers.
1256
1257@item @option{sftp}
1258@cindex method @option{sftp}
1259@cindex @option{sftp} method
1260
1261This method uses @command{sftp} in order to securely access remote
1262hosts.  @command{sftp} is a more secure option for connecting to hosts
1263that for security reasons refuse @command{ssh} connections.
1264
1265@end table
1266
1267@defopt tramp-gvfs-methods
1268This user option is a list of external methods for @acronym{GVFS}@.
1269By default, this list includes @option{afp}, @option{dav},
1270@option{davs}, @option{gdrive}, @option{nextcloud} and @option{sftp}.
1271Other methods to include are @option{ftp}, @option{http},
1272@option{https} and @option{smb}.  These methods are not intended to be
1273used directly as @acronym{GVFS}-based method.  Instead, they are added
1274here for the benefit of @ref{Archive file names}.
1275
1276If you want to use @acronym{GVFS}-based @option{ftp} or @option{smb}
1277methods, you must add them to @code{tramp-gvfs-methods}, and you must
1278disable the corresponding Tramp package by setting
1279@code{tramp-ftp-method} or @code{tramp-smb-method} to @code{nil},
1280respectively:
1281
1282@lisp
1283@group
1284(add-to-list 'tramp-gvfs-methods "ftp")
1285(customize-set-variable 'tramp-ftp-method nil)
1286@end group
1287@end lisp
1288@end defopt
1289
1290
1291@node Default Method
1292@section Selecting a default method
1293@cindex default method
1294
1295In a remote file name, the use of a default method is indicated by the
1296pseudo method @option{-}, @ref{File name syntax}.
1297
1298@defopt tramp-default-method
1299Default method is for transferring files.  The user option
1300@code{tramp-default-method} sets it.  @value{tramp} uses this user
1301option to determine the default method for remote file names that do
1302not have one specified.
1303
1304@lisp
1305(customize-set-variable 'tramp-default-method "ssh")
1306@end lisp
1307@end defopt
1308
1309@defopt tramp-default-method-alist
1310Default methods for transferring files can be customized for specific
1311user and host combinations through the user option
1312@code{tramp-default-method-alist}.
1313
1314For example, the following two lines specify to use the @option{ssh}
1315method for all user names matching @samp{john} and the @option{rsync}
1316method for all host names matching @samp{lily}.  The third line
1317specifies to use the @option{su} method for the user @samp{root} on
1318the host @samp{localhost}.
1319
1320@lisp
1321@group
1322(add-to-list 'tramp-default-method-alist '("" "john" "ssh"))
1323(add-to-list 'tramp-default-method-alist '("lily" "" "rsync"))
1324(add-to-list 'tramp-default-method-alist
1325             '("\\`localhost\\'" "\\`root\\'" "su"))
1326@end group
1327@end lisp
1328@end defopt
1329
1330@noindent
1331External methods performance faster for large files.  @pxref{Inline
1332methods}.  @pxref{External methods}.
1333
1334Choosing the access method also depends on the security environment.
1335For example, @option{rsh} and @option{telnet} methods that use clear
1336text password transfers are inappropriate for over the Internet
1337connections.  Secure remote connections should use @option{ssh} that
1338provide encryption.
1339
1340
1341@subsection Which method to use?
1342@cindex choosing the right method
1343
1344@value{tramp} provides maximum number of choices for maximum
1345flexibility.  Choosing which method depends on the hosts, clients,
1346network speeds, and the security context.
1347
1348Start by using an inline method.
1349
1350External methods might be more efficient for large files, but most
1351@value{tramp} users edit small files more often than large files.
1352
1353Enable compression, @code{tramp-inline-compress-start-size}, for a
1354performance boost for large files.
1355
1356Since @command{ssh} has become the most common method of remote host
1357access and it has the most reasonable security protocols, use
1358@option{ssh} method.  Typical @option{ssh} usage to edit the
1359@file{/etc/motd} file on the otherhost:
1360
1361@example
1362@kbd{C-x C-f @trampfn{ssh,root@@otherhost,/etc/motd} @key{RET}}
1363@end example
1364
1365If @option{ssh} is unavailable for whatever reason, look for other
1366obvious options.  For MS Windows, try the @option{plink} method.  For
1367Kerberos, try @option{krlogin}.
1368
1369For editing local files as @option{su} or @option{sudo} methods, try
1370the shortened syntax of @samp{root}:
1371
1372@example
1373@kbd{C-x C-f @trampfn{su,,/etc/motd} @key{RET}}
1374@end example
1375
1376For editing large files, @option{scp} is faster than @option{ssh}.
1377@option{pscp} is faster than @option{plink}.  But this speed
1378improvement is not always true.
1379
1380
1381@node Default User
1382@section Selecting a default user
1383@cindex default user
1384
1385@defopt tramp-default-user
1386A @value{tramp} file name can omit the user name part since
1387@value{tramp} substitutes the currently logged-in user name.  However
1388this substitution can be overridden with @code{tramp-default-user}.
1389For example:
1390
1391@lisp
1392(customize-set-variable 'tramp-default-user "root")
1393@end lisp
1394@end defopt
1395
1396@defopt tramp-default-user-alist
1397Instead of a single default user, @code{tramp-default-user-alist}
1398allows multiple default user values based on access method or host
1399name combinations.  The alist can hold multiple values.  For example, to
1400use the @samp{john} as the default user for the domain
1401@samp{somewhere.else} only:
1402
1403@lisp
1404@group
1405(add-to-list 'tramp-default-user-alist
1406             '("ssh" ".*\\.somewhere\\.else\\'" "john"))
1407@end group
1408@end lisp
1409
1410A Caution: @value{tramp} will override any default user specified in
1411the configuration files outside Emacs, such as @file{~/.ssh/config}.
1412To stop @value{tramp} from applying the default value, set the
1413corresponding alist entry to @code{nil}:
1414
1415@lisp
1416@group
1417(add-to-list 'tramp-default-user-alist
1418             '("ssh" "\\`here\\.somewhere\\.else\\'" nil))
1419@end group
1420@end lisp
1421
1422The last entry in @code{tramp-default-user-alist} should be reserved
1423for catch-all or most often used login.
1424
1425@lisp
1426@group
1427(add-to-list 'tramp-default-user-alist
1428             '(nil nil "jonas") t)
1429@end group
1430@end lisp
1431@end defopt
1432
1433
1434@node Default Host
1435@section Selecting a default host
1436@cindex default host
1437
1438@defopt tramp-default-host
1439When host name is omitted, @value{tramp} substitutes the value from
1440the @code{tramp-default-host} user option.  It is initially
1441populated with the local host name where Emacs is running.  The
1442default method, default user and default host can be overridden as
1443follows:
1444
1445@lisp
1446@group
1447(custom-set-variables
1448 '(tramp-default-method "ssh")
1449 '(tramp-default-user "john")
1450 '(tramp-default-host "target"))
1451@end group
1452@end lisp
1453
1454With all defaults set, @samp{@trampfn{-,,}} will connect @value{tramp}
1455to John's home directory on @code{target} via @code{ssh}.
1456@end defopt
1457
1458@defopt tramp-default-host-alist
1459Instead of a single default host, @code{tramp-default-host-alist}
1460allows multiple default host values based on access method or user
1461name combinations.  The alist can hold multiple values.  While
1462@code{tramp-default-host} is sufficient in most cases, some methods,
1463like @option{adb}, require defaults overwritten.
1464@end defopt
1465
1466
1467@node Multi-hops
1468@section Connecting to a remote host using multiple hops
1469@cindex multi-hop
1470@cindex proxy hosts
1471
1472Multi-hops are methods to reach hosts behind firewalls or to reach the
1473outside world from inside a bastion host.  With multi-hops,
1474@value{tramp} can negotiate these hops with the appropriate user/host
1475authentication at each hop.  All methods until now have been the single
1476hop kind, where the start and end points of the connection did not
1477have intermediate check points.
1478
1479@defopt tramp-default-proxies-alist
1480@code{tramp-default-proxies-alist} specifies proxy hosts to pass
1481through.  This user option is list of triples consisting of
1482@code{(@var{host} @var{user} @var{proxy})}.
1483
1484The first match is the proxy host through which passes the file name
1485and the target host matching @var{user}@@@var{host}.  @var{host} and
1486@var{user} are regular expressions or @code{nil}, interpreted as a
1487regular expression which always matches.
1488
1489@var{proxy} is a literal @value{tramp} file name whose local name part
1490is ignored, and the method and user name parts are optional.
1491
1492The method must be an inline method (@pxref{Inline methods}).  If
1493@var{proxy} is @code{nil}, no additional hop is required reaching
1494@var{user}@@@var{host}.
1495
1496For example, to pass through the host @samp{bastion.your.domain} as
1497user @samp{bird} to reach remote hosts outside the local domain:
1498
1499@lisp
1500@group
1501(add-to-list 'tramp-default-proxies-alist
1502             '("\\." nil "@trampfn{ssh,bird@@bastion.your.domain,}"))
1503(add-to-list 'tramp-default-proxies-alist
1504             '("\\.your\\.domain\\'" nil nil))
1505@end group
1506@end lisp
1507
1508@strong{Note}: @code{add-to-list} adds elements at the beginning of a
1509list.  Therefore, most relevant rules must come last in the list.
1510
1511Proxy hosts can be cascaded in the alist.  If there is another host
1512called @samp{jump.your.domain}, which is the only host allowed to
1513connect to @samp{bastion.your.domain}, then:
1514
1515@lisp
1516@group
1517(add-to-list 'tramp-default-proxies-alist
1518             '("\\`bastion\\.your\\.domain\\'"
1519               "\\`bird\\'"
1520               "@trampfn{ssh,jump.your.domain,}"))
1521@end group
1522@end lisp
1523
1524@var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
1525@var{user} respectively.  Ports or domains, if they are part of
1526a hop file name, are not expanded by those patterns.
1527
1528To login as @samp{root} on remote hosts in the domain
1529@samp{your.domain}, but login as @samp{root} is disabled for non-local
1530access, then use this alist entry:
1531
1532@lisp
1533@group
1534(add-to-list 'tramp-default-proxies-alist
1535             '("\\.your\\.domain\\'" "\\`root\\'" "@trampfn{ssh,%h,}"))
1536@end group
1537@end lisp
1538
1539Opening @file{@trampfn{sudo,randomhost.your.domain,}} first connects
1540to @samp{randomhost.your.domain} via @code{ssh} under your account
1541name, and then performs @code{sudo -u root} on that host.
1542
1543It is key for the @option{sudo} method in the above example to be
1544applied on the host after reaching it and not on the local host.
1545@value{tramp} checks therefore, that the host name for such hops
1546matches the host name of the previous hop.
1547
1548@var{host}, @var{user} and @var{proxy} can also take Lisp forms.  These
1549forms when evaluated must return either a string or @code{nil}.
1550
1551To generalize (from the previous example): For all hosts, except my
1552local one, first connect via @command{ssh}, and then apply
1553@command{sudo -u root}:
1554
1555@lisp
1556@group
1557(add-to-list 'tramp-default-proxies-alist
1558             '(nil "\\`root\\'" "@trampfn{ssh,%h,}"))
1559(add-to-list 'tramp-default-proxies-alist
1560             '((regexp-quote (system-name)) nil nil))
1561@end group
1562@end lisp
1563@end defopt
1564
1565Passing through hops involves dealing with restricted shells, such as
1566@command{rbash}.  If @value{tramp} is made aware, then it would use
1567them for proxies only.
1568
1569@defopt tramp-restricted-shell-hosts-alist
1570An alist of regular expressions of hosts running restricted shells,
1571such as @command{rbash}.  @value{tramp} will then use them only as
1572proxies.
1573
1574To specify the bastion host from the example above as running a
1575restricted shell:
1576
1577@lisp
1578@group
1579(add-to-list 'tramp-restricted-shell-hosts-alist
1580             "\\`bastion\\.your\\.domain\\'")
1581@end group
1582@end lisp
1583@end defopt
1584
1585
1586@node Firewalls
1587@section Passing firewalls
1588@cindex http tunnel
1589@cindex proxy hosts, http tunnel
1590
1591Sometimes, it is not possible to reach a remote host directly.  A
1592firewall might be in the way, which could be passed via a proxy
1593server.
1594
1595Both ssh and PuTTY support such proxy settings, using an HTTP tunnel
1596via the @command{CONNECT} command (conforming to RFC 2616, 2817
1597specifications).  Proxy servers using HTTP 1.1 or later protocol
1598support this command.
1599
1600
1601@subsection Tunneling with ssh
1602
1603With ssh, you could use the @code{ProxyCommand} entry in
1604@file{~/.ssh/config}:
1605
1606@example
1607@group
1608Host host.other.domain
1609     ProxyCommand nc -X connect -x proxy.your.domain:3128 %h %p
1610@end group
1611@end example
1612
1613@code{nc} is BSD's netcat program, which establishes HTTP tunnels.
1614Any other program with such a feature could be used as well.
1615
1616In the example, opening @file{@trampfn{ssh,host.your.domain,}} passes
1617the HTTP proxy server @samp{proxy.your.domain} on port 3128.
1618
1619
1620@subsection Tunneling with PuTTY
1621
1622PuTTY does not need an external program, HTTP tunnel support is
1623built-in.  In the PuTTY config program, create a session for
1624@samp{host.your.domain}.  In the @option{Connection/Data} entry,
1625select the @option{HTTP} option, and add @samp{proxy.your.domain} as
1626@option{Proxy hostname}, and 3128 as @option{Port}.
1627
1628Opening @file{@trampfn{plinkx,host.your.domain,}} passes the HTTP
1629proxy server @samp{proxy.your.domain} on port 3128.
1630
1631
1632@node Customizing Methods
1633@section Using Non-Standard Methods
1634@cindex customizing methods
1635@cindex using non-standard methods
1636@cindex create your own methods
1637
1638@vindex tramp-methods
1639The @code{tramp-methods} variable currently has an exhaustive list of
1640predefined methods.  Any part of this list can be modified with more
1641suitable settings.  Refer to the Lisp documentation of that variable,
1642accessible with @kbd{C-h v tramp-methods @key{RET}}.
1643
1644In the ELPA archives, there are several examples of such extensions.
1645They can be installed with Emacs' Package Manager.  This includes
1646
1647@table @samp
1648@c @item anything-tramp
1649@c @item counsel-tramp
1650@c @item helm-tramp
1651@c Contact Masashí Míyaura <masasam@users.noreply.github.com>
1652
1653@c @item ibuffer-tramp.el
1654@c Contact Svend Sorensen <svend@@ciffer.net>
1655
1656@item docker-tramp
1657@cindex method @option{docker}
1658@cindex @option{docker} method
1659Integration for Docker containers.  A container is accessed via
1660@file{@trampfn{docker,user@@container,/path/to/file}}, where
1661@samp{user} is the (optional) user that you want to use, and
1662@samp{container} is the id or name of the container.
1663
1664@item kubernetes-tramp
1665@cindex method @option{kubectl}
1666@cindex @option{kubectl} method
1667Integration for Docker containers deployed in a Kubernetes cluster.
1668It is derived from @samp{docker-tramp}.  A container is accessed via
1669@file{@trampfn{kubectl,user@@container,/path/to/file}}, @samp{user}
1670and @samp{container} have the same meaning as in @samp{docker-tramp}.
1671
1672@item lxc-tramp
1673@cindex method @option{lxc}
1674@cindex @option{lxc} method
1675Integration for LXC containers.  A container is accessed via
1676@file{@trampfn{lxc,container,/path/to/file}}, @samp{container} has the
1677same meaning as in @samp{docker-tramp}.  A @samp{user} specification
1678is ignored.
1679
1680@item lxd-tramp
1681@cindex method @option{lxd}
1682@cindex @option{lxd} method
1683Integration for LXD containers.  A container is accessed via
1684@file{@trampfn{lxd,user@@container,/path/to/file}}, @samp{user} and
1685@samp{container} have the same meaning as in @samp{docker-tramp}.
1686
1687@item magit-tramp
1688@cindex method @option{git}
1689@cindex @option{git} method
1690Browsing Git repositories with @code{magit}.  A versioned file is
1691accessed via @file{@trampfn{git,rev@@root-dir,/path/to/file}}.
1692@samp{rev} is a Git revision, and @samp{root-dir} is a virtual host
1693name for the root directory, specified in
1694@code{magit-tramp-hosts-alist}.
1695
1696@item tramp-hdfs
1697@cindex method @option{hdfs}
1698@cindex @option{hdfs} method
1699Access of a hadoop/hdfs file system.  A file is accessed via
1700@file{@trampfn{hdfs,user@@node,/path/to/file}}, where @samp{user} is
1701the user that you want to use, and @samp{node} is the name of the
1702hadoop server.
1703
1704@item vagrant-tramp
1705@cindex method @option{vagrant}
1706@cindex @option{vagrant} method
1707Convenience method to access vagrant boxes.  It is often used in
1708multi-hop file names like
1709@file{@value{prefix}vagrant@value{postfixhop}box|sudo@value{postfixhop}box@value{postfix}/path/to/file},
1710where @samp{box} is the name of the vagrant box.
1711@end table
1712
1713
1714@node Customizing Completion
1715@section Selecting config files for user/host name completion
1716@cindex customizing completion
1717@cindex selecting config files
1718
1719@vindex tramp-completion-function-alist
1720@code{tramp-completion-function-alist} uses predefined files for user
1721and host name completion (@pxref{File name completion}).  For each
1722method, it keeps a set of configuration files and a function that can
1723parse that file.  Each entry in @code{tramp-completion-function-alist}
1724is of the form (@var{method} @var{pair1} @var{pair2} @dots{}).
1725
1726Each @var{pair} is composed of (@var{function} @var{file}).
1727@var{function} is responsible for extracting user names and host names
1728from @var{file} for completion.  There are two functions which access
1729this variable:
1730
1731@defun tramp-get-completion-function method
1732This function returns the list of completion functions for @var{method}.
1733
1734Example:
1735@example
1736@group
1737(tramp-get-completion-function "rsh")
1738
1739     @result{} ((tramp-parse-rhosts "/etc/hosts.equiv")
1740         (tramp-parse-rhosts "~/.rhosts"))
1741@end group
1742@end example
1743@end defun
1744
1745@defun tramp-set-completion-function method function-list
1746This function sets @var{function-list} as list of completion functions
1747for @var{method}.
1748
1749Example:
1750@example
1751@group
1752(tramp-set-completion-function "ssh"
1753 '((tramp-parse-sconfig "/etc/ssh_config")
1754   (tramp-parse-sconfig "~/.ssh/config")))
1755
1756     @result{} ((tramp-parse-sconfig "/etc/ssh_config")
1757         (tramp-parse-sconfig "~/.ssh/config"))
1758@end group
1759@end example
1760@end defun
1761
1762The following predefined functions parsing configuration files exist:
1763
1764@table @asis
1765@item @code{tramp-parse-rhosts}
1766@findex tramp-parse-rhosts
1767
1768This function parses files which are syntactical equivalent to
1769@file{~/.rhosts}.  It returns both host names and user names, if
1770specified.
1771
1772@item @code{tramp-parse-shosts}
1773@findex tramp-parse-shosts
1774
1775This function parses files which are syntactical equivalent to
1776@file{~/.ssh/known_hosts}.  Since there are no user names specified
1777in such files, it can return host names only.
1778
1779@item @code{tramp-parse-sconfig}
1780@findex tramp-parse-sconfig
1781
1782This function returns the host nicknames defined by @code{Host} entries
1783in @file{~/.ssh/config} style files.
1784
1785@item @code{tramp-parse-shostkeys}
1786@findex tramp-parse-shostkeys
1787
1788SSH2 parsing of directories @file{/etc/ssh2/hostkeys/*} and
1789@file{~/ssh2/hostkeys/*}.  Hosts are coded in file names
1790@file{hostkey_@var{portnumber}_@var{host-name}.pub}.  User names
1791are always @code{nil}.
1792
1793@item @code{tramp-parse-sknownhosts}
1794@findex tramp-parse-sknownhosts
1795
1796Another SSH2 style parsing of directories like
1797@file{/etc/ssh2/knownhosts/*} and @file{~/ssh2/knownhosts/*}.  This
1798case, hosts names are coded in file names
1799@file{@var{host-name}.@var{algorithm}.pub}.  User names are always @code{nil}.
1800
1801@item @code{tramp-parse-hosts}
1802@findex tramp-parse-hosts
1803
1804A function dedicated to @file{/etc/hosts} for host names.
1805
1806@item @code{tramp-parse-passwd}
1807@findex tramp-parse-passwd
1808
1809A function which parses @file{/etc/passwd} for user names.
1810
1811@item @code{tramp-parse-etc-group}
1812@findex tramp-parse-etc-group
1813
1814A function which parses @file{/etc/group} for group names.
1815
1816@item @code{tramp-parse-netrc}
1817@findex tramp-parse-netrc
1818
1819A function which parses @file{~/.netrc} and @file{~/.authinfo}-style files.
1820
1821@end table
1822
1823To keep a custom file with custom data in a custom structure, a custom
1824function has to be provided.  This function must meet the following
1825conventions:
1826
1827@defun my-tramp-parse file
1828@var{file} must be either a file on the host, or @code{nil}.  The
1829function must return a list of (@var{user} @var{host}), which are
1830taken as candidates for completion for user and host names.
1831
1832Example:
1833@example
1834@group
1835(my-tramp-parse "~/.my-tramp-hosts")
1836
1837     @result{} ((nil "toto") ("daniel" "melancholia"))
1838@end group
1839@end example
1840@end defun
1841
1842
1843@node Password handling
1844@section Reusing passwords for several connections
1845@cindex passwords
1846
1847To avoid repeated prompts for passwords, consider native caching
1848mechanisms, such as @command{ssh-agent} for @option{ssh}-like
1849methods, or @command{pageant} for @option{plink}-like methods.
1850
1851@value{tramp} offers alternatives when native solutions cannot meet
1852the need.
1853
1854
1855@anchor{Using an authentication file}
1856@subsection Using an authentication file
1857
1858@vindex auth-sources
1859The package @file{auth-source.el}, originally developed for No Gnus,
1860reads passwords from different sources, @xref{Help for users, ,
1861auth-source, auth}.  The default authentication file is
1862@file{~/.authinfo.gpg}, but this can be changed via the user option
1863@code{auth-sources}.
1864
1865@noindent
1866A typical entry in the authentication file:
1867
1868@example
1869machine melancholia port scp login daniel password geheim
1870@end example
1871
1872The port can take any @value{tramp} method (@pxref{Inline methods},
1873@pxref{External methods}).  Omitting port values matches all
1874@value{tramp} methods.  Domain and ports, as used in @value{tramp}
1875file name syntax, must be appended to the machine and login items:
1876
1877@example
1878machine melancholia#4711 port davs login daniel%BIZARRE password geheim
1879@end example
1880
1881@vindex auth-source-save-behavior
1882If there doesn't exist a proper entry, the password is read
1883interactively.  After successful login (verification of the password),
1884it is offered to save a corresponding entry for further use by
1885@code{auth-source} backends which support this.  This could be changed
1886by setting the user option @code{auth-source-save-behavior} to @code{nil}.
1887
1888@vindex auth-source-debug
1889Set @code{auth-source-debug} to @code{t} to debug messages.
1890
1891@vindex ange-ftp-netrc-filename
1892@strong{Note} that @file{auth-source.el} is not used for @option{ftp}
1893connections, because @value{tramp} passes the work to Ange FTP@.  If
1894you want, for example, use your @file{~/.authinfo.gpg} authentication
1895file, you must customize @code{ange-ftp-netrc-filename}:
1896
1897@lisp
1898(customize-set-variable 'ange-ftp-netrc-filename "~/.authinfo.gpg")
1899@end lisp
1900
1901
1902@anchor{Caching passwords}
1903@subsection Caching passwords
1904
1905@value{tramp} can cache passwords as entered and reuse when needed for
1906the same user or host name independent of the access method.
1907
1908@vindex password-cache-expiry
1909@code{password-cache-expiry} sets the duration (in seconds) the
1910passwords are remembered.  Passwords are never saved permanently nor
1911can they extend beyond the lifetime of the current Emacs session.  Set
1912@code{password-cache-expiry} to @code{nil} to disable expiration.
1913
1914@vindex password-cache
1915Set @code{password-cache} to @code{nil} to disable password caching.
1916
1917
1918@node Connection caching
1919@section Reusing connection related information
1920@cindex caching
1921
1922@vindex tramp-persistency-file-name
1923For faster initial connection times, @value{tramp} stores previous
1924connection properties in a file specified by the user option
1925@code{tramp-persistency-file-name}.
1926
1927The default file name for @code{tramp-persistency-file-name} is
1928@file{~/.emacs.d/tramp}.
1929
1930@value{tramp} reads this file during Emacs startup, and writes to it
1931when exiting Emacs.  Delete this file for @value{tramp} to recreate a
1932new one on next Emacs startup.
1933
1934Set @code{tramp-persistency-file-name} to @code{nil} to disable
1935storing connections persistently.
1936
1937When @value{tramp} detects a change in the operating system version in
1938a remote host (via the command @command{uname -sr}), it flushes all
1939connection related information for that host and creates a new entry.
1940
1941
1942@node Predefined connection information
1943@section Setting own connection related information
1944
1945For more precise customization, parameters specified by
1946@code{tramp-methods} can be overwritten manually.
1947
1948@vindex tramp-connection-properties
1949Set @code{tramp-connection-properties} to manually override
1950@code{tramp-methods}.  Properties in this list are in the form
1951@code{(@var{regexp} @var{property} @var{value})}.  @var{regexp}
1952matches remote file names.  Use @code{nil} to match all.
1953@var{property} is the property's name, and @var{value} is the
1954property's value.
1955
1956@var{property} is any method specific parameter contained in
1957@code{tramp-methods}.  The parameter key in @code{tramp-methods} is a
1958symbol name @code{tramp-<foo>}.  To overwrite that property, use the
1959string @t{"<foo>"} for @var{property}.  For example, this changes the
1960remote shell:
1961
1962@lisp
1963@group
1964(add-to-list 'tramp-connection-properties
1965             (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1966                   "remote-shell" "/bin/ksh"))
1967@end group
1968
1969@group
1970(add-to-list 'tramp-connection-properties
1971             (list (regexp-quote "@trampfn{ssh,user@@randomhost.your.domain,}")
1972                   "remote-shell-login" '("-")))
1973@end group
1974@end lisp
1975
1976The parameters @code{tramp-remote-shell} and
1977@code{tramp-remote-shell-login} in @code{tramp-methods} now have new
1978values for the remote host.
1979
1980@var{property} could also be any property found in
1981@code{tramp-persistency-file-name}.
1982
1983
1984@subsection Relevant connection properties to override
1985
1986Not all connection properties need to be changed.  The most relevant
1987properties are listed here:
1988
1989@itemize
1990@item @t{"login-program"}
1991
1992The property @t{"login-program"} keeps the program to be called in
1993order to connect the remote host.  Sometimes, the program might have
1994another name on your host, or it is located on another path.  In this
1995case, you can overwrite the default value, which is special for every
1996connection method.  It is used in all connection methods of
1997@file{tramp-sh.el}.
1998
1999@item @t{"login-args"}
2000
2001@t{"login-args"} specifies a list of lists of arguments to pass to
2002@t{"login-program"}.  Read the docstring of @code{tramp-methods} how
2003to construct these lists.
2004
2005@item @t{"remote-shell"}
2006
2007This property tells Tramp which remote shell to apply on the remote
2008host.  It is used in all connection methods of @file{tramp-sh.el}.
2009The default value is @t{"/bin/sh"}.
2010
2011@item @t{"remote-shell-login"}
2012
2013A property to be used in conjunction with @t{"remote-shell"}.  It
2014specifies, which shell argument triggers a login shell.  Its default
2015value is @t{"-l"}, but some shells, like @command{ksh}, prefer
2016@t{"-"}.
2017
2018@item @t{"session-timeout"}
2019
2020All @file{tramp-sh.el} based methods accept the property
2021@t{"session-timeout"}.  This is the time (in seconds) after a
2022connection is disabled for security reasons, and must be
2023reestablished.  A value of @code{nil} disables this feature.  Most of
2024the methods do not set this property except the @option{sudo} and
2025@option{doas} methods, which use predefined values.
2026
2027@item @t{"tmpdir"}
2028
2029The temporary directory on the remote host.  If not specified, the
2030default value is @t{"/data/local/tmp"} for the @option{adb} method,
2031@t{"/C$/Temp"} for the @option{smb} method, and @t{"/tmp"} otherwise.
2032
2033@item @t{"posix"}
2034
2035Connections using the @option{smb} method check, whether the remote
2036host supports posix commands.  If the remote host runs Samba, it
2037confirms this capability.  However, some very old Samba versions have
2038errors in their implementation.  In order to suppress the posix
2039commands for those hosts, the property @t{"posix"} shall be set to
2040@code{nil}.
2041
2042The default value of this property is @code{t} (not specified in
2043@code{tramp-methods}).  If the remote host runs native MS Windows,
2044there is no effect of this property.
2045
2046@item @t{"mount-args"}@*
2047@t{"copyto-args"}@*
2048@t{"moveto-args"}
2049
2050These properties keep optional flags to the different @option{rclone}
2051operations.  Their default value is @code{nil}.
2052@end itemize
2053
2054
2055@node Remote programs
2056@section How @value{tramp} finds and uses programs on the remote host
2057
2058@value{tramp} requires access to and rights to several commands on
2059remote hosts: @command{ls}, @command{test}, @command{find} and
2060@command{cat}.
2061
2062Besides there are other required programs for @ref{Inline methods} and
2063@ref{External methods} of connection.
2064
2065To improve performance and accuracy of remote file access,
2066@value{tramp} uses @command{perl} (or @command{perl5}) and
2067@command{grep} when available.
2068
2069@defopt tramp-remote-path
2070@code{tramp-remote-path} specifies which remote directory paths
2071@value{tramp} can search for @ref{Remote programs}.
2072
2073@vindex tramp-default-remote-path
2074@value{tramp} uses standard defaults, such as @file{/bin} and
2075@file{/usr/bin}, which are reasonable for most hosts.  To accommodate
2076differences in hosts and paths, for example, @file{/bin:/usr/bin} on
2077Debian GNU/Linux or
2078@file{/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin} on
2079Solaris, @value{tramp} queries the remote host with @command{getconf
2080PATH} and updates the symbol @code{tramp-default-remote-path}.
2081
2082For instances where hosts keep obscure locations for paths for
2083security reasons, manually add such paths to local @file{.emacs} as
2084shown below for @value{tramp} to use when connecting.
2085
2086@lisp
2087(add-to-list 'tramp-remote-path "/usr/local/perl/bin")
2088@end lisp
2089
2090@vindex tramp-own-remote-path
2091Another way to find the remote path is to use the path assigned to the
2092remote user by the remote host.  @value{tramp} does not normally retain
2093this remote path after login.  However, @code{tramp-own-remote-path}
2094preserves the path value, which can be used to update
2095@code{tramp-remote-path}.
2096
2097@lisp
2098(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
2099@end lisp
2100
2101@strong{Note} that this works only if your remote @command{/bin/sh}
2102shell supports the login argument @samp{-l}.
2103@end defopt
2104
2105Starting with Emacs 26, @code{tramp-remote-path} can be set per host
2106via connection-local
2107@ifinfo
2108variables, @xref{Connection Variables, , , emacs}.
2109@end ifinfo
2110@ifnotinfo
2111variables.
2112@end ifnotinfo
2113You could define your own search directories like this:
2114
2115@lisp
2116@group
2117(connection-local-set-profile-variables 'remote-path-with-bin
2118   '((tramp-remote-path . ("~/bin" tramp-default-remote-path))))
2119@end group
2120
2121@group
2122(connection-local-set-profile-variables 'remote-path-with-apply-pub-bin
2123   '((tramp-remote-path . ("/appli/pub/bin" tramp-default-remote-path))))
2124@end group
2125
2126@group
2127(connection-local-set-profiles
2128   '(:application tramp :machine "randomhost") 'remote-path-with-bin)
2129@end group
2130
2131@group
2132(connection-local-set-profiles
2133   '(:application tramp :user "anotheruser" :machine "anotherhost")
2134     'remote-path-with-apply-pub-bin)
2135@end group
2136@end lisp
2137
2138When remote search paths are changed, local @value{tramp} caches must
2139be recomputed.  To force @value{tramp} to recompute afresh, call
2140@kbd{M-x tramp-cleanup-this-connection @key{RET}} or friends
2141(@pxref{Cleanup remote connections}).
2142
2143
2144@node Remote shell setup
2145@section Remote shell setup hints
2146
2147
2148@subsection Changing the default remote or local shell
2149@cindex zsh setup
2150
2151Per default, @value{tramp} uses the command @command{/bin/sh} for
2152starting a shell on the remote host.  This can be changed by setting
2153the connection property @t{"remote-shell"}, see @ref{Predefined
2154connection information}.  If you want, for example, use
2155@command{/usr/bin/zsh} on a remote host, you might apply
2156
2157@lisp
2158@group
2159(add-to-list 'tramp-connection-properties
2160             (list (regexp-quote "@trampfn{ssh,user@@host,}")
2161                   "remote-shell" "/usr/bin/zsh"))
2162@end group
2163@end lisp
2164
2165This works only for connection methods which allow to override the
2166remote login shell, like @option{sshx} or @option{plink}.  See
2167@ref{Inline methods} and @ref{External methods} for connection methods
2168which support this.
2169
2170@vindex tramp-sh-extra-args
2171This approach has also the advantage, that settings in
2172@code{tramp-sh-extra-args} will be applied.  For @command{zsh}, the
2173trouble with the shell prompt due to set zle options will be avoided.
2174
2175Similar problems can happen with the local shell Tramp uses to create
2176a process.  Per default, it uses the command @command{/bin/sh} for
2177this, which could also be a link to another shell.  In order to
2178overwrite this, you might apply
2179
2180@vindex tramp-encoding-shell
2181@lisp
2182(customize-set-variable 'tramp-encoding-shell "/usr/bin/zsh")
2183@end lisp
2184
2185This uses also the settings in @code{tramp-sh-extra-args}.
2186
2187
2188@subsection Other remote shell setup hints
2189@cindex remote shell setup
2190@cindex @file{.profile} file
2191@cindex @file{.login} file
2192@cindex shell init files
2193
2194@value{tramp} checks for the availability of standard programs in the
2195usual locations.  Common tactics include successively trying
2196@command{test -e}, @command{/usr/bin/test -e}, and @command{/bin/test
2197-e}.  @command{ls -d} is another approach.  But these approaches do not
2198help with these new login patterns.
2199
2200When @value{tramp} encounters two-factor logins or additional challenge
2201questions, such as entering birth date or security code or passphrase,
2202@value{tramp} needs a few more configuration steps to accommodate
2203them.
2204
2205The difference between a password prompt and a passphrase prompt is
2206that the password for completing the login while the passphrase is
2207for authorizing access to local authentication information, such as
2208the ssh key.
2209
2210There is no one configuration to accommodate all the variations in
2211login security, especially not the exotic ones.  However, @value{tramp}
2212provides a few tweaks to address the most common ones.
2213
2214@table @asis
2215@item @code{tramp-shell-prompt-pattern}
2216@vindex tramp-shell-prompt-pattern
2217
2218@code{tramp-shell-prompt-pattern} is for remote login shell prompt,
2219which may not be the same as the local login shell prompt,
2220@code{shell-prompt-pattern}.  Since most hosts use identical prompts,
2221@value{tramp} sets a similar default value for both prompts.
2222
2223@item @code{tramp-password-prompt-regexp}
2224@item @code{tramp-wrong-passwd-regexp}
2225@vindex tramp-password-prompt-regexp
2226@vindex tramp-wrong-passwd-regexp
2227
2228@value{tramp} uses @code{tramp-password-prompt-regexp} to
2229distinguish between prompts for passwords and prompts for passphrases.
2230By default, @code{tramp-password-prompt-regexp} handles the
2231detection in English language environments.  See a localization
2232example below:
2233
2234@lisp
2235@group
2236(customize-set-variable
2237 'tramp-password-prompt-regexp
2238  (concat
2239   "^.*"
2240   (regexp-opt
2241    '("passphrase" "Passphrase"
2242      ;; English
2243      "password" "Password"
2244      ;; Deutsch
2245      "passwort" "Passwort"
2246      ;; Français
2247      "mot de passe" "Mot de passe")
2248    t)
2249   ".*:\0? *"))
2250@end group
2251@end lisp
2252
2253Similar localization may be necessary for handling wrong password
2254prompts, for which @value{tramp} uses @code{tramp-wrong-passwd-regexp}.
2255
2256@item @code{tramp-terminal-type}
2257@vindex tramp-terminal-type
2258@vindex TERM@r{, environment variable}
2259
2260@value{tramp} uses the user option @code{tramp-terminal-type} to set
2261the remote environment variable @env{TERM} for the shells it runs.
2262Per default, it is @t{"dumb"}, but this could be changed.  A dumb
2263terminal is best suited to run the background sessions of
2264@value{tramp}.  However, running interactive remote shells might
2265require a different setting.  This could be achieved by tweaking the
2266@env{TERM} environment variable in @code{process-environment}.
2267
2268@lisp
2269@group
2270(let ((process-environment
2271       (cons "TERM=xterm-256color" process-environment)))
2272  (shell))
2273@end group
2274@end lisp
2275
2276@item Determining a @value{tramp} session
2277@vindex TERM@r{, environment variable}
2278@vindex INSIDE_EMACS@r{, environment variable}
2279
2280Sometimes, it is needed to identify whether a shell runs under
2281@value{tramp} control.  The setting of environment variable @env{TERM}
2282will help:
2283
2284@example
2285@group
2286if test "$TERM" = "dumb"; then
2287   ...
2288fi
2289@end group
2290@end example
2291
2292Another possibility is to check the environment variable
2293@env{INSIDE_EMACS}.  Like for all subprocesses of Emacs, this is set
2294to the version of the parent Emacs process, @xref{Interactive Shell, ,
2295, emacs}.  @value{tramp} adds its own package version to this string,
2296which could be used for further tests in an inferior shell.  The
2297string of that environment variable looks always like
2298
2299@example
2300@group
2301echo $INSIDE_EMACS
2302@result{} 27.2,tramp:2.4.5
2303@end group
2304@end example
2305
2306@item @command{tset} and other questions
2307@cindex unix command @command{tset}
2308@cindex @command{tset} unix command
2309
2310To suppress inappropriate prompts for terminal type, @value{tramp}
2311sets the @env{TERM} environment variable before the remote login
2312process begins via the user option @code{tramp-terminal-type} (see
2313above).  This will silence common @command{tset} related prompts.
2314
2315@value{tramp}'s strategy for handling such prompts (commonly triggered
2316from login scripts on remote hosts) is to set the environment
2317variables so that no prompts interrupt the shell initialization
2318process.
2319
2320@vindex tramp-actions-before-shell
2321An alternative approach is to configure @value{tramp} with strings
2322that can identify such questions using
2323@code{tramp-actions-before-shell}.  Example:
2324
2325@lisp
2326@group
2327(defconst my-tramp-prompt-regexp
2328  (concat (regexp-opt '("Enter the birth date of your mother:") t)
2329          "\\s-*")
2330  "Regular expression matching my login prompt question.")
2331@end group
2332
2333@group
2334(defun my-tramp-action (proc vec)
2335  "Enter \"19000101\" in order to give a correct answer."
2336  (save-window-excursion
2337    (with-current-buffer (tramp-get-connection-buffer vec)
2338      (tramp-message vec 6 "\n%s" (buffer-string))
2339      (tramp-send-string vec "19000101"))))
2340@end group
2341
2342@group
2343(add-to-list 'tramp-actions-before-shell
2344             '(my-tramp-prompt-regexp my-tramp-action))
2345@end group
2346@end lisp
2347
2348
2349@item Conflicting names for users and variables in @file{.profile}
2350
2351When a user name is the same as a variable name in a local file, such
2352as @file{.profile}, then @value{tramp} may send incorrect values for
2353environment variables.  To avoid incorrect values, change the local
2354variable name to something different from the user name.  For example,
2355if the user name is @env{FRUMPLE}, then change the variable name to
2356@env{FRUMPLE_DIR}.
2357
2358
2359@item Non-Bourne commands in @file{.profile}
2360
2361When the remote host's @file{.profile} is also used for shells other
2362than Bourne shell, then some incompatible syntaxes for commands in
2363@file{.profile} may trigger errors in Bourne shell on the host and may
2364not complete client's @value{tramp} connections.
2365
2366One example of a Bourne shell incompatible syntax in @file{.profile}:
2367using @command{export FOO=bar} instead of @command{FOO=bar; export
2368FOO}.  After remote login, @value{tramp} will trigger an error during
2369its execution of @command{/bin/sh} on the remote host because Bourne
2370shell does not recognize the export command as entered in
2371@file{.profile}.
2372
2373Likewise, (@code{~}) character in paths will cause errors because
2374Bourne shell does not do (@code{~}) character expansions.
2375
2376One approach to avoiding these incompatibilities is to make all
2377commands in @file{~/.shrc} and @file{~/.profile} Bourne shell
2378compatible so @value{tramp} can complete connections to that remote.
2379To accommodate using non-Bourne shells on that remote, use other
2380shell-specific config files.  For example, bash can use
2381@file{~/.bash_profile} and ignore @file{.profile}.
2382
2383
2384@item Interactive shell prompt
2385
2386@vindex INSIDE_EMACS@r{, environment variable}
2387@vindex SHELLNAME@r{, environment variable}
2388@vindex ESHELL@r{, environment variable}
2389@value{tramp} redefines the remote shell prompt internally for robust
2390parsing.  This redefinition affects the looks of a prompt in an
2391interactive remote shell through commands, such as @kbd{M-x shell
2392@key{RET}}.  Such prompts, however, can be reset to something more
2393readable and recognizable using these environment variables.
2394
2395@value{tramp} sets the @env{INSIDE_EMACS} environment variable in the
2396startup script file @file{~/.emacs_SHELLNAME}.
2397
2398@env{SHELLNAME} is @code{bash} or equivalent shell names.  Change it by
2399setting the environment variable @env{ESHELL} in the @file{.emacs} as
2400follows:
2401
2402@lisp
2403(setenv "ESHELL" "bash")
2404@end lisp
2405
2406Then re-set the prompt string in @file{~/.emacs_SHELLNAME} as follows:
2407
2408@example
2409@group
2410# Reset the prompt for remote @value{tramp} shells.
2411if [ "$@{INSIDE_EMACS/*tramp*/tramp@}" == "tramp" ] ; then
2412   PS1="[\u@@\h \w]$ "
2413fi
2414@end group
2415@end example
2416
2417@ifinfo
2418@xref{Interactive Shell, , , emacs}.
2419@end ifinfo
2420
2421@item @command{busybox} / @command{nc}
2422@cindex unix command @command{nc}
2423@cindex @command{nc} unix command
2424
2425@value{tramp}'s @option{nc} method uses the @command{nc} command to
2426install and execute a listener as follows (see @code{tramp-methods}):
2427
2428@example
2429$ nc -l -p 42
2430@end example
2431
2432The above command-line syntax has changed with @command{busybox}
2433versions.  If @command{nc} refuses the @samp{-p} parameter, then
2434overwrite as follows:
2435
2436@lisp
2437@group
2438(add-to-list
2439 'tramp-connection-properties
2440 `(,(regexp-quote "192.168.0.1")
2441   "remote-copy-args" (("-l") ("%r"))))
2442@end group
2443@end lisp
2444
2445@noindent
2446where @samp{192.168.0.1} is the remote host IP address
2447(@pxref{Predefined connection information}).
2448
2449@end table
2450
2451
2452@node Android shell setup
2453@section Android shell setup hints
2454@cindex android shell setup for ssh
2455
2456@value{tramp} uses the @option{adb} method to access Android devices.
2457Android devices provide a restricted shell access through an USB
2458connection.  The local host must have the @command{adb} program
2459installed.  Usually, it is sufficient to open the file
2460@file{@trampfn{adb,,/}}.  Then you can navigate in the filesystem via
2461@code{dired}.
2462
2463Alternatively, applications such as @code{Termux} or @code{SSHDroid}
2464that run @command{sshd} process on the Android device can accept any
2465@option{ssh}-based methods provided these settings are adjusted:
2466
2467@itemize
2468@item
2469@command{sh} must be specified for remote shell since Android devices
2470do not provide @command{/bin/sh}.  @command{sh} will then invoke
2471whatever shell is installed on the device with this setting:
2472
2473@lisp
2474@group
2475(add-to-list 'tramp-connection-properties
2476	     (list (regexp-quote "192.168.0.26") "remote-shell" "sh"))
2477@end group
2478@end lisp
2479
2480@noindent
2481where @samp{192.168.0.26} is the Android device's IP address.
2482(@pxref{Predefined connection information}).
2483
2484@item
2485@value{tramp} requires preserving @env{PATH} environment variable from
2486user settings.  Android devices prefer @file{/system/xbin} path over
2487@file{/system/bin}.  Both of these are set as follows:
2488
2489@lisp
2490@group
2491(add-to-list 'tramp-remote-path 'tramp-own-remote-path)
2492(add-to-list 'tramp-remote-path "/system/xbin")
2493@end group
2494@end lisp
2495
2496@item
2497When the Android device is not @samp{rooted}, specify a writable
2498directory for temporary files:
2499
2500@lisp
2501(add-to-list 'tramp-remote-process-environment "TMPDIR=$HOME")
2502@end lisp
2503
2504@item
2505Open a remote connection with the command @kbd{C-x C-f
2506@trampfn{ssh,192.168.0.26#2222,} @key{RET}}, where @command{sshd} is
2507listening on port @samp{2222}.
2508
2509To add a corresponding entry to the @file{~/.ssh/config} file
2510(recommended), use this:
2511
2512@example
2513@group
2514Host android
2515     HostName 192.168.0.26
2516     User root
2517     Port 2222
2518@end group
2519@end example
2520
2521@noindent
2522To use the host name @samp{android} instead of the IP address shown in
2523the previous example, fix the connection properties as follows:
2524
2525@lisp
2526@group
2527(add-to-list 'tramp-connection-properties
2528	     (list (regexp-quote "android") "remote-shell" "sh"))
2529@end group
2530@end lisp
2531
2532@noindent
2533Open a remote connection with a more concise command @kbd{C-x C-f
2534@trampfn{ssh,android,} @key{RET}}.
2535@end itemize
2536
2537
2538@node Auto-save and Backup
2539@section Auto-save and Backup configuration
2540@cindex auto-save
2541@cindex backup
2542
2543@vindex backup-directory-alist
2544To avoid @value{tramp} from saving backup files owned by @samp{root}
2545to locations accessible to others, default backup settings in
2546@code{backup-directory-alist} have to be altered.
2547
2548Here's a scenario where files could be inadvertently exposed.  Emacs
2549by default writes backup files to the same directory as the original
2550files unless changed to another location, such as
2551@file{~/.emacs.d/backups/}.  Such a directory will also be used by
2552default by @value{tramp} when using, say, a restricted file
2553@file{@trampfn{su,root@@localhost,/etc/secretfile}}.  The backup file
2554of the secretfile is now owned by the user logged in from
2555@value{tramp} and not @samp{root}.
2556
2557When @code{backup-directory-alist} is @code{nil} (the default), such
2558problems do not occur.
2559
2560To ``turn off'' the backup feature for remote files and stop
2561@value{tramp} from saving to the backup directory, use this:
2562
2563@lisp
2564@group
2565(add-to-list 'backup-directory-alist
2566             (cons tramp-file-name-regexp nil))
2567@end group
2568@end lisp
2569
2570@noindent
2571Disabling backups can be targeted to just the @option{su} and
2572@option{sudo} methods:
2573
2574@lisp
2575@group
2576(setq backup-enable-predicate
2577      (lambda (name)
2578        (and (normal-backup-enable-predicate name)
2579             (not
2580              (let ((method (file-remote-p name 'method)))
2581                (when (stringp method)
2582                  (member method '("su" "sudo"))))))))
2583@end group
2584@end lisp
2585
2586@vindex tramp-backup-directory-alist
2587Another option is to create better backup file naming with user and
2588host names prefixed to the file name.  For example, transforming
2589@file{/etc/secretfile} to
2590@file{~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile}, set the
2591@value{tramp} user option @code{tramp-backup-directory-alist} from
2592the existing user option @code{backup-directory-alist}.
2593
2594Then @value{tramp} backs up to a file name that is transformed with a
2595prefix consisting of the DIRECTORY name.  This file name prefixing
2596happens only when the DIRECTORY is an absolute local file name.
2597
2598@noindent
2599Example:
2600
2601@lisp
2602@group
2603(add-to-list 'backup-directory-alist
2604             (cons "." "~/.emacs.d/backups/"))
2605(customize-set-variable
2606 'tramp-backup-directory-alist backup-directory-alist)
2607@end group
2608@end lisp
2609
2610@noindent
2611The backup file name of
2612@file{@trampfn{su,root@@localhost,/etc/secretfile}} would be
2613@ifset unified
2614@file{@trampfn{su,root@@localhost,~/.emacs.d/backups/!su:root@@localhost:!etc!secretfile~}}
2615@end ifset
2616@ifset separate
2617@file{@trampfn{su,root@@localhost,~/.emacs.d/backups/![su!root@@localhost]!etc!secretfile~}}
2618@end ifset
2619
2620@vindex auto-save-file-name-transforms
2621Just as for backup files, similar issues of file naming affect
2622auto-saving remote files.  Auto-saved files are saved in the directory
2623specified by the user option @code{auto-save-file-name-transforms}.
2624By default this is set to the local temporary directory.  But in some
2625versions of Debian GNU/Linux, this points to the source directory
2626where the Emacs was compiled.  Reset such values to a valid directory.
2627
2628Set @code{auto-save-file-name-transforms} to @code{nil} to save
2629auto-saved files to the same directory as the original file.
2630
2631@vindex tramp-auto-save-directory
2632Alternatively, set the user option @code{tramp-auto-save-directory}
2633to direct all auto saves to that location.
2634
2635@node Windows setup hints
2636@section Issues with Cygwin ssh
2637@cindex cygwin, issues
2638
2639This section is incomplete.  Please share your solutions.
2640
2641@cindex method @option{sshx} with cygwin
2642@cindex @option{sshx} method with cygwin
2643
2644Cygwin's @command{ssh} works only with a Cygwin version of Emacs.  To
2645check for compatibility: type @kbd{M-x eshell @key{RET}}, and start
2646@kbd{ssh test.host @key{RET}}.  Incompatibilities trigger this
2647message:
2648
2649@example
2650Pseudo-terminal will not be allocated because stdin is not a terminal.
2651@end example
2652
2653Some older versions of Cygwin's @command{ssh} work with the
2654@option{sshx} access method.  Consult Cygwin's FAQ at
2655@uref{https://cygwin.com/faq/} for details.
2656
2657@cindex cygwin and @command{fakecygpty}
2658@cindex @command{fakecygpty} and cygwin
2659
2660On @uref{https://www.emacswiki.org/emacs/SshWithNTEmacs, the Emacs
2661Wiki} it is explained how to use the helper program
2662@command{fakecygpty} to fix this problem.
2663
2664@cindex method @option{scpx} with cygwin
2665@cindex @option{scpx} method with cygwin
2666
2667When using the @option{scpx} access method, Emacs may call
2668@command{scp} with MS Windows file naming, such as @code{c:/foo}.  But
2669the version of @command{scp} that is installed with Cygwin does not
2670know about MS Windows file naming, which causes it to incorrectly look
2671for a host named @code{c}.
2672
2673A workaround: write a wrapper script for @option{scp} to convert
2674Windows file names to Cygwin file names.
2675
2676@cindex cygwin and @command{ssh-agent}
2677@cindex @env{SSH_AUTH_SOCK} and emacs on ms windows
2678@vindex SSH_AUTH_SOCK@r{, environment variable}
2679
2680When using the @command{ssh-agent} on MS Windows for password-less
2681interaction, @option{ssh} methods depend on the environment variable
2682@env{SSH_AUTH_SOCK}.  But this variable is not set when Emacs is
2683started from a Desktop shortcut and authentication fails.
2684
2685One workaround is to use an MS Windows based SSH Agent, such as
2686Pageant.  It is part of the Putty Suite of tools.
2687
2688The fallback is to start Emacs from a shell.
2689
2690
2691@node Usage
2692@chapter Using @value{tramp}
2693@cindex using @value{tramp}
2694
2695@value{tramp} operates transparently, accessing remote files as if
2696they are local.  However, @value{tramp} employs a formalized remote
2697file naming syntax to perform its functions transparently.  This
2698syntax consists of many parts specifying access methods,
2699authentication, host names, and file names.  Ange FTP uses a similar
2700syntax.
2701
2702@cindex type-ahead
2703
2704Unlike opening local files in Emacs, which are instantaneous, opening
2705remote files in @value{tramp} is slower at first.  Sometimes there is
2706a noticeable delay before the prompts for passwords or authentication
2707appear in the minibuffer.  Hitting @kbd{@key{RET}} or other keys
2708during this gap will be processed by Emacs.  This type-ahead facility
2709is a feature of Emacs that may cause missed prompts when using
2710@value{tramp}.
2711
2712@menu
2713* File name syntax::            @value{tramp} file name conventions.
2714@ifset unified
2715* Change file name syntax::     Alternative file name syntax.
2716@end ifset
2717* File name completion::        File name completion.
2718* Ad-hoc multi-hops::           Declaring multiple hops in the file name.
2719* Remote processes::            Integration with other Emacs packages.
2720* Cleanup remote connections::  Cleanup remote connections.
2721* Renaming remote files::       Renaming remote files.
2722* Archive file names::          Access to files in file archives.
2723@end menu
2724
2725
2726@node File name syntax
2727@section @value{tramp} file name conventions
2728@cindex file name syntax
2729@cindex file name examples
2730
2731@file{@trampfn{method,host,/path/to/file}} opens file @var{/path/to/file}
2732on the remote host @var{host}, using the method @var{method}.
2733
2734@table @file
2735@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}.emacs
2736For the file @file{.emacs} located in the home directory, on the host
2737@code{melancholia}, using method @code{ssh}.
2738
2739@item @value{prefix}ssh@value{postfixhop}melancholia.danann.net@value{postfix}.emacs
2740For the file @file{.emacs} specified using the fully qualified domain name of
2741the host.
2742
2743@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~/.emacs
2744For the file @file{.emacs} specified using the @file{~}, which is expanded.
2745
2746@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}~daniel/.emacs
2747For the file @file{.emacs} located in @code{daniel}'s home directory
2748on the host, @code{melancholia}.  The @file{~<user>} construct is
2749expanded to the home directory of that user on the remote host.
2750
2751@item @value{prefix}ssh@value{postfixhop}melancholia@value{postfix}/etc/squid.conf
2752For the file @file{/etc/squid.conf} on the host @code{melancholia}.
2753
2754@end table
2755
2756@var{host} can take IPv4 or IPv6 address, as in
2757@file{@trampfn{ssh,127.0.0.1,.emacs}} or
2758@file{@trampfn{ssh,@value{ipv6prefix}::1@value{ipv6postfix},.emacs}}.
2759@ifset unified
2760For syntactical reasons, IPv6 addresses must be embedded in square
2761brackets @file{@value{ipv6prefix}} and @file{@value{ipv6postfix}}.
2762@end ifset
2763
2764By default, @value{tramp} will use the current local user name as the
2765remote user name for log in to the remote host.  Specifying a different
2766name using the proper syntax will override this default behavior:
2767
2768@example
2769@trampfn{method,user@@host,path/to/file}
2770@end example
2771
2772@file{@trampfn{ssh,daniel@@melancholia,.emacs}} is for file
2773@file{.emacs} in @code{daniel}'s home directory on the host,
2774@code{melancholia}, accessing via method @code{ssh}.
2775
2776For specifying port numbers, affix @file{#<port>} to the host
2777name.  For example: @file{@trampfn{ssh,daniel@@melancholia#42,.emacs}}.
2778
2779All method, user name, host name, port number and local name parts are
2780optional, @xref{Default Method}, @xref{Default User}, @xref{Default Host}.
2781@ifset unified
2782For syntactical reasons, the default method must be indicated by the
2783pseudo method @file{-}.
2784@end ifset
2785
2786
2787@ifset unified
2788@node Change file name syntax
2789@section Alternative file name syntax
2790@cindex change file name syntax
2791@cindex alternative file name syntax
2792
2793The syntax described in @ref{File name syntax} is the @code{default}
2794syntax, which is active after Emacs startup.  However, this can be
2795changed.
2796
2797@deffn Command tramp-change-syntax syntax
2798This command changes the syntax @value{tramp} uses for remote file
2799names.  Beside the @code{default} value, @var{syntax} can be
2800
2801@itemize
2802@item @code{simplified}
2803@cindex simplified syntax
2804
2805The remote file name syntax is similar to the syntax used by Ange FTP@.
2806A remote file name has the form
2807@code{@value{prefix}user@@host@value{postfix}path/to/file}.  The
2808@code{user@@} part is optional, and the method is determined by
2809@ref{Default Method}.
2810
2811@item @code{separate}
2812@cindex separate syntax
2813
2814@clear unified
2815@set separate
2816@include trampver.texi
2817The remote file name syntax is similar to the syntax used by XEmacs.
2818A remote file name has the form
2819@code{@trampfn{method,user@@host,path/to/file}}.  The @code{method}
2820and @code{user@@} parts are optional.
2821@clear separate
2822@set unified
2823@include trampver.texi
2824@end itemize
2825@end deffn
2826
2827@defvar tramp-file-name-regexp
2828This variable keeps a regexp which matches the selected remote file
2829name syntax.  Its value changes after every call of
2830@code{tramp-change-syntax}.  However, it is not recommended to use
2831this variable in external packages, a call of @code{file-remote-p} is
2832much more appropriate.
2833@ifinfo
2834@pxref{Magic File Names, , , elisp}.
2835@end ifinfo
2836@end defvar
2837@end ifset
2838
2839
2840@node File name completion
2841@section File name completion
2842@cindex file name completion
2843
2844@value{tramp} can complete the following @value{tramp} file name
2845components: method names, user names, host names, and file names
2846located on remote hosts.  User name and host name completion is
2847activated only, if file name completion has one of the styles
2848@code{basic}, @code{emacs21}, or @code{emacs22}.
2849@ifinfo
2850@xref{Completion Styles, , , emacs}.
2851@end ifinfo
2852
2853For example, type @kbd{C-x C-f @value{prefixwithspace} s @key{TAB}},
2854@value{tramp} completion choices show up as
2855
2856@example
2857@group
2858@multitable @columnfractions .2 .2 .2 .2 .2
2859@item @c
2860  sbin/ @tab @c
2861  @value{prefixhop}scp@value{postfix} @tab @c
2862  @value{prefixhop}scpx@value{postfix} @tab @c
2863  @value{prefixhop}sftp@value{postfix} @tab @c
2864  @value{prefixhop}sg@value{postfix}
2865@item @c
2866  @value{prefixhop}smb@value{postfix} @tab @c
2867  srv/ @tab @c
2868  @value{prefixhop}ssh@value{postfix} @tab @c
2869  @value{prefixhop}sshx@value{postfix} @tab @c
2870  @value{prefixhop}su@value{postfix}
2871@item @c
2872  @value{prefixhop}sudo@value{postfix} @tab @c
2873  sys/
2874@end multitable
2875@end group
2876@end example
2877
2878@samp{@value{prefixhop}ssh@value{postfixhop}} is a possible
2879completion for the respective method, and @samp{sbin/} stands for the
2880directory @file{/sbin} on your local host.
2881
2882Type @kbd{s h @value{postfixhop}} for the minibuffer completion to
2883@samp{@value{prefix}ssh@value{postfixhop}}.  Typing @kbd{@key{TAB}}
2884shows host names @value{tramp} extracts from @file{~/.ssh/config}
2885file, for example.
2886
2887@example
2888@group
2889@multitable @columnfractions .5 .5
2890@item @c
2891  @value{prefixhop}ssh@value{postfixhop}127.0.0.1@value{postfix} @tab @c
2892  @value{prefixhop}ssh@value{postfixhop}192.168.0.1@value{postfix}
2893@item @c
2894  @value{prefixhop}ssh@value{postfixhop}@value{ipv6prefix}::1@value{ipv6postfix}@value{postfix} @tab @c
2895  @value{prefixhop}ssh@value{postfixhop}localhost@value{postfix}
2896@item @c
2897  @value{prefixhop}ssh@value{postfixhop}melancholia.danann.net@value{postfix} @tab @c
2898  @value{prefixhop}ssh@value{postfixhop}melancholia@value{postfix}
2899@end multitable
2900@end group
2901@end example
2902
2903Choose a host from the above list and then continue to complete file
2904names on that host.
2905
2906When the configuration (@pxref{Customizing Completion}) includes user
2907names, then the completion lists will account for the user names as well.
2908
2909@vindex tramp-completion-use-auth-sources
2910Results from @code{auth-sources} search (@pxref{Using an
2911authentication file}) are added to the completion candidates.  This
2912search could be annoying, for example due to a passphrase request of
2913the @file{~/.authinfo.gpg} authentication file.  The user option
2914@code{tramp-completion-use-auth-sources} controls, whether such a
2915search is performed during completion.
2916
2917Remote hosts previously visited or hosts whose connections are kept
2918persistently (@pxref{Connection caching}) will be included in the
2919completion lists.
2920
2921After remote host name completion comes completion of file names on
2922the remote host.  It works the same as with local host file completion
2923except that killing with double-slash @file{//} kills only the file
2924name part of the @value{tramp} file name syntax.  A triple-slash
2925stands for the default behavior.
2926@ifinfo
2927@xref{Minibuffer File, , , emacs}.
2928@end ifinfo
2929
2930@noindent
2931Example:
2932
2933@example
2934@group
2935@kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin//etc} @key{TAB}}
2936     @print{} @trampfn{ssh,melancholia,/etc}
2937
2938@kbd{C-x C-f @trampfn{ssh,melancholia,//etc} @key{TAB}}
2939     @print{} @trampfn{ssh,melancholia,/etc}
2940
2941@kbd{C-x C-f @trampfn{ssh,melancholia,/usr/local/bin///etc} @key{TAB}}
2942     @print{} /etc
2943@end group
2944@end example
2945
2946
2947@node Ad-hoc multi-hops
2948@section Declaring multiple hops in the file name
2949@cindex multi-hop, ad-hoc
2950@cindex proxy hosts, ad-hoc
2951
2952@value{tramp} file name syntax can accommodate ad-hoc specification of
2953multiple proxies without using @code{tramp-default-proxies-alist}
2954configuration setup (@pxref{Multi-hops}).
2955
2956Each proxy is specified using the same syntax as the remote host
2957specification minus the file name part.  Each hop is separated by a
2958@samp{|}.  Chain the proxies from the starting host to the destination
2959remote host name and file name.  For example, hopping over a single
2960proxy @samp{bird@@bastion} to a remote file on @samp{you@@remotehost}:
2961
2962@example
2963@c @kbd{C-x C-f @trampfn{ssh@value{postfixhop}bird@@bastion|ssh,you,remotehost,/path} @key{RET}}
2964@kbd{C-x C-f @value{prefix}ssh@value{postfixhop}bird@@bastion|ssh@value{postfixhop}you@@remotehost@value{postfix}/path @key{RET}}
2965@end example
2966
2967Each involved method must be an inline method (@pxref{Inline methods}).
2968
2969@value{tramp} adds the ad-hoc definitions on the fly to
2970@code{tramp-default-proxies-alist} and is available for re-use during
2971that Emacs session.  Subsequent @value{tramp} connections to the same
2972remote host can then use the shortcut form:
2973@samp{@trampfn{ssh,you@@remotehost,/path}}.  Ad-hoc definitions are
2974removed from @code{tramp-default-proxies-alist} via the command
2975@kbd{M-x tramp-cleanup-all-connections @key{RET}} (@pxref{Cleanup
2976remote connections}).
2977
2978@defopt tramp-save-ad-hoc-proxies
2979For ad-hoc definitions to be saved automatically in
2980@code{tramp-default-proxies-alist} for future Emacs sessions, set
2981@code{tramp-save-ad-hoc-proxies} to non-@code{nil}.
2982
2983@lisp
2984(customize-set-variable 'tramp-save-ad-hoc-proxies t)
2985@end lisp
2986@end defopt
2987
2988Ad-hoc proxies can take patterns @code{%h} or @code{%u} like in
2989@code{tramp-default-proxies-alist}.  The following file name expands
2990to user @code{root} on host @code{remotehost}, starting with an
2991@option{ssh} session on host @code{remotehost}:
2992@samp{@value{prefix}ssh@value{postfixhop}%h|su@value{postfixhop}remotehost@value{postfix}}.
2993
2994On the other hand, if a trailing hop does not specify a host name,
2995the host name of the previous hop is reused. Therefore, the following
2996file name is equivalent to the previous example:
2997@samp{@value{prefix}ssh@value{postfixhop}remotehost|su@value{postfixhop}@value{postfix}}.
2998
2999
3000@node Remote processes
3001@section Integration with other Emacs packages
3002@cindex @code{compile}
3003@cindex @code{recompile}
3004
3005@value{tramp} supports starting new running processes on the remote
3006host for discovering remote file names.  Emacs packages on the remote
3007host need no specific modifications for @value{tramp}'s use.
3008
3009This type of integration does not work with the @option{ftp} method,
3010and does not support the pty association as specified in
3011@code{start-file-process}.
3012
3013@code{process-file} and @code{start-file-process} work on the remote
3014host when the variable @code{default-directory} is remote:
3015
3016@lisp
3017@group
3018(let ((default-directory "/ssh:remote.host:"))
3019  (start-file-process "grep" (get-buffer-create "*grep*")
3020                      "/bin/sh" "-c" "grep -e tramp *"))
3021@end group
3022@end lisp
3023
3024@vindex process-file-return-signal-string
3025@code{process-file} shall return either the exit code of the process,
3026or a string describing the signal, when the process has been
3027interrupted.  Since it cannot be determined reliably whether a remote
3028process has been interrupted, @code{process-file} returns always the
3029exit code.  When the user option
3030@code{process-file-return-signal-string} is non-nil,
3031@code{process-file} regards all exit codes greater than 128 as an
3032indication that the process has been interrupted, and returns a
3033respective string.
3034
3035Remote processes do not apply to @acronym{GVFS} (see @ref{GVFS-based
3036methods}) because the remote file system is mounted on the local host
3037and @value{tramp} just accesses by changing the
3038@code{default-directory}.
3039
3040@value{tramp} starts a remote process when a command is executed in a
3041remote file or directory buffer.  As of now, these packages have been
3042integrated to work with @value{tramp}: @file{shell.el},
3043@file{eshell.el}, @file{compile.el} (commands like @code{compile} and
3044@code{grep}) and @file{gud.el} (@code{gdb} or @code{perldb}).
3045
3046@vindex INSIDE_EMACS@r{, environment variable}
3047@value{tramp} always modifies the @env{INSIDE_EMACS} environment
3048variable for remote processes.  Per default, this environment variable
3049shows the Emacs version.  @value{tramp} adds its own version string,
3050so it looks like @samp{27.2,tramp:2.4.5.1}.  However, other packages
3051might also add their name to this environment variable, like
3052@samp{27.2,comint,tramp:2.4.5.1}.
3053
3054For @value{tramp} to find the command on the remote, it must be
3055accessible through the default search path as setup by @value{tramp}
3056upon first connection.  Alternatively, use an absolute path or extend
3057@code{tramp-remote-path} (see @ref{Remote programs}):
3058
3059@lisp
3060@group
3061(add-to-list 'tramp-remote-path "~/bin")
3062(add-to-list 'tramp-remote-path "/appli/pub/bin")
3063@end group
3064@end lisp
3065
3066@vindex tramp-remote-process-environment
3067Customize user option @code{tramp-remote-process-environment} to
3068suit the remote program's environment for the remote host.
3069@code{tramp-remote-process-environment} is a list of strings
3070structured similar to @code{process-environment}, where each element
3071is a string of the form @samp{ENVVARNAME=VALUE}.
3072
3073To avoid any conflicts with local host environment variables set
3074through local configuration files, such as @file{~/.profile}, use
3075@samp{ENVVARNAME=} to unset them for the remote environment.
3076
3077@noindent
3078Use @code{add-to-list} to add entries:
3079
3080@lisp
3081(add-to-list 'tramp-remote-process-environment "JAVA_HOME=/opt/java")
3082@end lisp
3083
3084@vindex HISTORY@r{, environment variable}
3085Modifying or deleting already existing values in the
3086@code{tramp-remote-process-environment} list may not be feasible on
3087restricted remote hosts.  For example, some system administrators
3088disallow changing @env{HISTORY} environment variable.  To accommodate
3089such restrictions when using @value{tramp}, fix the
3090@code{tramp-remote-process-environment} by the following code in the
3091local @file{.emacs} file:
3092
3093@lisp
3094@group
3095(let ((process-environment tramp-remote-process-environment))
3096  (setenv "HISTORY" nil)
3097  (setq tramp-remote-process-environment process-environment))
3098@end group
3099@end lisp
3100
3101@vindex ENV@r{, environment variable}
3102Setting the @env{ENV} environment variable instructs some shells to
3103read an initialization file.  Per default, @value{tramp} has disabled
3104this.  You could overwrite this behavior by evaluating
3105
3106@lisp
3107@group
3108(let ((process-environment tramp-remote-process-environment))
3109  (setenv "ENV" "$HOME/.profile")
3110  (setq tramp-remote-process-environment process-environment))
3111@end group
3112@end lisp
3113
3114In addition to @code{tramp-remote-process-environment}, you can set
3115environment variables for individual remote process calls by
3116let-binding @code{process-environment}.  @value{tramp} applies any
3117entries not present in the global default value of
3118@code{process-environment} (overriding
3119@code{tramp-remote-process-environment} settings, if they conflict).
3120For example:
3121
3122@lisp
3123@group
3124(let ((process-environment (cons "HGPLAIN=1" process-environment)))
3125  (process-file @dots{}))
3126@end group
3127@end lisp
3128
3129@vindex HGPLAIN@r{, environment variable}
3130Let-binding in this way works regardless of whether the process to be
3131called is local or remote, since @value{tramp} would add just the
3132@env{HGPLAIN} setting and local processes would take whole value of
3133@code{process-environment} along with the new value of @env{HGPLAIN}.
3134
3135For integrating other Emacs packages so @value{tramp} can execute
3136remotely, please file a bug report.  @xref{Bug Reports}.
3137
3138
3139@subsection Running remote programs that create local X11 windows
3140
3141@vindex DISPLAY@r{, environment variable}
3142To allow a remote program to create an X11 window on the local host,
3143set the @env{DISPLAY} environment variable for the remote host as
3144follows in the local @file{.emacs} file:
3145
3146@lisp
3147@group
3148(add-to-list 'tramp-remote-process-environment
3149             (format "DISPLAY=%s" (getenv "DISPLAY")))
3150@end group
3151@end lisp
3152
3153@noindent
3154@code{(getenv "DISPLAY")} should return a recognizable name for the
3155local host that the remote host can redirect X11 window
3156interactions.  If querying for a recognizable name is not possible for
3157whatever reason, then replace @code{(getenv "DISPLAY")} with a
3158hard-coded, fixed name.  Note that using @code{:0} for X11 display name
3159here will not work as expected.
3160
3161An alternate approach is specify @code{ForwardX11 yes} or
3162@code{ForwardX11Trusted yes} in @file{~/.ssh/config} on the local
3163host.
3164
3165
3166@subsection Running @code{shell} on a remote host
3167@cindex @code{shell}
3168
3169Set @code{explicit-shell-file-name} to the appropriate shell name
3170when using @value{tramp} between two hosts with different operating
3171systems, such as @samp{windows-nt} and @samp{gnu/linux}.  This option
3172ensures the correct name of the remote shell program.
3173
3174When @code{explicit-shell-file-name} is equal to @code{nil}, calling
3175@code{shell} interactively will prompt for a shell name.
3176
3177Starting with Emacs 26, you could use connection-local variables for
3178setting different values of @code{explicit-shell-file-name} for
3179different remote hosts.
3180@ifinfo
3181@xref{Connection Variables, , , emacs}.
3182@end ifinfo
3183
3184@lisp
3185@group
3186(connection-local-set-profile-variables
3187  'remote-bash
3188  '((explicit-shell-file-name . "/bin/bash")
3189    (explicit-bash-args . ("-i"))))
3190@end group
3191
3192@group
3193(connection-local-set-profile-variables
3194  'remote-ksh
3195  '((explicit-shell-file-name . "/bin/ksh")
3196    (explicit-ksh-args . ("-i"))))
3197@end group
3198
3199@group
3200(connection-local-set-profiles
3201  '(:application tramp :protocol "ssh" :machine "localhost")
3202  'remote-bash)
3203@end group
3204
3205@group
3206(connection-local-set-profiles
3207  `(:application tramp :protocol "sudo"
3208    :user "root" :machine ,(system-name))
3209  'remote-ksh)
3210@end group
3211@end lisp
3212
3213
3214@subsection Running @code{shell-command} on a remote host
3215@cindex @code{shell-command}
3216
3217@code{shell-command} executes commands synchronously or asynchronously
3218on remote hosts and displays output in buffers on the local
3219host.  Example:
3220
3221@example
3222@group
3223@kbd{C-x C-f @trampfn{sudo,,} @key{RET}}
3224@kbd{M-& tail -f /var/log/syslog.log @key{RET}}
3225@end group
3226@end example
3227
3228@command{tail} command outputs continuously to the local buffer,
3229@file{*Async Shell Command*}
3230
3231@kbd{M-x auto-revert-tail-mode @key{RET}} runs similarly showing
3232continuous output.
3233
3234@vindex shell-file-name
3235@vindex shell-command-switch
3236@code{shell-command} uses the variables @code{shell-file-name} and
3237@code{shell-command-switch} in order to determine which shell to run.
3238For remote hosts, their default values are @file{/bin/sh} and
3239@option{-c}, respectively (except for the @option{adb} method, which
3240uses @file{/system/bin/sh}).  Like the variables in the previous
3241section, these variables can be changed via connection-local
3242variables.
3243
3244@vindex async-shell-command-width
3245@vindex COLUMNS@r{, environment variable}
3246If Emacs supports the variable @code{async-shell-command-width} (since
3247Emacs 27), @value{tramp} cares about its value for asynchronous shell
3248commands.  It specifies the number of display columns for command
3249output.  For synchronous shell commands, a similar effect can be
3250achieved by adding the environment variable @env{COLUMNS} to
3251@code{tramp-remote-process-environment}.
3252
3253
3254@subsection Running @code{eshell} on a remote host
3255@cindex @code{eshell}
3256
3257@value{tramp} is integrated into @file{eshell.el}, which enables
3258interactive eshell sessions on remote hosts at the command prompt.
3259You must add the module @code{eshell-tramp} to
3260@code{eshell-modules-list}.  Here's a sample interaction after opening
3261@kbd{M-x eshell @key{RET}} on a remote host:
3262
3263@example
3264@group
3265@b{~ $} cd @trampfn{sudo,,/etc} @key{RET}
3266@b{@trampfn{sudo,root@@host,/etc} $} hostname @key{RET}
3267host
3268@b{@trampfn{sudo,root@@host,/etc} $} id @key{RET}
3269uid=0(root) gid=0(root) groups=0(root)
3270@b{@trampfn{sudo,root@@host,/etc} $} find-file shadow @key{RET}
3271#<buffer shadow>
3272@b{@trampfn{sudo,root@@host,/etc} $}
3273@end group
3274@end example
3275
3276@code{eshell} added custom @code{su} and @code{sudo} commands that set
3277the default directory correctly for the @file{*eshell*} buffer.
3278@value{tramp} silently updates @code{tramp-default-proxies-alist}
3279with an entry for this directory (@pxref{Multi-hops}):
3280
3281@example
3282@group
3283@b{~ $} cd @trampfn{ssh,user@@remotehost,/etc} @key{RET}
3284@b{@trampfn{ssh,user@@remotehost,/etc} $} find-file shadow @key{RET}
3285File is not readable: @trampfn{ssh,user@@remotehost,/etc/shadow}
3286@b{@trampfn{ssh,user@@remotehost,/etc} $} sudo find-file shadow @key{RET}
3287#<buffer shadow>
3288@end group
3289
3290@group
3291@b{@trampfn{ssh,user@@remotehost,/etc} $} su - @key{RET}
3292@b{@trampfn{su,root@@remotehost,/root} $} id @key{RET}
3293uid=0(root) gid=0(root) groups=0(root)
3294@b{@trampfn{su,root@@remotehost,/root} $}
3295@end group
3296@end example
3297
3298
3299@anchor{Running a debugger on a remote host}
3300@subsection Running a debugger on a remote host
3301@cindex @file{gud.el}
3302@cindex @code{gdb}
3303@cindex @code{perldb}
3304
3305@file{gud.el} provides a unified interface to symbolic debuggers
3306@ifinfo
3307(@ref{Debuggers, , , emacs}).
3308@end ifinfo
3309@value{tramp} can run debug on remote hosts by calling @code{gdb}
3310with a remote file name:
3311
3312@example
3313@group
3314@kbd{M-x gdb @key{RET}}
3315@b{Run gdb (like this):} gdb -i=mi @trampfn{ssh,host,~/myprog} @key{RET}
3316@end group
3317@end example
3318
3319Since the remote @code{gdb} and @code{gdb-inferior} processes do not
3320belong to the same process group on the remote host, there will be a
3321warning, which can be ignored:
3322
3323@example
3324&"warning: GDB: Failed to set controlling terminal: Operation not permitted\n"
3325@end example
3326
3327@noindent
3328As consequence, there will be restrictions in I/O of the process to be
3329debugged.
3330
3331Relative file names are based on the remote default directory.  When
3332@file{myprog.pl} exists in @file{@trampfn{ssh,host,/home/user}}, valid
3333calls include:
3334
3335@example
3336@group
3337@kbd{M-x perldb @key{RET}}
3338@b{Run perldb (like this):} perl -d myprog.pl @key{RET}
3339@end group
3340@end example
3341
3342Just the local part of a remote file name, such as @command{perl -d
3343/home/user/myprog.pl}, is not possible.
3344
3345Arguments of the program to be debugged must be literal, can take
3346relative or absolute paths, but not remote paths.
3347
3348
3349@subsection Running remote processes on MS Windows hosts
3350@cindex @command{winexe}
3351@cindex @command{powershell}
3352
3353@command{winexe} runs processes on a remote MS Windows host, and
3354@value{tramp} can use it for @code{process-file} and
3355@code{start-file-process}.
3356
3357@code{tramp-smb-winexe-program} specifies the local @command{winexe}
3358command.  Powershell V2.0 on the remote host is required to run
3359processes triggered from @value{tramp}.
3360
3361@code{explicit-shell-file-name} and @code{explicit-*-args} have to
3362be set properly so @kbd{M-x shell @key{RET}} can open a proper remote
3363shell on a MS Windows host.  To open @command{cmd}, set it as follows:
3364
3365@lisp
3366@group
3367(setq explicit-shell-file-name "cmd"
3368      explicit-cmd-args '("/q"))
3369@end group
3370@end lisp
3371
3372@noindent
3373To open @command{powershell} as a remote shell, use this:
3374
3375@lisp
3376@group
3377(setq explicit-shell-file-name "powershell"
3378      explicit-powershell-args '("-file" "-"))
3379@end group
3380@end lisp
3381
3382
3383@node Cleanup remote connections
3384@section Cleanup remote connections
3385@cindex cleanup
3386
3387@value{tramp} provides several ways to flush remote connections.
3388
3389@deffn Command tramp-cleanup-connection vec &optional keep-debug keep-password
3390This command flushes all connection related objects.  @var{vec} is the
3391internal representation of a remote connection.  When called
3392interactively, this command lists active remote connections in the
3393minibuffer.  Each connection is of the format
3394@file{@trampfn{method,user@@host,}}.
3395
3396Flushing remote connections also cleans the password cache
3397(@pxref{Password handling}), file cache, connection cache
3398(@pxref{Connection caching}), and recentf cache (@pxref{File
3399Conveniences, , , emacs}).  It also deletes session timers
3400(@pxref{Predefined connection information}) and connection buffers.
3401
3402If @var{keep-debug} is non-@code{nil}, the debug buffer is kept.  A
3403non-@code{nil} @var{keep-password} preserves the password cache.
3404@end deffn
3405
3406@deffn Command tramp-cleanup-this-connection
3407Flushes the current buffer's remote connection objects, the same as in
3408@code{tramp-cleanup-connection}.
3409@end deffn
3410
3411@deffn Command tramp-cleanup-all-connections
3412Flushes all active remote connection objects, the same as in
3413@code{tramp-cleanup-connection}.  This command removes also ad-hoc
3414proxy definitions (@pxref{Ad-hoc multi-hops}).
3415
3416@end deffn
3417
3418@deffn Command tramp-cleanup-all-buffers
3419Just as for @code{tramp-cleanup-all-connections}, all remote
3420connections and ad-hoc proxy definition are cleaned up in addition to
3421killing all buffers related to remote connections.
3422@end deffn
3423
3424
3425@node Renaming remote files
3426@section Renaming remote files
3427@cindex save remote files
3428
3429Sometimes, it is desirable to safe file contents of buffers visiting a
3430given remote host.  This could happen for example, if the local host
3431changes its network integration, and the remote host is not reachable
3432anymore.
3433
3434@deffn Command tramp-rename-files source target
3435Replace in all buffers the visiting file name from @var{source} to
3436@var{target}.  @var{source} is a remote directory name, which could
3437contain also a localname part.  @var{target} is the directory name
3438@var{source} is replaced with.  Often, @var{target} is a remote
3439directory name on another host, but it can also be a local directory
3440name.  If @var{target} has no local part, the local part from
3441@var{source} is used.
3442
3443If @var{target} is @code{nil}, it is selected according to the first
3444match in @code{tramp-default-rename-alist}.  If called interactively,
3445this match is offered as initial value for selection.
3446
3447On all buffers, which have a @code{buffer-file-name} matching
3448@var{source}, this name is modified by replacing @var{source} with
3449@var{target}.  This is applied by calling
3450@code{set-visited-file-name}.  The new @code{buffer-file-name} is
3451prompted for modification in the minibuffer.  The buffers are marked
3452modified, and must be saved explicitly.
3453
3454If user option @code{tramp-confirm-rename-file-names} is nil, changing
3455the file name happens without confirmation.  This requires a
3456matching entry in @code{tramp-default-rename-alist}.
3457
3458Remote buffers related to the remote connection identified by
3459@var{source}, which are not visiting files, or which are visiting
3460files not matching @var{source}, are not modified.
3461
3462Interactively, @var{target} is selected from
3463@code{tramp-default-rename-alist} without confirmation if the prefix
3464argument is non-@code{nil}.
3465
3466The remote connection identified by @var{source} is flushed by
3467@code{tramp-cleanup-connection}.
3468@end deffn
3469
3470@deffn Command tramp-rename-these-files target
3471Replace visiting file names to @var{target}.  The current buffer must
3472be related to a remote connection.  In all buffers, which are visiting
3473a file with the same directory name, the buffer file name is changed.
3474
3475Interactively, @var{target} is selected from
3476@code{tramp-default-rename-alist} without confirmation if the prefix
3477argument is non-@code{nil}.
3478@end deffn
3479
3480@defopt tramp-default-rename-alist
3481The default target for renaming remote buffer file names.  This is an
3482alist of cons cells @code{(source . target)}.  The first matching item
3483specifies the target to be applied for renaming buffer file names from
3484source via @code{tramp-rename-files}.  @code{source} is a regular
3485expressions, which matches a remote file name.  @code{target} must be
3486a directory name, which could be remote (including remote directories
3487Tramp infers by default, such as @samp{@trampfn{method,user@@host,}}).
3488
3489@code{target} can contain the patterns @code{%m}, @code{%u} or
3490@code{%h}, which are replaced by the method name, user name or host
3491name of @code{source} when calling @code{tramp-rename-files}.
3492
3493@code{source} could also be a Lisp form, which will be evaluated.  The
3494result must be a string or nil, which is interpreted as a regular
3495expression which always matches.
3496
3497Example entries:
3498
3499@lisp
3500@group
3501("@trampfn{ssh,badhost,/path/to/dir/}"
3502 . "@trampfn{ssh,goodhost,/path/to/another/dir/}")
3503@end group
3504@end lisp
3505
3506would trigger renaming of buffer file names on @samp{badhost} to
3507@samp{goodhost}, including changing the directory name.
3508
3509@lisp
3510("@trampfn{ssh,.+\\\\.company\\\\.org,}" . "@value{prefix}ssh@value{postfixhop}multi.hop|ssh@value{postfixhop}%h@value{postfix}")
3511@end lisp
3512
3513routes all connections to a host in @samp{company.org} via
3514@samp{@trampfn{ssh,multi.hop,}}, which might be useful when using
3515Emacs outside the company network.
3516
3517@lisp
3518(nil . "~/saved-files/%m:%u@@%h/")
3519@end lisp
3520
3521saves all remote files locally, with a directory name including method
3522name, user name and host name of the remote connection.
3523@end defopt
3524
3525@defopt tramp-confirm-rename-file-names
3526Whether renaming a buffer file name by @code{tramp-rename-files} or
3527@code{tramp-rename-these-files} must be confirmed.
3528@end defopt
3529
3530
3531@node Archive file names
3532@section Archive file names
3533@cindex file archives
3534@cindex archive file names
3535@cindex method archive
3536@cindex archive method
3537
3538@value{tramp} offers also transparent access to files inside file
3539archives.  This is possible only on hosts which have installed
3540@acronym{GVFS, the GNOME Virtual File System}, @ref{GVFS-based
3541methods}.  Internally, file archives are mounted via the
3542@acronym{GVFS} @option{archive} method.
3543
3544A file archive is a regular file of kind @file{/path/to/dir/file.EXT}.
3545The extension @samp{.EXT} identifies the type of the file archive.  A
3546file inside a file archive, called archive file name, has the name
3547@file{/path/to/dir/file.EXT/dir/file}.
3548
3549Most of the @ref{Magic File Names, , magic file name operations,
3550elisp}, are implemented for archive file names, exceptions are all
3551operations which write into a file archive, and process related
3552operations.  Therefore, functions like
3553
3554@lisp
3555(copy-file "/path/to/dir/file.tar/dir/file" "/somewhere/else")
3556@end lisp
3557
3558@noindent
3559work out of the box.  This is also true for file name completion, and
3560for libraries like @code{dired} or @code{ediff}, which accept archive
3561file names as well.
3562
3563@vindex tramp-archive-suffixes
3564File archives are identified by the file name extension @samp{.EXT}.
3565Since @acronym{GVFS} uses internally the library @code{libarchive(3)},
3566all suffixes, which are accepted by this library, work also for
3567archive file names.  Accepted suffixes are listed in the constant
3568@code{tramp-archive-suffixes}.  They are
3569
3570@itemize
3571@item @samp{.7z} ---
35727-Zip archives
3573@cindex @file{7z} file archive suffix
3574@cindex file archive suffix @file{7z}
3575
3576@item @samp{.apk} ---
3577Android package kits
3578@cindex @file{apk} file archive suffix
3579@cindex file archive suffix @file{apk}
3580
3581@item @samp{.ar} ---
3582UNIX archiver formats
3583@cindex @file{ar} file archive suffix
3584@cindex file archive suffix @file{ar}
3585
3586@item @samp{.cab}, @samp{.CAB} ---
3587Microsoft Windows cabinets
3588@cindex @file{cab} file archive suffix
3589@cindex @file{CAB} file archive suffix
3590@cindex file archive suffix @file{cab}
3591@cindex file archive suffix @file{CAB}
3592
3593@item @samp{.cpio} ---
3594CPIO archives
3595@cindex @file{cpio} file archive suffix
3596@cindex file archive suffix @file{cpio}
3597
3598@item @samp{.deb} ---
3599Debian packages
3600@cindex @file{deb} file archive suffix
3601@cindex file archive suffix @file{deb}
3602
3603@item @samp{.depot} ---
3604HP-UX SD depots
3605@cindex @file{depot} file archive suffix
3606@cindex file archive suffix @file{depot}
3607
3608@item @samp{.exe} ---
3609Self extracting Microsoft Windows EXE files
3610@cindex @file{exe} file archive suffix
3611@cindex file archive suffix @file{exe}
3612
3613@item @samp{.iso} ---
3614ISO 9660 images
3615@cindex @file{iso} file archive suffix
3616@cindex file archive suffix @file{iso}
3617
3618@item @samp{.jar} ---
3619Java archives
3620@cindex @file{jar} file archive suffix
3621@cindex file archive suffix @file{jar}
3622
3623@item @samp{.lzh}, @samp{.LZH} ---
3624Microsoft Windows compressed LHA archives
3625@cindex @file{lzh} file archive suffix
3626@cindex @file{LZH} file archive suffix
3627@cindex file archive suffix @file{lzh}
3628@cindex file archive suffix @file{LZH}
3629
3630@item @samp{.msu}, @samp{.MSU} ---
3631Microsoft Windows Update packages
3632@cindex @file{msu} file archive suffix
3633@cindex @file{MSU} file archive suffix
3634@cindex file archive suffix @file{msu}
3635@cindex file archive suffix @file{MSU}
3636
3637@item @samp{.mtree} ---
3638BSD mtree format
3639@cindex @file{mtree} file archive suffix
3640@cindex file archive suffix @file{mtree}
3641
3642@item @samp{.odb}, @samp{.odf}, @samp{.odg}, @samp{.odp}, @samp{.ods},
3643@samp{.odt} ---
3644OpenDocument formats
3645@cindex @file{odb} file archive suffix
3646@cindex @file{odf} file archive suffix
3647@cindex @file{odg} file archive suffix
3648@cindex @file{odp} file archive suffix
3649@cindex @file{ods} file archive suffix
3650@cindex @file{odt} file archive suffix
3651@cindex file archive suffix @file{odb}
3652@cindex file archive suffix @file{odf}
3653@cindex file archive suffix @file{odg}
3654@cindex file archive suffix @file{odp}
3655@cindex file archive suffix @file{ods}
3656@cindex file archive suffix @file{odt}
3657
3658@item @samp{.pax} ---
3659Posix archives
3660@cindex @file{pax} file archive suffix
3661@cindex file archive suffix @file{pax}
3662
3663@item @samp{.rar} ---
3664RAR archives
3665@cindex @file{rar} file archive suffix
3666@cindex file archive suffix @file{rar}
3667
3668@item @samp{.rpm} ---
3669Red Hat packages
3670@cindex @file{rpm} file archive suffix
3671@cindex file archive suffix @file{rpm}
3672
3673@item @samp{.shar} ---
3674Shell archives
3675@cindex @file{shar} file archive suffix
3676@cindex file archive suffix @file{shar}
3677
3678@item @samp{.tar}, @samp{.tbz}, @samp{.tgz}, @samp{.tlz}, @samp{.txz},
3679@samp{.tzst} ---
3680(Compressed) tape archives
3681@cindex @file{tar} file archive suffix
3682@cindex @file{tbz} file archive suffix
3683@cindex @file{tgz} file archive suffix
3684@cindex @file{tlz} file archive suffix
3685@cindex @file{txz} file archive suffix
3686@cindex @file{tzst} file archive suffix
3687@cindex file archive suffix @file{tar}
3688@cindex file archive suffix @file{tbz}
3689@cindex file archive suffix @file{tgz}
3690@cindex file archive suffix @file{tlz}
3691@cindex file archive suffix @file{txz}
3692@cindex file archive suffix @file{tzst}
3693
3694@item @samp{.warc} ---
3695Web archives
3696@cindex @file{warc} file archive suffix
3697@cindex file archive suffix @file{warc}
3698
3699@item @samp{.xar} ---
3700macOS XAR archives
3701@cindex @file{xar} file archive suffix
3702@cindex file archive suffix @file{xar}
3703
3704@item @samp{.xpi} ---
3705XPInstall Mozilla addons
3706@cindex @file{xpi} file archive suffix
3707@cindex file archive suffix @file{xpi}
3708
3709@item @samp{.xps} ---
3710Open XML Paper Specification (OpenXPS) documents
3711@cindex @file{xps} file archive suffix
3712@cindex file archive suffix @file{xps}
3713
3714@item @samp{.zip}, @samp{.ZIP} ---
3715ZIP archives
3716@cindex @file{zip} file archive suffix
3717@cindex @file{ZIP} file archive suffix
3718@cindex file archive suffix @file{zip}
3719@cindex file archive suffix @file{ZIP}
3720@end itemize
3721
3722@vindex tramp-archive-compression-suffixes
3723File archives could also be compressed, identified by an additional
3724compression suffix.  Valid compression suffixes are listed in the
3725constant @code{tramp-archive-compression-suffixes}.  They are
3726@samp{.bz2}, @samp{.gz}, @samp{.lrz}, @samp{.lz}, @samp{.lz4},
3727@samp{.lzma}, @samp{.lzo}, @samp{.uu}, @samp{.xz}, @samp{.Z}, and
3728@samp{.zst}.  A valid archive file name would be
3729@file{/path/to/dir/file.tar.gz/dir/file}.  Even several suffixes in a
3730row are possible, like @file{/path/to/dir/file.tar.gz.uu/dir/file}.
3731
3732@vindex tramp-archive-all-gvfs-methods
3733An archive file name could be a remote file name, as in
3734@file{/ftp:anonymous@@ftp.gnu.org:/gnu/tramp/tramp-2.4.5.tar.gz/INSTALL}.
3735Since all file operations are mapped internally to @acronym{GVFS}
3736operations, remote file names supported by @code{tramp-gvfs} perform
3737better, because no local copy of the file archive must be downloaded
3738first.  For example, @samp{/sftp:user@@host:...} performs better than
3739the similar @samp{/scp:user@@host:...}.  See the constant
3740@code{tramp-archive-all-gvfs-methods} for a complete list of
3741@code{tramp-gvfs} supported method names.
3742
3743If @code{url-handler-mode} is enabled, archives could be visited via
3744URLs, like
3745@file{https://ftp.gnu.org/gnu/tramp/tramp-2.4.5.tar.gz/INSTALL}.  This
3746allows complex file operations like
3747
3748@lisp
3749@group
3750(progn
3751  (url-handler-mode 1)
3752  (ediff-directories
3753   "https://ftp.gnu.org/gnu/tramp/tramp-2.4.4.tar.gz/tramp-2.4.4"
3754   "https://ftp.gnu.org/gnu/tramp/tramp-2.4.5.tar.gz/tramp-2.4.5" ""))
3755@end group
3756@end lisp
3757
3758It is even possible to access file archives in file archives, as
3759
3760@lisp
3761@group
3762(progn
3763  (url-handler-mode 1)
3764  (find-file
3765   "http://ftp.debian.org/debian/pool/main/c/coreutils/coreutils_8.28-1_amd64.deb/control.tar.gz/control"))
3766@end group
3767@end lisp
3768
3769@vindex tramp-archive-enabled
3770In order to disable file archives, you could add the following form to
3771your init file:
3772
3773@lisp
3774(customize-set-variable 'tramp-archive-enabled nil)
3775@end lisp
3776
3777
3778@node Bug Reports
3779@chapter Reporting Bugs and Problems
3780@cindex bug reports
3781
3782@value{tramp}'s development team is actively engaged in solving bugs
3783and problems and looks to feature requests and suggestions.
3784
3785@value{tramp}'s mailing list is the place for more advice and
3786information on working with @value{tramp}, solving problems,
3787discussing, and general discussions about @value{tramp}.
3788
3789@value{tramp}'s mailing list is moderated but even non-subscribers can
3790post for moderator approval.  Sometimes this approval step may take as
3791long as 48 hours due to public holidays.
3792
3793@email{@value{tramp-bug-report-address}} is the mailing list.
3794Messages sent to this address go to all the subscribers.  This is
3795@emph{not} the address to send subscription requests to.
3796
3797To subscribe to the mailing list, visit:
3798@uref{https://lists.gnu.org/mailman/listinfo/tramp-devel/, the
3799@value{tramp} Mail Subscription Page}.
3800
3801@ifset installchapter
3802Before sending a bug report, run the test suite first @ref{Testing}.
3803@end ifset
3804
3805@findex tramp-bug
3806Check if the bug or problem is already addressed in @xref{Frequently
3807Asked Questions}.
3808
3809Run @kbd{M-x tramp-bug @key{RET}} to generate a buffer with details of
3810the system along with the details of the @value{tramp} installation.
3811Please include these details with the bug report.
3812
3813The bug report must describe in as excruciating detail as possible the
3814steps required to reproduce the problem.  These details must include
3815the setup of the remote host and any special or unique conditions that
3816exist.
3817
3818Include a minimal test case that reproduces the problem.  This will
3819help the development team find the best solution and avoid unrelated
3820detours.
3821
3822To exclude cache-related problems, flush all caches before running the
3823test, @ref{Cleanup remote connections}.  Alternatively, and often
3824better for analysis, reproduce the problem in a clean Emacs session
3825started with @command{emacs -Q}.  Then, @value{tramp} does not load
3826the persistency file (@pxref{Connection caching}), and it does not use
3827passwords from @file{auth-source.el} (@pxref{Password handling}).
3828
3829When including @value{tramp}'s messages in the bug report, increase
3830the verbosity level to 6 (@pxref{Traces and Profiles, Traces}) in the
3831@file{~/.emacs} file before repeating steps to the bug.  Include the
3832contents of the @file{*tramp/foo*} and @file{*debug tramp/foo*}
3833buffers with the bug report.  Both buffers could contain
3834non-@acronym{ASCII} characters which are relevant for analysis, append
3835the buffers as attachments to the bug report.  This is also needed in
3836order to avoid line breaks during mail transfer.
3837
3838@strong{Note} that a verbosity level greater than 6 is not necessary
3839at this stage.  Also note that a verbosity level of 6 or greater, the
3840contents of files and directories will be included in the debug
3841buffer.  Passwords typed in @value{tramp} will never be included
3842there.
3843
3844
3845@node Frequently Asked Questions
3846@chapter Frequently Asked Questions
3847@cindex frequently asked questions
3848@cindex FAQ
3849
3850@itemize @bullet
3851@item
3852Where is the latest @value{tramp}?
3853
3854@value{tramp} is available at the GNU URL:
3855
3856@noindent
3857@uref{https://ftp.gnu.org/gnu/tramp/}
3858
3859@noindent
3860@value{tramp}'s GNU project page is located here:
3861
3862@noindent
3863@uref{https://savannah.gnu.org/projects/tramp/}
3864
3865
3866@item
3867Which systems does it work on?
3868
3869The package works successfully on Emacs 24, Emacs 25, Emacs 26, Emacs
387027, and Emacs 28.
3871
3872While Unix and Unix-like systems are the primary remote targets,
3873@value{tramp} has equal success connecting to other platforms, such as
3874MS Windows 7/8/10.
3875
3876
3877@item
3878How to speed up @value{tramp}?
3879
3880@value{tramp} does many things in the background, some of which
3881depends on network speeds, response speeds of remote hosts, and
3882authentication delays.  During these operations, @value{tramp}'s
3883responsiveness slows down.  Some suggestions within the scope of
3884@value{tramp}'s settings include:
3885
3886Use an external method, such as @option{scp}, which are faster than
3887internal methods.
3888
3889Keep the file @code{tramp-persistency-file-name}, which is where
3890@value{tramp} caches remote information about hosts and files.  Caching
3891is enabled by default.  Don't disable it.
3892
3893@vindex remote-file-name-inhibit-cache
3894Set @code{remote-file-name-inhibit-cache} to @code{nil} if remote
3895files are not independently updated outside @value{tramp}'s control.
3896That cache cleanup will be necessary if the remote directories or
3897files are updated independent of @value{tramp}.
3898
3899Disable version control to avoid delays:
3900
3901@lisp
3902@group
3903(setq vc-ignore-dir-regexp
3904      (format "\\(%s\\)\\|\\(%s\\)"
3905              vc-ignore-dir-regexp
3906              tramp-file-name-regexp))
3907@end group
3908@end lisp
3909
3910If this is too radical, because you want to use version control
3911remotely, trim @code{vc-handled-backends} to just those you care
3912about, for example:
3913
3914@lisp
3915(setq vc-handled-backends '(SVN Git))
3916@end lisp
3917
3918Disable excessive traces.  Set @code{tramp-verbose} to 3 or lower,
3919default being 3.  Increase trace levels temporarily when hunting for
3920bugs.
3921
3922@item
3923@value{tramp} does not connect to the remote host
3924
3925Three main reasons for why @value{tramp} does not connect to the remote host:
3926
3927@itemize @minus
3928@item
3929Unknown characters in the prompt
3930
3931@value{tramp} needs a clean recognizable prompt on the remote host for
3932accurate parsing.  Shell prompts that contain escape sequences for
3933coloring cause parsing problems.  @ref{Remote shell setup} for
3934customizing prompt detection using regular expressions.
3935
3936To check if the remote host's prompt is being recognized, use this
3937test: switch to @value{tramp} connection buffer @file{*tramp/foo*},
3938put the cursor at the top of the buffer, and then apply the following
3939expression:
3940
3941@example
3942@kbd{M-: (re-search-forward (concat tramp-shell-prompt-pattern "$")) @key{RET}}
3943@end example
3944
3945If the cursor has not moved to the prompt at the bottom of the buffer,
3946then @value{tramp} has failed to recognize the prompt.
3947
3948When using zsh on remote hosts, disable zsh line editor because zsh
3949uses left-hand side and right-hand side prompts in parallel.  Add the
3950following line to @file{~/.zshrc}:
3951
3952@example
3953[[ $TERM == "dumb" ]] && unsetopt zle && PS1='$ ' && return
3954@end example
3955
3956This uses the default value of @code{tramp-terminal-type}, @t{"dumb"},
3957as value of the @env{TERM} environment variable.  If you want to use
3958another value for @env{TERM}, change @code{tramp-terminal-type} and
3959this line accordingly.
3960
3961Alternatively, you could set the remote login shell explicitly.  See
3962@ref{Remote shell setup} for discussion of this technique,
3963
3964When using fish shell on remote hosts, disable fancy formatting by
3965adding the following to @file{~/.config/fish/config.fish}:
3966
3967@example
3968@group
3969function fish_prompt
3970  if test $TERM = "dumb"
3971     echo "\$ "
3972  else
3973     @dots{}
3974  end
3975end
3976@end group
3977@end example
3978
3979When using WinSSHD on remote hosts, @value{tramp} does not recognize
3980the strange prompt settings.
3981
3982A similar problem exist with the iTerm2 shell integration, which sends
3983proprietary escape codes when starting a shell.  This can be
3984suppressed by changing the respective integration snippet in your
3985@file{~/.profile} like this:
3986
3987@example
3988@group
3989[ $TERM = "dumb" ] || \
3990test -e "$@{HOME@}/.iterm2_shell_integration.bash" && \
3991source "$@{HOME@}/.iterm2_shell_integration.bash"
3992@end group
3993@end example
3994
3995And finally, bash's readline should not use key bindings like
3996@samp{C-j} to commands.  Disable this in your @file{~/.inputrc}:
3997
3998@example
3999@group
4000$if term=dumb
4001# Don't bind Control-J or it messes up @value{tramp}.
4002$else
4003"\C-j": next-history
4004$endif
4005@end group
4006@end example
4007
4008@item
4009Echoed characters after login
4010
4011@value{tramp} suppresses echos from remote hosts with the
4012@command{stty -echo} command.  But sometimes it is too late to suppress
4013welcome messages from the remote host containing harmful control
4014characters.  Using @option{sshx} or @option{scpx} methods can avoid
4015this problem because they allocate a pseudo tty.  @xref{Inline
4016methods}.
4017
4018@item
4019@value{tramp} stops transferring strings longer than 500 characters
4020
4021Set @code{tramp-chunksize} to 500 to get around this problem, which is
4022related to faulty implementation of @code{process-send-string} on
4023HP-UX, FreeBSD and Tru64 Unix systems.  Consult the documentation for
4024@code{tramp-chunksize} to see when this is necessary.
4025
4026Set @code{file-precious-flag} to @code{t} for files accessed by
4027@value{tramp} so the file contents are checked using checksum by
4028first saving to a temporary file.
4029@ifinfo
4030@pxref{Saving Buffers, , , elisp}.
4031@end ifinfo
4032
4033@lisp
4034@group
4035(add-hook
4036 'find-file-hook
4037 (lambda ()
4038   (when (file-remote-p default-directory)
4039     (set (make-local-variable 'file-precious-flag) t))))
4040@end group
4041@end lisp
4042@end itemize
4043
4044
4045@item
4046@value{tramp} fails in a chrooted environment
4047
4048@vindex tramp-local-host-regexp
4049When connecting to a local host, @value{tramp} uses some internal
4050optimizations.  They fail when Emacs runs in a chrooted environment.
4051In order to disable those optimizations, set user option
4052@code{tramp-local-host-regexp} to @code{nil}.
4053
4054
4055@item
4056@value{tramp} does not recognize if a @command{ssh} session hangs
4057
4058@command{ssh} sessions on the local host hang when the network is
4059down.  @value{tramp} cannot safely detect such hangs.  The network
4060configuration for @command{ssh} can be configured to kill such hangs
4061with the following command in the @file{~/.ssh/config}:
4062
4063@example
4064@group
4065Host *
4066     ServerAliveInterval 5
4067@end group
4068@end example
4069
4070
4071@item
4072@value{tramp} does not use default @command{ssh} @code{ControlPath}
4073
4074@value{tramp} overwrites @code{ControlPath} settings when initiating
4075@command{ssh} sessions.  @value{tramp} does this to fend off a stall
4076if a master session opened outside the Emacs session is no longer
4077open.  That is why @value{tramp} prompts for the password again even
4078if there is an @command{ssh} already open.
4079
4080@vindex tramp-ssh-controlmaster-options
4081Some @command{ssh} versions support a @code{ControlPersist} option,
4082which allows you to set the @code{ControlPath} provided the variable
4083@code{tramp-ssh-controlmaster-options} is customized as follows:
4084
4085@lisp
4086@group
4087(customize-set-variable
4088 'tramp-ssh-controlmaster-options
4089 (concat
4090   "-o ControlPath=/tmp/ssh-ControlPath-%%r@@%%h:%%p "
4091   "-o ControlMaster=auto -o ControlPersist=yes"))
4092@end group
4093@end lisp
4094
4095Note how "%r", "%h" and "%p" must be encoded as "%%r", "%%h" and
4096"%%p".
4097
4098@vindex tramp-use-ssh-controlmaster-options
4099If the @file{~/.ssh/config} is configured appropriately for the above
4100behavior, then any changes to @command{ssh} can be suppressed with
4101this @code{nil} setting:
4102
4103@lisp
4104(customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
4105@end lisp
4106
4107
4108@item
4109On multi-hop connections, @value{tramp} does not use @command{ssh}
4110@code{ControlMaster}
4111
4112In order to use the @code{ControlMaster} option, @value{tramp} must
4113check whether the @command{ssh} client supports this option.  This is
4114only possible on the local host, for the first hop.  @value{tramp}
4115does not use this option on proxy hosts.
4116
4117If you want to use this option also for the other hops, you must
4118configure @file{~/.ssh/config} on the proxy host:
4119
4120@example
4121@group
4122Host *
4123     ControlMaster	auto
4124     ControlPath	tramp.%C
4125     ControlPersist	no
4126@end group
4127@end example
4128
4129Check @command{man ssh_config} whether these options are supported on
4130your proxy host.
4131
4132
4133@item
4134@value{tramp} does not connect to Samba or MS Windows hosts running
4135SMB1 connection protocol.
4136
4137@vindex tramp-smb-options
4138Recent versions of @command{smbclient} do not support old connection
4139protocols by default.  In order to connect to such a host, add a
4140respective option:
4141
4142@lisp
4143(add-to-list 'tramp-smb-options "client min protocol=NT1")
4144@end lisp
4145
4146@strong{Note} that using a deprecated connection protocol raises
4147security problems, you should do it only if absolutely necessary.
4148
4149
4150@item
4151File name completion does not work with @value{tramp}
4152
4153@acronym{ANSI} escape sequences from the remote shell may cause errors
4154in @value{tramp}'s parsing of remote buffers.
4155
4156To test if this is the case, open a remote shell and check if the output
4157of @command{ls} is in color.
4158
4159To disable @acronym{ANSI} escape sequences from the remote hosts,
4160disable @samp{--color=yes} or @samp{--color=auto} in the remote host's
4161@file{.bashrc} or @file{.profile}.  Turn this alias on and off to see
4162if file name completion works.
4163
4164@item
4165File name completion does not work in directories with large number of
4166files
4167
4168This may be related to globbing, which is the use of shell's ability
4169to expand wild card specifications, such as @samp{*.c}.  For
4170directories with large number of files, globbing might exceed the
4171shell's limit on length of command lines and hang.  @value{tramp} uses
4172globbing.
4173
4174To test if globbing hangs, open a shell on the remote host and then
4175run @command{ls -d * ..?* > /dev/null}.
4176
4177When testing, ensure the remote shell is the same shell
4178(@command{/bin/sh}, @command{ksh} or @command{bash}), that
4179@value{tramp} uses when connecting to that host.
4180
4181
4182@item
4183How to get notified after @value{tramp} completes file transfers?
4184
4185Make Emacs beep after reading from or writing to the remote host with
4186the following code in @file{~/.emacs}.
4187
4188@lisp
4189@group
4190(defadvice tramp-handle-write-region
4191  (after tramp-write-beep-advice activate)
4192  "Make @value{tramp} beep after writing a file."
4193  (interactive)
4194  (beep))
4195@end group
4196
4197@group
4198(defadvice tramp-handle-do-copy-or-rename-file
4199  (after tramp-copy-beep-advice activate)
4200  "Make @value{tramp} beep after copying a file."
4201  (interactive)
4202  (beep))
4203@end group
4204
4205@group
4206(defadvice tramp-handle-insert-file-contents
4207  (after tramp-insert-beep-advice activate)
4208  "Make @value{tramp} beep after inserting a file."
4209  (interactive)
4210  (beep))
4211@end group
4212@end lisp
4213
4214
4215@item
4216How to get a Visual Warning when working with @samp{root} privileges?
4217Host indication in the mode line?
4218
4219@cindex @value{tramp} theme
4220@vindex tramp-theme-face-remapping-alist
4221Install @file{tramp-theme} from GNU ELPA via Emacs' Package Manager.
4222Enable it via @kbd{M-x load-theme @key{RET} tramp @key{RET}}.  Further
4223customization is explained in user option
4224@code{tramp-theme-face-remapping-alist}.
4225
4226
4227@item
4228Remote host does not understand default options for directory listing
4229
4230Emacs computes the @command{dired} options based on the local host but
4231if the remote host cannot understand the same @command{ls} command,
4232then set them with a hook as follows:
4233
4234@lisp
4235@group
4236(add-hook
4237 'dired-before-readin-hook
4238 (lambda ()
4239   (when (file-remote-p default-directory)
4240     (setq dired-actual-switches "-al"))))
4241@end group
4242@end lisp
4243
4244
4245@item
4246Why is @file{~/.sh_history} on the remote host growing?
4247
4248@vindex tramp-histfile-override
4249@vindex HISTFILE@r{, environment variable}
4250@vindex HISTFILESIZE@r{, environment variable}
4251@vindex HISTSIZE@r{, environment variable}
4252Due to the remote shell saving tilde expansions triggered by
4253@value{tramp}, the history file is probably growing rapidly.
4254@value{tramp} can suppress this behavior with the user option
4255@code{tramp-histfile-override}.  When set to @code{t}, environment
4256variable @env{HISTFILE} is unset, and environment variables
4257@env{HISTFILESIZE} and @env{HISTSIZE} are set to 0.  Don't use this
4258with @command{bash} 5.0.0.  There is a bug in @command{bash} which
4259lets @command{bash} die.
4260
4261Alternatively, @code{tramp-histfile-override} could be a string.
4262Environment variable @env{HISTFILE} is set to this file name then.  Be
4263careful when setting to @file{/dev/null}; this might result in
4264undesired results when using @command{bash} as remote shell.
4265
4266Another approach is to disable @value{tramp}'s handling of the
4267@env{HISTFILE} at all by setting @code{tramp-histfile-override} to
4268@code{nil}.  In this case, saving history could be turned off by
4269putting this shell code in @file{.bashrc} or @file{.kshrc}:
4270
4271@example
4272@group
4273if [ -f $HOME/.sh_history ] ; then
4274   /bin/rm $HOME/.sh_history
4275fi
4276if [ "$@{HISTFILE-unset@}" != "unset" ] ; then
4277   unset HISTFILE
4278fi
4279if [ "$@{HISTSIZE-unset@}" != "unset" ] ; then
4280   unset HISTSIZE
4281fi
4282@end group
4283@end example
4284
4285For @option{ssh}-based method, add the following line to your
4286@file{~/.ssh/environment}:
4287
4288@example
4289HISTFILE=/dev/null
4290@end example
4291
4292
4293@item
4294How to shorten long file names when typing in @value{tramp}?
4295
4296Adapt several of these approaches to reduce typing.  If the full name
4297is @file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, then:
4298
4299@enumerate
4300
4301@item
4302Use simplified syntax:
4303
4304If you always apply the default method (@pxref{Default Method}), you
4305could use the simplified @value{tramp} syntax (@pxref{Change file name
4306syntax}):
4307
4308@lisp
4309@group
4310(customize-set-variable 'tramp-default-method "ssh")
4311(tramp-change-syntax 'simplified)
4312@end group
4313@end lisp
4314
4315The reduced typing: @kbd{C-x C-f
4316@code{@value{prefix}news@@news.my.domain@value{postfix}/opt/news/etc}
4317@key{RET}}.
4318
4319@item
4320Use default values for method name and user name:
4321
4322You can define default methods and user names for hosts,
4323(@pxref{Default Method}, @pxref{Default User}):
4324
4325@lisp
4326@group
4327(custom-set-variables
4328 '(tramp-default-method "ssh")
4329 '(tramp-default-user "news"))
4330@end group
4331@end lisp
4332
4333The reduced typing: @kbd{C-x C-f
4334@trampfn{-,news.my.domain,/opt/news/etc} @key{RET}}.
4335
4336@strong{Note} that there are some useful shortcuts already.  Accessing
4337your local host as @samp{root} user, is possible just by @kbd{C-x C-f
4338@trampfn{su,,} @key{RET}}.
4339
4340@item
4341Use configuration options of the access method:
4342
4343Programs used for access methods already offer powerful configurations
4344(@pxref{Customizing Completion}).  For @option{ssh}, configure the
4345file @file{~/.ssh/config}:
4346
4347@example
4348@group
4349Host xy
4350     HostName news.my.domain
4351     User news
4352@end group
4353@end example
4354
4355The reduced typing: @kbd{C-x C-f @trampfn{ssh,xy,/opt/news/etc} @key{RET}}.
4356
4357Depending on the number of files in the directories, host names
4358completion can further reduce key strokes: @kbd{C-x C-f
4359@value{prefix}ssh@value{postfixhop}x @key{TAB}}.
4360
4361@item
4362Use environment variables to expand long strings
4363
4364For long file names, set up environment variables that are expanded in
4365the minibuffer.  Environment variables are set either outside Emacs or
4366inside Emacs with Lisp:
4367
4368@lisp
4369(setenv "xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")
4370@end lisp
4371
4372The reduced typing: @kbd{C-x C-f $xy @key{RET}}.
4373
4374@strong{Note} that file name cannot be edited here because the
4375environment variables are not expanded during editing in the
4376minibuffer.
4377
4378@item Define own keys:
4379
4380Redefine another key sequence in Emacs for @kbd{C-x C-f}:
4381
4382@lisp
4383@group
4384(global-set-key
4385 [(control x) (control y)]
4386 (lambda ()
4387   (interactive)
4388   (find-file
4389    (read-file-name
4390     "Find @value{tramp} file: "
4391     "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))))
4392@end group
4393@end lisp
4394
4395Simply typing @kbd{C-x C-y} would prepare minibuffer editing of file
4396name.
4397
4398See @uref{https://www.emacswiki.org/emacs/TrampMode, the Emacs Wiki}
4399for a more comprehensive example.
4400
4401@item
4402Define own abbreviation (1):
4403
4404Abbreviation list expansion can be used to reduce typing long file names:
4405
4406@lisp
4407@group
4408(add-to-list
4409 'directory-abbrev-alist
4410 '("^/xy" . "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
4411@end group
4412@end lisp
4413
4414The reduced typing: @kbd{C-x C-f /xy @key{RET}}.
4415
4416@strong{Note} that file name cannot be edited here because the
4417abbreviations are not expanded during editing in the minibuffer.
4418Furthermore, the abbreviation is not expanded during @key{TAB}
4419completion.
4420
4421@item
4422Define own abbreviation (2):
4423
4424The @code{abbrev-mode} gives additional flexibility for editing in the
4425minibuffer:
4426
4427@lisp
4428@group
4429(define-abbrev-table 'my-tramp-abbrev-table
4430  '(("xy" "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}")))
4431@end group
4432
4433@group
4434(add-hook
4435 'minibuffer-setup-hook
4436 (lambda ()
4437   (abbrev-mode 1)
4438   (setq local-abbrev-table my-tramp-abbrev-table)))
4439@end group
4440
4441@group
4442(defadvice minibuffer-complete
4443  (before my-minibuffer-complete activate)
4444  (expand-abbrev))
4445@end group
4446
4447@group
4448;; If you use partial-completion-mode
4449(defadvice PC-do-completion
4450  (before my-PC-do-completion activate)
4451  (expand-abbrev))
4452@end group
4453@end lisp
4454
4455The reduced typing: @kbd{C-x C-f xy @key{TAB}}.
4456
4457The minibuffer expands for further editing.
4458
4459@item Use bookmarks:
4460
4461Use bookmarks to save @value{tramp} file names.
4462@ifinfo
4463@pxref{Bookmarks, , , emacs}.
4464@end ifinfo
4465
4466Upon visiting a location with @value{tramp}, save it as a bookmark with
4467@kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{set}}.
4468
4469To revisit that bookmark:
4470@kbd{@key{menu-bar} @key{edit} @key{bookmarks} @key{jump}}.
4471
4472@item Use recent files:
4473
4474@file{recentf} remembers visited places.
4475@ifinfo
4476@pxref{File Conveniences, , , emacs}.
4477@end ifinfo
4478
4479Keep remote file names in the recent list without have to check for
4480their accessibility through remote access:
4481
4482@lisp
4483(recentf-mode 1)
4484@end lisp
4485
4486Reaching recently opened files: @kbd{@key{menu-bar} @key{file}
4487@key{Open Recent}}.
4488
4489@item Use filecache:
4490
4491Since @file{filecache} remembers visited places, add the remote
4492directory to the cache:
4493
4494@lisp
4495@group
4496(with-eval-after-load 'filecache
4497  (file-cache-add-directory
4498    "@trampfn{ssh,news@@news.my.domain,/opt/news/etc/}"))
4499@end group
4500@end lisp
4501
4502Then use directory completion in the minibuffer with @kbd{C-x C-f
4503C-@key{TAB}}.
4504
4505@item Use bbdb:
4506
4507@file{bbdb} has a built-in feature for Ange FTP files, which also
4508works for @value{tramp} file names.
4509@ifinfo
4510@pxref{bbdb-ftp, Storing FTP sites in the BBDB, , bbdb}.
4511@end ifinfo
4512
4513Load @file{bbdb} in Emacs:
4514
4515@lisp
4516@group
4517(require 'bbdb)
4518(bbdb-initialize)
4519@end group
4520@end lisp
4521
4522Create a BBDB entry with @kbd{M-x bbdb-create-ftp-site @key{RET}}.
4523Then specify a method and user name where needed.  Examples:
4524
4525@example
4526@group
4527@kbd{M-x bbdb-create-ftp-site @key{RET}}
4528@b{Ftp Site:} news.my.domain @key{RET}
4529@b{Ftp Directory:} /opt/news/etc/ @key{RET}
4530@b{Ftp Username:} ssh@value{postfixhop}news @key{RET}
4531@b{Company:} @key{RET}
4532@b{Additional Comments:} @key{RET}
4533@end group
4534@end example
4535
4536In BBDB buffer, access an entry by pressing the key @kbd{F}.
4537
4538@end enumerate
4539
4540Thanks to @value{tramp} users for contributing to these recipes.
4541
4542@item
4543Why saved multi-hop file names do not work in a new Emacs session?
4544
4545When saving ad-hoc multi-hop @value{tramp} file names (@pxref{Ad-hoc
4546multi-hops}) via bookmarks, recent files, filecache, bbdb, or another
4547package, use the full ad-hoc file name including all hops, like
4548@file{@trampfn{ssh,bird@@bastion|ssh@value{postfixhop}news.my.domain,/opt/news/etc}}.
4549
4550Alternatively, when saving abbreviated multi-hop file names
4551@file{@trampfn{ssh,news@@news.my.domain,/opt/news/etc}}, the user
4552option @code{tramp-save-ad-hoc-proxies} must be set non-@code{nil}
4553value.
4554
4555
4556@item
4557How to connect to a remote Emacs session using @value{tramp}?
4558
4559Configure Emacs Client
4560@ifinfo
4561(@pxref{Emacs Server, , , emacs}).
4562@end ifinfo
4563
4564Then on the remote host, start the Emacs Server:
4565
4566@lisp
4567@group
4568(require 'server)
4569(setq server-host (system-name)
4570      server-use-tcp t)
4571(server-start)
4572@end group
4573@end lisp
4574
4575If @code{(system-name)} of the remote host cannot be resolved on the
4576local host, use IP address instead.
4577
4578Copy from the remote host the resulting file
4579@file{~/.emacs.d/server/server} to the local host, to the same
4580location.
4581
4582Then start Emacs Client from the command line:
4583
4584@example
4585emacsclient @trampfn{ssh,user@@host,/file/to/edit}
4586@end example
4587
4588@code{user} and @code{host} refer to the local host.
4589
4590To make Emacs Client an editor for other programs, use a wrapper
4591script @file{emacsclient.sh}:
4592
4593@example
4594@group
4595#!/bin/sh
4596emacsclient @trampfn{ssh,$(whoami)@@$(hostname --fqdn),$1}
4597@end group
4598@end example
4599
4600@vindex EDITOR@r{, environment variable}
4601Then change the environment variable @env{EDITOR} to point to the
4602wrapper script:
4603
4604@example
4605export EDITOR=/path/to/emacsclient.sh
4606@end example
4607
4608
4609@item
4610How to determine whether a buffer is remote?
4611
4612The buffer-local variable @code{default-directory} tells this.  If the
4613form @code{(file-remote-p default-directory)} returns non-@code{nil},
4614the buffer is remote.  See the optional arguments of
4615@code{file-remote-p} for determining details of the remote connection.
4616
4617
4618@item
4619How to save files when a remote host isn't reachable anymore?
4620
4621If the local machine Emacs is running on changes its network
4622integration, remote hosts could become unreachable.  This happens for
4623example, if the local machine is moved between your office and your
4624home without restarting Emacs.
4625
4626In such cases, the command @code{tramp-rename-files} can be used to
4627alter remote buffers’ method, host, and/or directory names.  This
4628permits saving their contents in the same location via another network
4629path, or somewhere else entirely (including locally).  @pxref{Renaming
4630remote files}.
4631
4632
4633@item
4634I get a warning @samp{Tramp has been compiled with Emacs a.b, this is Emacs c.d}
4635
4636@value{tramp} comes with compatibility code for different Emacs
4637versions.  When you see this warning, you don't use the Emacs built-in
4638version of @value{tramp}.  In case you have installed @value{tramp}
4639from GNU ELPA, you must delete and reinstall it.
4640@ifset installchapter
4641In case you have installed it from its Git repository, @ref{Recompilation}.
4642@end ifset
4643
4644
4645@item
4646How to disable other packages from calling @value{tramp}?
4647
4648There are packages that call @value{tramp} without the user ever
4649entering a remote file name.  Even without applying a remote file
4650syntax, some packages enable @value{tramp} on their own.  How can users
4651disable such features.
4652
4653@itemize @minus
4654@item
4655@file{ido.el}
4656
4657Disable @value{tramp} file name completion:
4658
4659@lisp
4660(customize-set-variable 'ido-enable-tramp-completion nil)
4661@end lisp
4662
4663@item
4664@file{rlogin.el}
4665
4666Disable remote directory tracking mode:
4667
4668@lisp
4669(rlogin-directory-tracking-mode -1)
4670@end lisp
4671@end itemize
4672
4673
4674@item
4675How to disable @value{tramp}?
4676
4677@itemize @minus
4678@item
4679To keep Ange FTP as default the remote files access package, set this
4680in @file{.emacs}:
4681
4682@lisp
4683(customize-set-variable 'tramp-default-method "ftp")
4684@end lisp
4685
4686If you want to enable Ange FTP's syntax, add the following form:
4687
4688@lisp
4689(tramp-change-syntax 'simplified)
4690@end lisp
4691
4692@item
4693@vindex tramp-mode
4694To disable both @value{tramp} (and Ange FTP), set @code{tramp-mode} to
4695@code{nil} in @file{.emacs}.  @strong{Note}, that we don't use
4696@code{customize-set-variable}, in order to avoid loading @value{tramp}.
4697
4698@lisp
4699(setq tramp-mode nil)
4700@end lisp
4701
4702@item
4703@vindex tramp-ignored-file-name-regexp
4704To deactivate @value{tramp} for some look-alike remote file names, set
4705@code{tramp-ignored-file-name-regexp} to a proper regexp in
4706@file{.emacs}.  @strong{Note}, that we don't use
4707@code{customize-set-variable}, in order to avoid loading
4708@value{tramp}.
4709
4710@lisp
4711(setq tramp-ignored-file-name-regexp "\\`/ssh:example\\.com:")
4712@end lisp
4713
4714This is needed, if you mount for example a virtual file system on your
4715local host's root directory as @file{/ssh:example.com:}.
4716
4717@item
4718To unload @value{tramp}, type @kbd{M-x tramp-unload-tramp @key{RET}}.
4719Unloading @value{tramp} resets Ange FTP plugins also.
4720@end itemize
4721@end itemize
4722
4723
4724@c For the developer
4725@node Files directories and localnames
4726@chapter How file names, directories and localnames are mangled and managed
4727
4728@menu
4729* Localname deconstruction::    Splitting a localname into its component parts.
4730* External packages::           Integrating with external Lisp packages.
4731@end menu
4732
4733
4734@node Localname deconstruction
4735@section Splitting a localname into its component parts
4736
4737@value{tramp} package redefines lisp functions
4738@code{file-name-directory} and @code{file-name-nondirectory} to
4739accommodate the unique file naming syntax that @value{tramp} requires.
4740
4741The replacements dissect the file name, use the original handler for
4742the localname, take that result, and then re-build the @value{tramp}
4743file name.  By relying on the original handlers for localnames,
4744@value{tramp} benefits from platform specific hacks to the original
4745handlers.
4746
4747
4748@node External packages
4749@section Integrating with external Lisp packages
4750@subsection File name completion.
4751
4752@vindex non-essential
4753Sometimes, it is not convenient to open a new connection to a remote
4754host, including entering the password and alike.  For example, this is
4755nasty for packages providing file name completion.  Such a package
4756could signal to @value{tramp}, that they don't want it to establish a
4757new connection.  Use the variable @code{non-essential} temporarily and
4758bind it to non-@code{nil} value.
4759
4760@lisp
4761@group
4762(let ((non-essential t))
4763  @dots{})
4764@end group
4765@end lisp
4766
4767
4768@subsection File attributes cache.
4769
4770Keeping a local cache of remote file attributes in sync with the
4771remote host is a time-consuming operation.  Flushing and re-querying
4772these attributes can tax @value{tramp} to a grinding halt on busy
4773remote servers.
4774
4775To get around these types of slow-downs in @value{tramp}'s
4776responsiveness, set the @code{process-file-side-effects} to @code{nil}
4777to stop @value{tramp} from flushing the cache.  This is helpful in
4778situations where callers to @code{process-file} know there are no file
4779attribute changes.  The let-bind form to accomplish this:
4780
4781@lisp
4782@group
4783(let (process-file-side-effects)
4784  @dots{})
4785@end group
4786@end lisp
4787
4788For asynchronous processes, @value{tramp} uses a process sentinel to
4789flush file attributes cache.  When callers to @code{start-file-process}
4790know beforehand no file attribute changes are expected, then the
4791process sentinel should be set to the default state.  In cases where
4792the caller defines its own process sentinel, @value{tramp}'s process
4793sentinel is overwritten.  The caller can still flush the file
4794attributes cache in its process sentinel with this code:
4795
4796@lisp
4797@group
4798(unless (memq (process-status proc) '(run open))
4799  (dired-uncache remote-directory))
4800@end group
4801@end lisp
4802
4803Since @value{tramp} traverses subdirectories starting with the
4804root-directory, it is most likely sufficient to make the
4805@code{default-directory} of the process buffer as the root directory.
4806
4807
4808@node Traces and Profiles
4809@chapter How to Customize Traces
4810@vindex tramp-verbose
4811
4812@value{tramp} messages are raised with verbosity levels ranging from 0
4813to 10.  @value{tramp} does not display all messages; only those with a
4814verbosity level less than or equal to @code{tramp-verbose}.
4815
4816The verbosity levels are
4817
4818          @w{ 0}  silent (no @value{tramp} messages at all)
4819@*@indent @w{ 1}  errors
4820@*@indent @w{ 2}  warnings
4821@*@indent @w{ 3}  connection to remote hosts (default verbosity)
4822@*@indent @w{ 4}  activities
4823@*@indent @w{ 5}  internal
4824@*@indent @w{ 6}  sent and received strings
4825@*@indent @w{ 7}  file caching
4826@*@indent @w{ 8}  connection properties
4827@*@indent @w{ 9}  test commands
4828@*@indent @w{10}  traces (huge)
4829
4830With @code{tramp-verbose} greater than or equal to 4, messages are
4831also written to a @value{tramp} debug buffer.  Such debug buffers are
4832essential to bug and problem analyses.  For @value{tramp} bug reports,
4833set the @code{tramp-verbose} level to 6 (@pxref{Bug Reports}).
4834
4835The debug buffer is in
4836@ifinfo
4837@ref{Outline Mode, , , emacs}.
4838@end ifinfo
4839@ifnotinfo
4840Outline Mode.
4841@end ifnotinfo
4842In this buffer, messages can be filtered by their level.  To see
4843messages up to verbosity level 5, enter @kbd{C-u 6 C-c C-q}.
4844@ifinfo
4845Other navigation keys are described in
4846@ref{Outline Visibility, , , emacs}.
4847@end ifinfo
4848
4849@value{tramp} handles errors internally.  But to get a Lisp backtrace,
4850both the error and the signal have to be set as follows:
4851
4852@lisp
4853@group
4854(setq debug-on-error t
4855      debug-on-signal t)
4856@end group
4857@end lisp
4858
4859If @code{tramp-verbose} is greater than or equal to 10, Lisp
4860backtraces are also added to the @value{tramp} debug buffer in case of
4861errors.
4862
4863To enable stepping through @value{tramp} function call traces, they
4864have to be specifically enabled as shown in this code:
4865
4866@lisp
4867@group
4868(require 'trace)
4869(dolist (elt (all-completions "tramp-" obarray 'functionp))
4870  (trace-function-background (intern elt)))
4871(untrace-function 'tramp-read-passwd)
4872@end group
4873@end lisp
4874
4875The buffer @file{*trace-output*} contains the output from the function
4876call traces.  Disable @code{tramp-read-passwd} to stop password
4877strings from being written to @file{*trace-output*}.
4878
4879
4880@node GNU Free Documentation License
4881@appendix GNU Free Documentation License
4882@include doclicense.texi
4883
4884
4885@node Function Index
4886@unnumbered Function Index
4887@printindex fn
4888
4889
4890@node Variable Index
4891@unnumbered Variable Index
4892@printindex vr
4893
4894
4895@node Concept Index
4896@unnumbered Concept Index
4897@printindex cp
4898
4899@bye
4900
4901@c TODO
4902@c
4903@c * Say something about the .login and .profile files of the remote
4904@c   shells.
4905@c * Explain how tramp.el works in principle: open a shell on a remote
4906@c   host and then send commands to it.
4907@c * Consistent small or capitalized words especially in menus.
4908