linux

如何使用SFTP进行文件共享

小樊
55
2025-08-16 01:40:26
栏目: 编程语言

使用SFTP进行文件共享需先安装配置服务器,再通过客户端连接操作,以下是具体步骤:

一、安装与配置SFTP服务器(Linux)

  1. 安装OpenSSH服务器
    • Debian/Ubuntu系统:
      sudo apt update && sudo apt install openssh-server
    • CentOS/RHEL系统:
      sudo yum install openssh-server
  2. 启动SSH服务
    sudo systemctl start sshd && sudo systemctl enable sshd
  3. 配置防火墙
    • Ubuntu(UFW):sudo ufw allow 22
    • CentOS(firewalld):sudo firewall-cmd --add-service=ssh --permanent && sudo firewall-cmd --reload
  4. (可选)限制用户权限
    编辑/etc/ssh/sshd_config,添加以下内容限制用户只能通过SFTP访问指定目录:
    Subsystem sftp internal-sftp  
    Match Group sftpusers  
        ChrootDirectory /path/to/shared_dir  
        ForceCommand internal-sftp  
        AllowTcpForwarding no  
    
    然后重启服务:sudo systemctl restart sshd

二、使用SFTP客户端连接与操作

1. 命令行客户端(推荐)

2. 图形化客户端(Windows/macOS)

三、安全注意事项

四、常见问题解决

通过以上步骤即可安全高效地使用SFTP完成文件共享。

0
看了该问题的人还看了