github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/docs/content/sftp.md (about)

     1  ---
     2  title: "SFTP"
     3  description: "SFTP"
     4  date: "2017-02-01"
     5  ---
     6  
     7  <i class="fa fa-server"></i> SFTP
     8  ----------------------------------------
     9  
    10  SFTP is the [Secure (or SSH) File Transfer
    11  Protocol](https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol).
    12  
    13  The SFTP backend can be used with a number of different providers:
    14  
    15  * {{< provider name="C14" home="https://www.online.net/en/storage/c14-cold-storage" config="/sftp/#c14" >}}
    16  * {{< provider name="rsync.net" home="https://rsync.net/products/rclone.html" config="/sftp/#rsync-net" >}}
    17  
    18  SFTP runs over SSH v2 and is installed as standard with most modern
    19  SSH installations.
    20  
    21  Paths are specified as `remote:path`. If the path does not begin with
    22  a `/` it is relative to the home directory of the user.  An empty path
    23  `remote:` refers to the user's home directory.
    24  
    25  "Note that some SFTP servers will need the leading / - Synology is a
    26  good example of this. rsync.net, on the other hand, requires users to
    27  OMIT the leading /.
    28  
    29  Here is an example of making an SFTP configuration.  First run
    30  
    31      rclone config
    32  
    33  This will guide you through an interactive setup process.
    34  
    35  ```
    36  No remotes found - make a new one
    37  n) New remote
    38  s) Set configuration password
    39  q) Quit config
    40  n/s/q> n
    41  name> remote
    42  Type of storage to configure.
    43  Choose a number from below, or type in your own value
    44  [snip]
    45  XX / SSH/SFTP Connection
    46     \ "sftp"
    47  [snip]
    48  Storage> sftp
    49  SSH host to connect to
    50  Choose a number from below, or type in your own value
    51   1 / Connect to example.com
    52     \ "example.com"
    53  host> example.com
    54  SSH username, leave blank for current username, ncw
    55  user> sftpuser
    56  SSH port, leave blank to use default (22)
    57  port>
    58  SSH password, leave blank to use ssh-agent.
    59  y) Yes type in my own password
    60  g) Generate random password
    61  n) No leave this optional password blank
    62  y/g/n> n
    63  Path to unencrypted PEM-encoded private key file, leave blank to use ssh-agent.
    64  key_file>
    65  Remote config
    66  --------------------
    67  [remote]
    68  host = example.com
    69  user = sftpuser
    70  port =
    71  pass =
    72  key_file =
    73  --------------------
    74  y) Yes this is OK
    75  e) Edit this remote
    76  d) Delete this remote
    77  y/e/d> y
    78  ```
    79  
    80  This remote is called `remote` and can now be used like this:
    81  
    82  See all directories in the home directory
    83  
    84      rclone lsd remote:
    85  
    86  Make a new directory
    87  
    88      rclone mkdir remote:path/to/directory
    89  
    90  List the contents of a directory
    91  
    92      rclone ls remote:path/to/directory
    93  
    94  Sync `/home/local/directory` to the remote directory, deleting any
    95  excess files in the directory.
    96  
    97      rclone sync /home/local/directory remote:directory
    98  
    99  ### SSH Authentication ###
   100  
   101  The SFTP remote supports three authentication methods:
   102  
   103    * Password
   104    * Key file
   105    * ssh-agent
   106  
   107  Key files should be PEM-encoded private key files. For instance `/home/$USER/.ssh/id_rsa`.
   108  Only unencrypted OpenSSH or PEM encrypted files are supported.
   109  
   110  If you don't specify `pass` or `key_file` then rclone will attempt to contact an ssh-agent.
   111  
   112  You can also specify `key_use_agent` to force the usage of an ssh-agent. In this case
   113  `key_file` can also be specified to force the usage of a specific key in the ssh-agent.
   114  
   115  Using an ssh-agent is the only way to load encrypted OpenSSH keys at the moment.
   116  
   117  If you set the `--sftp-ask-password` option, rclone will prompt for a
   118  password when needed and no password has been configured.
   119  
   120  ### ssh-agent on macOS ###
   121  
   122  Note that there seem to be various problems with using an ssh-agent on
   123  macOS due to recent changes in the OS.  The most effective work-around
   124  seems to be to start an ssh-agent in each session, eg
   125  
   126      eval `ssh-agent -s` && ssh-add -A
   127  
   128  And then at the end of the session
   129  
   130      eval `ssh-agent -k`
   131  
   132  These commands can be used in scripts of course.
   133  
   134  ### Modified time ###
   135  
   136  Modified times are stored on the server to 1 second precision.
   137  
   138  Modified times are used in syncing and are fully supported.
   139  
   140  Some SFTP servers disable setting/modifying the file modification time after
   141  upload (for example, certain configurations of ProFTPd with mod_sftp). If you
   142  are using one of these servers, you can set the option `set_modtime = false` in
   143  your RClone backend configuration to disable this behaviour.
   144  
   145  <!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/sftp/sftp.go then run make backenddocs -->
   146  ### Standard Options
   147  
   148  Here are the standard options specific to sftp (SSH/SFTP Connection).
   149  
   150  #### --sftp-host
   151  
   152  SSH host to connect to
   153  
   154  - Config:      host
   155  - Env Var:     RCLONE_SFTP_HOST
   156  - Type:        string
   157  - Default:     ""
   158  - Examples:
   159      - "example.com"
   160          - Connect to example.com
   161  
   162  #### --sftp-user
   163  
   164  SSH username, leave blank for current username, ncw
   165  
   166  - Config:      user
   167  - Env Var:     RCLONE_SFTP_USER
   168  - Type:        string
   169  - Default:     ""
   170  
   171  #### --sftp-port
   172  
   173  SSH port, leave blank to use default (22)
   174  
   175  - Config:      port
   176  - Env Var:     RCLONE_SFTP_PORT
   177  - Type:        string
   178  - Default:     ""
   179  
   180  #### --sftp-pass
   181  
   182  SSH password, leave blank to use ssh-agent.
   183  
   184  - Config:      pass
   185  - Env Var:     RCLONE_SFTP_PASS
   186  - Type:        string
   187  - Default:     ""
   188  
   189  #### --sftp-key-file
   190  
   191  Path to PEM-encoded private key file, leave blank or set key-use-agent to use ssh-agent.
   192  
   193  - Config:      key_file
   194  - Env Var:     RCLONE_SFTP_KEY_FILE
   195  - Type:        string
   196  - Default:     ""
   197  
   198  #### --sftp-key-file-pass
   199  
   200  The passphrase to decrypt the PEM-encoded private key file.
   201  
   202  Only PEM encrypted key files (old OpenSSH format) are supported. Encrypted keys
   203  in the new OpenSSH format can't be used.
   204  
   205  - Config:      key_file_pass
   206  - Env Var:     RCLONE_SFTP_KEY_FILE_PASS
   207  - Type:        string
   208  - Default:     ""
   209  
   210  #### --sftp-key-use-agent
   211  
   212  When set forces the usage of the ssh-agent.
   213  
   214  When key-file is also set, the ".pub" file of the specified key-file is read and only the associated key is
   215  requested from the ssh-agent. This allows to avoid `Too many authentication failures for *username*` errors
   216  when the ssh-agent contains many keys.
   217  
   218  - Config:      key_use_agent
   219  - Env Var:     RCLONE_SFTP_KEY_USE_AGENT
   220  - Type:        bool
   221  - Default:     false
   222  
   223  #### --sftp-use-insecure-cipher
   224  
   225  Enable the use of insecure ciphers and key exchange methods. 
   226  
   227  This enables the use of the the following insecure ciphers and key exchange methods:
   228  
   229  - aes128-cbc
   230  - aes192-cbc
   231  - aes256-cbc
   232  - 3des-cbc
   233  - diffie-hellman-group-exchange-sha256
   234  - diffie-hellman-group-exchange-sha1
   235  
   236  Those algorithms are insecure and may allow plaintext data to be recovered by an attacker.
   237  
   238  - Config:      use_insecure_cipher
   239  - Env Var:     RCLONE_SFTP_USE_INSECURE_CIPHER
   240  - Type:        bool
   241  - Default:     false
   242  - Examples:
   243      - "false"
   244          - Use default Cipher list.
   245      - "true"
   246          - Enables the use of the aes128-cbc cipher and diffie-hellman-group-exchange-sha256, diffie-hellman-group-exchange-sha1 key exchange.
   247  
   248  #### --sftp-disable-hashcheck
   249  
   250  Disable the execution of SSH commands to determine if remote file hashing is available.
   251  Leave blank or set to false to enable hashing (recommended), set to true to disable hashing.
   252  
   253  - Config:      disable_hashcheck
   254  - Env Var:     RCLONE_SFTP_DISABLE_HASHCHECK
   255  - Type:        bool
   256  - Default:     false
   257  
   258  ### Advanced Options
   259  
   260  Here are the advanced options specific to sftp (SSH/SFTP Connection).
   261  
   262  #### --sftp-ask-password
   263  
   264  Allow asking for SFTP password when needed.
   265  
   266  If this is set and no password is supplied then rclone will:
   267  - ask for a password
   268  - not contact the ssh agent
   269  
   270  
   271  - Config:      ask_password
   272  - Env Var:     RCLONE_SFTP_ASK_PASSWORD
   273  - Type:        bool
   274  - Default:     false
   275  
   276  #### --sftp-path-override
   277  
   278  Override path used by SSH connection.
   279  
   280  This allows checksum calculation when SFTP and SSH paths are
   281  different. This issue affects among others Synology NAS boxes.
   282  
   283  Shared folders can be found in directories representing volumes
   284  
   285      rclone sync /home/local/directory remote:/directory --ssh-path-override /volume2/directory
   286  
   287  Home directory can be found in a shared folder called "home"
   288  
   289      rclone sync /home/local/directory remote:/home/directory --ssh-path-override /volume1/homes/USER/directory
   290  
   291  - Config:      path_override
   292  - Env Var:     RCLONE_SFTP_PATH_OVERRIDE
   293  - Type:        string
   294  - Default:     ""
   295  
   296  #### --sftp-set-modtime
   297  
   298  Set the modified time on the remote if set.
   299  
   300  - Config:      set_modtime
   301  - Env Var:     RCLONE_SFTP_SET_MODTIME
   302  - Type:        bool
   303  - Default:     true
   304  
   305  #### --sftp-md5sum-command
   306  
   307  The command used to read md5 hashes. Leave blank for autodetect.
   308  
   309  - Config:      md5sum_command
   310  - Env Var:     RCLONE_SFTP_MD5SUM_COMMAND
   311  - Type:        string
   312  - Default:     ""
   313  
   314  #### --sftp-sha1sum-command
   315  
   316  The command used to read sha1 hashes. Leave blank for autodetect.
   317  
   318  - Config:      sha1sum_command
   319  - Env Var:     RCLONE_SFTP_SHA1SUM_COMMAND
   320  - Type:        string
   321  - Default:     ""
   322  
   323  #### --sftp-skip-links
   324  
   325  Set to skip any symlinks and any other non regular files.
   326  
   327  - Config:      skip_links
   328  - Env Var:     RCLONE_SFTP_SKIP_LINKS
   329  - Type:        bool
   330  - Default:     false
   331  
   332  <!--- autogenerated options stop -->
   333  
   334  ### Limitations ###
   335  
   336  SFTP supports checksums if the same login has shell access and `md5sum`
   337  or `sha1sum` as well as `echo` are in the remote's PATH.
   338  This remote checksumming (file hashing) is recommended and enabled by default.
   339  Disabling the checksumming may be required if you are connecting to SFTP servers
   340  which are not under your control, and to which the execution of remote commands
   341  is prohibited.  Set the configuration option `disable_hashcheck` to `true` to
   342  disable checksumming.
   343  
   344  SFTP also supports `about` if the same login has shell
   345  access and `df` are in the remote's PATH. `about` will
   346  return the total space, free space, and used space on the remote
   347  for the disk of the specified path on the remote or, if not set,
   348  the disk of the root on the remote.
   349  `about` will fail if it does not have shell
   350  access or if `df` is not in the remote's PATH.
   351  
   352  Note that some SFTP servers (eg Synology) the paths are different for
   353  SSH and SFTP so the hashes can't be calculated properly.  For them
   354  using `disable_hashcheck` is a good idea.
   355  
   356  The only ssh agent supported under Windows is Putty's pageant.
   357  
   358  The Go SSH library disables the use of the aes128-cbc cipher by
   359  default, due to security concerns. This can be re-enabled on a
   360  per-connection basis by setting the `use_insecure_cipher` setting in
   361  the configuration file to `true`. Further details on the insecurity of
   362  this cipher can be found [in this paper]
   363  (http://www.isg.rhul.ac.uk/~kp/SandPfinal.pdf).
   364  
   365  SFTP isn't supported under plan9 until [this
   366  issue](https://github.com/pkg/sftp/issues/156) is fixed.
   367  
   368  Note that since SFTP isn't HTTP based the following flags don't work
   369  with it: `--dump-headers`, `--dump-bodies`, `--dump-auth`
   370  
   371  Note that `--timeout` isn't supported (but `--contimeout` is).
   372  
   373  
   374  ## C14 {#c14}
   375  
   376  C14 is supported through the SFTP backend.
   377  
   378  See [C14's documentation](https://www.online.net/en/storage/c14-cold-storage)
   379  
   380  ## rsync.net {#rsync-net}
   381  
   382  rsync.net is supported through the SFTP backend.
   383  
   384  See [rsync.net's documentation of rclone examples](https://www.rsync.net/products/rclone.html).