在 Ubuntu 上开启 SFTP 服务,通常是通过 OpenSSH Server 来提供的(SFTP 基于 SSH)。下面是常见且正确的做法:
which sshd
或
systemctl status ssh
sudo apt update
sudo apt install openssh-server
sudo systemctl start ssh
sudo systemctl enable ssh
sudo systemctl status ssh
看到 active (running) 即说明 SFTP 已可用。
sftp 用户名@localhost
sftp 用户名@服务器IP
/etc/ssh/sshd_config
SFTP 默认已启用(一般包含):
Subsystem sftp /usr/lib/openssh/sftp-server
在 /etc/ssh/sshd_config 末尾添加:
Match User sftpuser
PasswordAuthentication yes
ChrootDirectory /home/sftpuser
ForceCommand internal-sftp
AllowTcpForwarding no
然后重启 SSH:
sudo systemctl restart ssh
如果启用了防火墙:
sudo ufw allow ssh
(SSH 默认端口 22,SFTP 共用)
ChrootDirectory 必须属 root 且 755如果你是想:
可以告诉我你的具体需求,我可以给你更针对性的配置。