今天早上一切都正常,但也许我的 SFTP 用户出了问题。在 FileZilla 上,我无法从 Virtualbox VM 下载文件,因此我决定重新启动 FileZilla 客户端,然后无法重新连接。
以下是我的配置/etc/ssh/sshd_config:
Subsystem sftp /usr/lib/openssh/sftp-server
Match group sftp
ChrootDirectory /var/www
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
FileZilla 输出:
Status: Connecting to 127.0.0.1...
Status: Using username "sftpuser".
Command: Pass: **********
Error: Could not connect to server
Status: Waiting to retry...
Status: Connecting to 127.0.0.1...
Response: fzSftp started, protocol_version=11
Command: open "[email protected]" 22
Status: Using username "sftpuser".
Command: Pass: **********
Error: Could not connect to server
PuTTY 输出:
$ sftp [email protected]
client_loop: send disconnect: Broken pipe
Connection closed
SSH 输出:
$ ls -lua
total 28
drwxr-xr-x 5 www-data www-data 4096 june 21 00:00 .
drwxr-xr-x 15 root root 4096 june 21 00:00 ..
drwxr-xr-x 27 www-data www-data 12288 june 21 00:00 foo
drwxrwxr-x 30 www-data www-data 4096 june 21 00:00 bar
drwxrwxr-x 27 www-data www-data 4096 june 21 00:00 baz
SSH 日志使用journalctl -u ssh | tail -n 12:
june 21 00:00:00 developer sshd[14508]: Accepted password for sftpuser from 10.0.2.2 port 54811 ssh2
june 21 00:00:00 developer sshd[14508]: pam_unix(sshd:session): session opened for user sftpuser(uid=1001) by (uid=0)
june 21 00:00:00 developer sshd[14508]: pam_unix(sshd:session): session closed for user sftpuser
june 21 00:00:00 developer sshd[14653]: Accepted password for sftpuser from 10.0.2.2 port 54816 ssh2
june 21 00:00:00 developer sshd[14653]: pam_unix(sshd:session): session opened for user sftpuser(uid=1001) by (uid=0)
june 21 00:00:00 developer sshd[14653]: pam_unix(sshd:session): session closed for user sftpuser
june 21 00:00:00 developer sshd[15041]: Accepted password for sftpuser from 10.0.2.2 port 54817 ssh2
june 21 00:00:00 developer sshd[15041]: pam_unix(sshd:session): session opened for user sftpuser(uid=1001) by (uid=0)
june 21 00:00:00 developer sshd[15041]: pam_unix(sshd:session): session closed for user sftpuser
june 21 00:00:00 developer sshd[15119]: Accepted password for sftpuser from 127.0.0.1 port 54046 ssh2
june 21 00:00:00 developer sshd[15119]: pam_unix(sshd:session): session opened for user sftpuser(uid=1001) by (uid=0)
june 21 00:00:00 developer sshd[15119]: pam_unix(sshd:session): session closed for user sftpuser
我认为这是一个权限问题,但我不知道该去哪里查找。你有什么想法吗?
编辑:我没有提到它,因为这对我来说很明显,但使用 SSH 与任何其他用户连接都在 PuTTY 上工作
谢谢 !
答案1
我决定在另一台虚拟机上重试创建 SFTP,因为我正在创建一个新的开发环境,并且遇到了同样的问题。我修复了这个问题,在 sftp 用户的主目录中授予了良好的权限,并创建了一个挂载文件夹来访问我的 /var/www
我遵循了本教程:https://gaelbillon.com/create-a-sftp-user-restricted-to-a-var-www-directory-on-ubuntu-debian/ 如果您遇到此问题,我建议您从头重试!