如何在 Linux 上设置 openSSH SFTP 服务器?

Emi*_*ano 10 linux openssh sftp

我想配置 sftp-server 来共享一个目录,但我不知道如何修改/etc/ssh/sshd_config.

我的要求是:

1) 登录不得使用证书,只能使用密码(即授权使用密码方式)

2)我想用用户:ftp,密码:foo 和共享目录/home/ftp 登录。

3)我有一个应用程序,它不时需要从服务器下载文件,我不需要使用完整的客户端登录。

到目前为止,我在 /etc/ssh/sshd_config 中添加了以下几行:

Protocol 2
Subsystem sftp /usr/libexec/sftp-server
Match User ftp
   ForceCommand internal-sftp
   ChrootDirectory /home/ftp
Run Code Online (Sandbox Code Playgroud)

其他一切都被评论了。

/home/ftp 目前是一个空目录。

如果我尝试使用 root 凭据下载文件,则访问有效,但如果我使用 ftp 凭据,则访问无效。我需要设置登录shell吗?我需要以某种方式填充 /home/ftp 吗?

编辑:这是我的 sshd 日志:

subsystem request for sftp
debug1: subsystem: exec() internal-sftp
debug1: Forced command (config) 'internal-sftp '
debug2: fd 3 setting TCP_NODELAY
debug2: fd 9 setting O_NONBLOCK
debug2: fd 8 setting O_NONBLOCK
debug1: Received SIGCHLD.
debug1: session_by_pid: pid 17613
debug1: session_exit_message: session 0 channel 0 pid 17613
debug2: channel 0: request exit-status confirm 0
debug1: session_exit_message: release channel 0
debug2: channel 0: write failed
debug2: channel 0: close_write
debug2: channel 0: send eow
debug2: channel 0: output open -> closed
debug2: channel 0: read<=0 rfd 9 len 0
debug2: channel 0: read failed
debug2: channel 0: close_read
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: send close
debug2: notify_done: reading
debug3: channel 0: will not send data after close
debug3: channel 0: will not send data after close
User child is on pid 17611
debug3: mm_request_receive entering
Run Code Online (Sandbox Code Playgroud)

* 客户端挂在这里(直到发生超时) *

请再次注意,如果我以“root”身份登录,文件将正确下载。如果我注释掉配置文件的最后三行(即该Match行和以下 2 行),它也能正确下载。

Dan*_*eck 7

您需要确保/home/ftproot该组拥有并且其他人没有写权限,例如chmod 0755. 您需要添加子目录ftp来添加文件。


您还需要internal-sftp子系统,否则您需要在以下位置提供适当的chroot环境/home/ftp

Subsystem sftp internal-sftp
Run Code Online (Sandbox Code Playgroud)

要禁止所有非密码类型的登录,请输入

ChallengeResponseAuthentication no
GSSAPIAuthentication no
PubkeyAuthentication no
Run Code Online (Sandbox Code Playgroud)

这些是默认激活的。