sftp的服务在sshd_config中配置,具体目录为/etc/ssh/sshd_config
一般情况下使用的是sftp-server。由BSD系统管理器提供sftp-server的命令如下:

  1. NAME
  2. sftp-server -- SFTP server subsystem
  3. SYNOPSIS
  4. sftp-server [-ehR] [-d start_directory] [-f log_facility] [-l log_level]
  5. [-P blacklisted_requests] [-p whitelisted_requests]
  6. [-u umask]
  7. sftp-server -Q protocol_feature
  8. DESCRIPTION
  9. sftp-server is a program that speaks the server side of SFTP protocol to
  10. stdout and expects client requests from stdin. sftp-server is not
  11. intended to be called directly, but from sshd(8) using the Subsystem
  12. option.
  13. Command-line flags to sftp-server should be specified in the Subsystem
  14. declaration. See sshd_config(5) for more information.
  15. Valid options are:
  16. -d start_directory
  17. specifies an alternate starting directory for users. The path-
  18. name may contain the following tokens that are expanded at run-
  19. time: %% is replaced by a literal '%', %d is replaced by the home
  20. directory of the user being authenticated, and %u is replaced by
  21. the username of that user. The default is to use the user's home
  22. directory. This option is useful in conjunction with the
  23. sshd_config(5) ChrootDirectory option.
  24. -e Causes sftp-server to print logging information to stderr instead
  25. of syslog for debugging.
  26. -f log_facility
  27. Specifies the facility code that is used when logging messages
  28. from sftp-server. The possible values are: DAEMON, USER, AUTH,
  29. LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
  30. The default is AUTH.
  31. -h Displays sftp-server usage information.
  32. -l log_level
  33. Specifies which messages will be logged by sftp-server. The pos-
  34. sible values are: QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG,
  35. DEBUG1, DEBUG2, and DEBUG3. INFO and VERBOSE log transactions
  36. that sftp-server performs on behalf of the client. DEBUG and
  37. DEBUG1 are equivalent. DEBUG2 and DEBUG3 each specify higher
  38. levels of debugging output. The default is ERROR.
  39. -P blacklisted_requests
  40. Specify a comma-separated list of SFTP protocol requests that are
  41. banned by the server. sftp-server will reply to any blacklisted
  42. request with a failure. The -Q flag can be used to determine the
  43. supported request types. If both a blacklist and a whitelist are
  44. specified, then the blacklist is applied before the whitelist.
  45. -p whitelisted_requests
  46. Specify a comma-separated list of SFTP protocol requests that are
  47. permitted by the server. All request types that are not on the
  48. whitelist will be logged and replied to with a failure message.
  49. Care must be taken when using this feature to ensure that
  50. requests made implicitly by SFTP clients are permitted.
  51. -Q protocol_feature
  52. Query protocol features supported by sftp-server. At present the
  53. only feature that may be queried is ``requests'', which may be
  54. used for black or whitelisting (flags -P and -p respectively).
  55. -R Places this instance of sftp-server into a read-only mode.
  56. Attempts to open files for writing, as well as other operations
  57. that change the state of the filesystem, will be denied.
  58. -u umask
  59. Sets an explicit umask(2) to be applied to newly-created files
  60. and directories, instead of the user's default mask.
  61. On some systems, sftp-server must be able to access /dev/log for logging
  62. to work, and use of sftp-server in a chroot configuration therefore
  63. requires that syslogd(8) establish a logging socket inside the chroot
  64. directory.

修改ssh的配置

  1. vim /etc/ssh/sshd_config
  2. #搜索Subsystem找到对应的行
  3. # Subsystem sftp /usr/libexec/openssh/sftp-server
  4. # 在其后面增加日志配置参数
  5. Subsystem sftp /usr/libexec/openssh/sftp-server -l DEBUG3 -f local5

修改rsyslog的配置

由上诉的sftp-server的命令帮助中可知,在某些系统上,sftp-server必须能够访问/dev/log才能进行日志记录,因此在chroot配置中使用sftp-server需要syslogd(8)在chroot目录内建立日志记录套接字。

  1. vim /etc/rsyslog.conf
  2. # 在最后一行增加如下配置
  3. auth,authpriv.*,local5.* /var/log/sftp.log

重启服务

  1. systemctl restart sshd
  2. systemctl restart rsyslog

查看日志

  1. #日志最终会记录到/var/log/sftp.log中。可以使用tailf,less,more等命令进行查看
  2. tailf /var/log/sftp.log