1、新建FTP账号
升级
1
yum update //升级软件,非必要
创建名称为sftp的SFTP用户组
1
groupadd sftp
创建用户
1
useradd -G sftp -s /sbin/nologin 【username 】
- 创建密码
1 passwd 【username】
- 修改sshd配置文件
1
vim /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
26
27
28
29
30
31
32#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
# override default of no subsystems
#下面这行注释掉
#Subsystem sftp /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
# 加入
Subsystem sftp internal-sftp
# 以下需要添加在文件的最下方,否则root用户无法登录
Match Group sftp
X11Forwarding no
AllowTcpForwarding no
ChrootDirectory %h
ForceCommand internal-sftp
Match Group sftp 匹配sftp用户组中的用户
ChrootDirectory %h 只能访问默认的用户目录(自己的目录),例如 /home/test
2、配置FTP账号访问路径
1 | chown root:sftp /home/【username 】 |
3、重启sshd服务
1 | systemctl restart sshd |
4、Nginx配置站点信息
第一种,直接通过IP&端口访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17server {
listen 8081;
server_name localhost;
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/【username 】/upload;
index index.html index.htm;
autoindex on; #显示索引
autoindex_exact_size off; #显示大小
autoindex_localtime on; #显示时间
}
}第二种,通过域名访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17server {
listen 80;
server_name xxx.域名.com;
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/【username 】/upload;
index index.html index.htm;
autoindex on; #显示索引
autoindex_exact_size off; #显示大小
autoindex_localtime on; #显示时间
}
}