在 CentOS 上,SFTP 本身已经是加密的,不需要额外“再加密”。
SFTP(SSH File Transfer Protocol)底层走的是 SSH 协议,所有数据(包括账号密码/密钥、文件内容)都会自动加密传输。
下面我分几种常见场景说明,你可以按需查看。
只要你是使用 22 端口 + SSH 提供的 SFTP,就是加密的:
sftp user@服务器IP
✅ 加密内容:
无需额外配置。
yum install -y openssh-server
systemctl enable sshd
systemctl start sshd
编辑配置文件:
vim /etc/ssh/sshd_config
确保有以下内容(默认就有):
Subsystem sftp internal-sftp
重启 SSH:
systemctl restart sshd
ssh-keygen -t rsa -b 4096
ssh-copy-id user@服务器IP
vim /etc/ssh/sshd_config
PasswordAuthentication no
PubkeyAuthentication yes
systemctl restart sshd
✅ 这样即使有人抓包,也无法破解登录凭证。
useradd -m sftpuser
passwd sftpuser
vim /etc/ssh/sshd_config
追加:
Match User sftpuser
ChrootDirectory /home/sftpuser
ForceCommand internal-sftp
X11Forwarding no
AllowTcpForwarding no
chown root:root /home/sftpuser
chmod 755 /home/sftpuser
mkdir /home/sftpuser/upload
chown sftpuser:sftpuser /home/sftpuser/upload
✅ 用户只能 SFTP,不能登录系统
✅ 只能访问指定目录
SFTP 只保证 传输过程加密,不加密 服务器上的文件。
如果你需要:
可以使用:
gpgopenssl示例(GPG):
gpg -c file.txt
| 问题 | 答案 |
|---|---|
| SFTP 需要额外加密吗? | ❌ 不需要 |
| 可以用 SSL 证书吗? | ❌ SFTP 不是 FTP+SSL |
| SFTP = FTPS? | ❌ 完全不同 |
| 端口一定是 22 吗? | ✅ 默认是,可改 |
✅ 使用 SFTP(SSH)
✅ 禁用 root 登录
✅ 使用 SSH 密钥登录
✅ 限制用户 SFTP 权限
✅ 不改默认 22 端口(或配合防火墙)
如果你愿意,可以告诉我:
我可以给你一套 可直接用的完整配置方案。