一、linux

  • FTP

    1
    2
    3
    4
    5
    yum install vsftpd -y

    touch ftp.sh

    chmod +x ftp.sh
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    name=nmk

    filePath=/sftp/$name
    lnPath=/files/sftp/$name

    #groupadd sftp

    echo create $name ....

    useradd -g sftp -s /sbin/nologin -M $name
    usermod -d $filePath $name

    #mkdir $filePath

    mkdir $lnPath
    mkdir $lnPath/cmpay

    ln -s $lnPath /sftp

    chown root:root $filePath
    chmod 755 $filePath

    chown $name:sftp $lnPath/cmpay
    chmod 755 $lnPath/cmpay


    echo "password" | passwd $name --stdin > /dev/null 2>&1
    echo $name >> /etc/vsftpd/chroot_list

    service vsftpd restart

    echo create $name success.
  • SFTP

    1
    2
    3
    touch sftp.sh

    chmod +x sftp.sh
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    name=nmk

    filePath=/sftp/$name/
    lnPath=/files/sftp/$name/

    #groupadd sftp

    echo create $name ....

    useradd -g sftp -s /sbin/nologin -M $name
    usermod -d $filePath $name

    #mkdir $filePath

    mkdir $lnPath
    mkdir $lnPath/cmpay

    ln -s $lnPath /sftp

    chown root:root $filePath
    chmod 755 $filePath

    chown $name:sftp $lnPath/cmpay
    chmod 755 $lnPath/cmpay


    echo "password" | passwd $name --stdin > /dev/null 2>&1

    echo create $name success.

    修改/etc/ssh/sshd_config配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    # override default of no subsystems
    #Subsystem sftp /usr/libexec/openssh/sftp-server

    Subsystem sftp internal-sftp

    # Example of overriding settings on a per-user basis
    #Match User anoncvs
    # X11Forwarding no
    # AllowTcpForwarding no
    # PermitTTY no
    # ForceCommand cvs server

    UseDNS no
    AddressFamily inet
    SyslogFacility AUTHPRIV
    PermitRootLogin yes
    PasswordAuthentication yes

    # #注意,以下要 放在 本文件的最后行,否则 root用户无法登陆
    Match Group sftp
    X11Forwarding no
    AllowTcpForwarding no

    ChrootDirectory %h
    ForceCommand internal-sftp

二、windows

  • FTP

    通过启用windows自带的IIS功能建立FTP

    image-20200107011735061

    添加FTP站点

    image-20200107012103410

    定义FTP名称和映射目录

    image-20200107231204818

    定义FTP的IP和端口

    image-20200107231240035

    如需不用账号访问,请勾选匿名.可在允许授权定义哪些用户可访问和读写权限

    image-20200107231403866

    FTP拓展
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #FTP用户隔离
    创建D:/FTP
    IIS中指定D:/FTP为ftp根目录
    在D:/FTP下建立localuser
    在localuser下建立jack和rose目录
    创建两个用户
    jack目录添加jack用户完全控制
    rose目录添加rose用户完全控制
    IIS授权规则>允许两个用户
    用户验证>基本验证启用 匿名禁用
    用户隔离>用户名目录(禁用全局虚拟目录)

    #此功能实现每个用户进入用户自己的目录
    #此场景适用于windows下多用户使用同一端口的FTP

1、进入链接下载最新 OpenSSH-Win64.zip,解压至D:\OpenSSH

2、打开cmd,进入安装目录cd D:\OpenSSH,执行命令:

1
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

3、设置服务自动启动并启动服务:

1
2
3
sc config sshd start= auto

net start sshd

服务安装完毕,默认端口是22,默认用户名密码为Window账户名和密码

配置文件会存放在C:\ProgramData\ssh\

主要配置文件为sshd_config

1
2
3
4
5
6
7
8
#此配置指定SFTP连接的根目录,如果默认注释则为windows的用户目录
ChrootDirectory D:\SFTP\

#密钥访问
PasswordAuthentication yes

#允许哪些用户访问
AllowUsers nmk

具体可参考sshd_config配置,此处只列举使用到的一部分

1
2
3
4
5
#window下SFTP目录配置
创建用户>管理用户>隶属于的组>删除users
右键D:\SFTP目录>权限>高级>禁用继承
只给nmk用户读写D:\SFTP文件夹权限
这样用户就访问不到系统目录,只能访问D:/SFTP目录了