anonymous_enable=YES | 启用匿名用户的功能 |
---|---|
anon_umask=022 | 匿名用户所上传文件的权限掩码 |
anon_root=/var/ftp | 匿名用户默认登录目录 |
anon_upload_enable=YES | 允许上传文件 |
anon_mkdir_write_enable=YES | 允许创建目录 |
anon_other_write_enable=YES | 开放其他写入权限(删除、覆盖、重命名) |
anon_max_rate=0 | 限制最大传输速率(0为不限速,单位:byte/秒) |
实验准备:
1)服务器端安装vsftpd:
[root@vsftpd-server ~]# yum install vsftpd -y
Installed:
vsftpd.x86_64 0:3.0.2-21.el7
Complete!
[root@vsftpd-server ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@vsftpd-server ~]# systemctl start vsftpd
2)客户端安装ftp服务:
[root@client ~]# yum install ftp -y
Installed:
ftp.x86_64 0:0.17-67.el7
Complete!
3)客户端登录服务端vsftpd服务:
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
4)查看登录位置:
ftp> ls
227 Entering Passive Mode (172,25,5,10,72,14).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Jun 23 2016 pub
-rw-r--r-- 1 0 0 0 Aug 21 01:22 song.txt
226 Directory send OK.
5)服务端验证,是同一位置:
[root@vsftpd-server ~]# cd /var/ftp/
[root@vsftpd-server ftp]# ls
pub song.txt
1)服务端配置文件,允许上传:
[root@vsftpd-server ~]# vim /etc/vsftpd/vsftpd.conf
# 允许匿名用户上传
anon_upload_enable=YES
2)服务端目录文件系统允许写入:
[root@vsftpd-server ~]# cd /var/ftp/ #进入默认根
[root@vsftpd-server ftp]# ls
pub song.txt
[root@vsftpd-server ftp]# mkdir upload # 新建一个上传目录,更安全,不回混乱
[root@vsftpd-server ftp]# ll
total 0
drwxr-xr-x 2 root root 6 Jun 23 2016 pub
-rw-r--r-- 1 root root 0 Aug 21 09:22 song.txt
drwxr-xr-x 2 root root 6 Aug 21 10:50 upload
[root@vsftpd-server ftp]# chmod o+w upload/ # 给予其他人写权限
[root@vsftpd-server ftp]# ll
total 0
drwxr-xr-x 2 root root 6 Jun 23 2016 pub
-rw-r--r-- 1 root root 0 Aug 21 09:22 song.txt
drwxr-xrwx 2 root root 6 Aug 21 10:50 upload # 给予成功
3)服务端重启vsftpd服务:
[root@vsftpd-server ftp]# systemctl restart vsftpd
4)客户端测试,查看upload目录是否存在:
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (172,25,5,10,215,212).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Jun 23 2016 pub
-rw-r--r-- 1 0 0 0 Aug 21 01:22 song.txt
drwxr-xrwx 2 0 0 6 Aug 21 02:50 upload # 目录已经存在
5)进入上传目录上传文件:
ftp> cd upload # 进入上传目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,223,149).
150 Here comes the directory listing.
226 Directory send OK.
ftp> put anaconda-ks.cfg # 上传文件
local: anaconda-ks.cfg remote: anaconda-ks.cfg
227 Entering Passive Mode (172,25,5,10,212,69).
150 Ok to send data.
226 Transfer complete. # 上传成功
2050 bytes sent in 0.000478 secs (4288.70 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (172,25,5,10,155,89).
150 Here comes the directory listing.
-rw------- 1 14 50 2050 Aug 21 02:53 anaconda-ks.cfg # 上传成功
226 Directory send OK.
6)但是上传的文件无法下载:
ftp> ls
227 Entering Passive Mode (172,25,5,10,155,89).
150 Here comes the directory listing.
-rw------- 1 14 50 2050 Aug 21 02:53 anaconda-ks.cfg
226 Directory send OK.
ftp> get anaconda-ks.cfg
local: anaconda-ks.cfg remote: anaconda-ks.cfg
227 Entering Passive Mode (172,25,5,10,79,65).
550 Failed to open file. # 下载要有r权限,可读取保存
1)服务端配置文件,anon_umask=022:
[root@vsftpd-server ftp]# vim /etc/vsftpd/vsftpd.conf
anon_upload_enable=YES
anon_umask=022
2)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
3)客户端连接,重新上传:
ftp> put initial-setup-ks.cfg # 上传一个新文件
local: initial-setup-ks.cfg remote: initial-setup-ks.cfg
227 Entering Passive Mode (172,25,5,10,132,238).
150 Ok to send data.
226 Transfer complete.
2143 bytes sent in 0.00061 secs (3513.11 Kbytes/sec)
ftp> ls
227 Entering Passive Mode (172,25,5,10,42,247).
150 Here comes the directory listing.
-rw------- 1 14 50 2050 Aug 21 02:53 anaconda-ks.cfg
-rw-r--r-- 1 14 50 2143 Aug 21 03:04 initial-setup-ks.cfg # 上传的新文件
226 Directory send OK.
ftp> get initial-setup-ks.cfg # 可以下载了
local: initial-setup-ks.cfg remote: initial-setup-ks.cfg
227 Entering Passive Mode (172,25,5,10,92,251).
150 Opening BINARY mode data connection for initial-setup-ks.cfg (2143 bytes).
226 Transfer complete.
2143 bytes received in 0.000145 secs (14779.31 Kbytes/sec)
1)服务端配置文件,
[root@vsftpd-server ftp]# vim /etc/vsftpd/vsftpd.conf
# 可以创建目录
anon_mkdir_write_enable=YES
# 可以对文件删除,覆盖,重命名
anon_other_write_enable=YES
2)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
3)客户端连接,测试:
ftp> cd upload # 进入目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,92,190).
150 Here comes the directory listing.
-rw------- 1 14 50 2050 Aug 21 02:53 anaconda-ks.cfg
-rw-r--r-- 1 14 50 2143 Aug 21 03:04 initial-setup-ks.cfg
226 Directory send OK.
ftp> mkdir abc # 建立目录
257 "/upload/abc" created
ftp> delete anaconda-ks.cfg # 删除文件
250 Delete operation successful.
ftp> rename initial-setup-ks.cfg is # 文件重命名
350 Ready for RNTO.
250 Rename successful.
ftp> ls
227 Entering Passive Mode (172,25,5,10,123,134).
150 Here comes the directory listing.
drwxr-xr-x 2 14 50 6 Aug 21 03:10 abc # 操作成功
-rw-r--r-- 1 14 50 2143 Aug 21 03:04 is
226 Directory send OK.
用户进入某个目录时,弹出相应说明:
1)创建一个隐藏的信息文件:
[root@vsftpd-server ftp]# vim /var/ftp/upload/.message
welcome to song.upload
2)修改配置文件:
[root@vsftpd-server ftp]# vim /etc/vsftpd/vsftpd.conf
dirmessage_enable=YES
3)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
4)客户端测试:
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd upload # 进入目录
250-welcome to song.upload # 目录提示生效
250 Directory successfully changed.
local_enable=YES | 是否允许本地系统用户 |
---|---|
local_umask=022 | 本地用户上传文件的权限掩码 |
local_root=/var/ftp | 本地用户的FTP根目录 |
chroot_local_user=YES | 是否将用户的登录点禁锢在家目录(保护服务器安全) |
local_max_rate=0 | 限制最大传输速率 |
ftpd_banner=欢迎信息 | 用户登录的欢迎信息 |
userlist_enable=yes&userlist_deny=YES | 禁止/etc/vsftpd/user_list文件中的用户名登录FTP,黑名单 |
userlist_enable=yes&userlist_deny=NO | 仅允许/etc/vsftpd/user_list文件中的用户名登录FTP,白名单 |
ftpusers | 黑名单,高于前面两个的优先级,立即生效,都不用重启 |
实验准备:
1)建立两个本地用户,tom和daisy,设定密码:
[root@vsftpd-server ~]# useradd -s /sbin/nologin tom
[root@vsftpd-server ~]# passwd tom
Changing password for user tom.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@vsftpd-server ~]# useradd -s /sbin/nologin daisy
[root@vsftpd-server ~]# passwd daisy
Changing password for user daisy.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
1)首先测试没有设置前是否禁锢(没有):
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): daisy
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -a
227 Entering Passive Mode (172,25,5,10,208,121).
150 Here comes the directory listing.
drwx------ 3 1002 1002 101 Aug 21 01:53 .
drwxr-xr-x 6 0 0 54 Aug 21 03:32 ..
-rw-r--r-- 1 1002 1002 18 Jul 12 2016 .bash_logout
-rw-r--r-- 1 1002 1002 193 Jul 12 2016 .bash_profile
-rw-r--r-- 1 1002 1002 231 Jul 12 2016 .bashrc
drwxr-xr-x 4 1002 1002 39 May 14 02:24 .mozilla
-rw-r--r-- 1 1002 1002 2050 Aug 21 01:53 anaconda-ks.cfg
ftp> cd / # 可以切换到家目录下
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,106,170).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 14 02:28 1
lrwxrwxrwx 1 0 0 7 May 14 02:24 bin -> usr/bin
dr-xr-xr-x 3 0 0 4096 May 14 02:39 boot
drwxr-xr-x 21 0 0 3180 Aug 21 01:12 dev
drwxr-xr-x 141 0 0 12288 Aug 21 03:33 etc
drwxr-xr-x 6 0 0 54 Aug 21 03:32 home
lrwxrwxrwx 1 0 0 7 May 14 02:24 lib -> usr/lib
lrwxrwxrwx 1 0 0 9 May 14 02:24 lib64 -> usr/lib64
drwxr-xr-x 2 0 0 6 Mar 10 2016 media
drwxr-xr-x 2 0 0 6 Mar 10 2016 mnt
drwxr-xr-x 3 0 0 16 May 14 02:32 opt
dr-xr-xr-x 157 0 0 0 Aug 21 01:12 proc
dr-xr-x--- 18 0 0 4096 Aug 21 03:32 root
drwxr-xr-x 37 0 0 1160 Aug 21 01:14 run
lrwxrwxrwx 1 0 0 8 May 14 02:24 sbin -> usr/sbin
drwxr-xr-x 2 0 0 6 Mar 10 2016 srv
2)并且可以被下载(other有r权限的文件都可以被下载):
ftp> cd /etc/ssh/
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,200,13).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 242153 Sep 06 2016 moduli
-rw-r--r-- 1 0 0 2208 Sep 06 2016 ssh_config
-rw-r----- 1 0 999 227 May 14 02:38 ssh_host_ecdsa_key
-rw-r--r-- 1 0 0 162 May 14 02:38 ssh_host_ecdsa_key.pub
-rw-r----- 1 0 999 387 May 14 02:38 ssh_host_ed25519_key
-rw-r--r-- 1 0 0 82 May 14 02:38 ssh_host_ed25519_key.pub
-rw-r----- 1 0 999 1679 May 14 02:38 ssh_host_rsa_key
-rw-r--r-- 1 0 0 382 May 14 02:38 ssh_host_rsa_key.pub
-rw------- 1 0 0 4360 Aug 19 02:34 sshd_config
226 Directory send OK.
ftp> get ssh_config # ssh的配置文件被下载
local: ssh_config remote: ssh_config
227 Entering Passive Mode (172,25,5,10,67,236).
150 Opening BINARY mode data connection for ssh_config (2208 bytes).
226 Transfer complete.
2208 bytes received in 2.7e-05 secs (81777.78 Kbytes/sec)
3)客户端修改配置文件中的,禁锢选项:
[root@vsftpd-server ~]# vim /etc/vsftpd/vsftpd.conf
# chroot)
chroot_local_user=YES # 将用户的登录点禁锢在家目录
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
3)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
4)客户端测试(用户登录出现问题):
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): daisy
331 Please specify the password.
Password:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
421 Service not available, remote server has closed connection
原因:从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现还有写权限,就会报该错误。
5)在vsftpd.conf中新增allow_writeable_chroot=YES配置
[root@vsftpd-server ~]# vim /etc/vsftpd/vsftpd.conf
chroot_local_user=YES
allow_writeable_chroot=YES # 允许用户具有主目录写权限
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
6)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
7)测试:
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): daisy
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files. # 登录用户成功
ftp> ls -a
227 Entering Passive Mode (172,25,5,10,179,138).
150 Here comes the directory listing.
drwx------ 3 1002 1002 101 Aug 21 01:53 .
drwx------ 3 1002 1002 101 Aug 21 01:53 ..
-rw-r--r-- 1 1002 1002 18 Jul 12 2016 .bash_logout
-rw-r--r-- 1 1002 1002 193 Jul 12 2016 .bash_profile
-rw-r--r-- 1 1002 1002 231 Jul 12 2016 .bashrc
drwxr-xr-x 4 1002 1002 39 May 14 02:24 .mozilla
-rw-r--r-- 1 1002 1002 2050 Aug 21 01:53 anaconda-ks.cfg
226 Directory send OK.
ftp> cd / # 切换到更目录
250 Directory successfully changed.
ftp> ls # 现在的根目录就是家目录
227 Entering Passive Mode (172,25,5,10,109,168).
150 Here comes the directory listing.
-rw-r--r-- 1 1002 1002 2050 Aug 21 01:53 anaconda-ks.cfg
226 Directory send OK.
允许白名单中的用户随意切换目录。
1) 修改配置文件,开启白名单
[root@vsftpd-server ~]# vim /etc/vsftpd/vsftpd.conf
chroot_local_user=YES
allow_writeable_chroot=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
2)白名单中添加用户:
[root@vsftpd-server ~]# vim /etc/vsftpd/chroot_list # 一个新文件,之前没有
tom
3)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
4)测试daisy用户(不能):
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): daisy
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,57,206).
150 Here comes the directory listing.
-rw-r--r-- 1 1002 1002 2050 Aug 21 01:53 anaconda-ks.cfg
226 Directory send OK.
5)测试tom用户(可以切换):
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): tom
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd /
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,25,5,10,51,157).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 14 02:28 1
lrwxrwxrwx 1 0 0 7 May 14 02:24 bin -> usr/bin
dr-xr-xr-x 3 0 0 4096 May 14 02:39 boot
drwxr-xr-x 21 0 0 3180 Aug 21 01:12 dev
drwxr-xr-x 141 0 0 12288 Aug 21 03:33 etc
drwxr-xr-x 6 0 0 54 Aug 21 03:32 home
lrwxrwxrwx 1 0 0 7 May 14 02:24 lib -> usr/lib
lrwxrwxrwx 1 0 0 9 May 14 02:24 lib64 -> usr/lib64
drwxr-xr-x 2 0 0 6 Mar 10 2016 media
drwxr-xr-x 2 0 0 6 Mar 10 2016 mnt
防止使用root用户登录ftp,所以我们将root用户加入黑名单。
1)打开黑名单文件,写入daisy用户:
[root@vsftpd-server ~]# vim /etc/vsftpd/ftpusers
# 里面的用户都不能直接登录
# Users that are not allowed to login via ftp
root
bin
………………
daisy
2)直接测试(daisy用户不能登录,但是tom可以登录):
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): daisy
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp>
[root@client ~]# ftp 172.25.5.10
Connected to 172.25.5.10 (172.25.5.10).
220 (vsFTPd 3.0.2)
Name (172.25.5.10:root): tom
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
注意这里不需要重启服务器就可以生效。
pasv_enable=YES | 开启被动模式 |
---|---|
pasv_min_port=30000 | 端口起始点 |
pasv_max_port=35000 | 端口终止点 |
1)服务器端配置文件中写入:
[root@vsftpd-server ~]# vim /etc/vsftpd/vsftpd.conf
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=35000
2)重启服务器:
[root@vsftpd-server ftp]# systemctl restart vsftpd
3)tom用户家目录建立大文件,进行传输:
[root@vsftpd-server ~]# cd /home/tom/
[root@vsftpd-server tom]# dd if=/dev/zero of=./big.txt bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 1.72035 s, 610 MB/s
[root@vsftpd-server tom]# ls
big.txt
4)客户端下载测试:
ftp> ls
227 Entering Passive Mode (172,25,5,10,135,14).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1048576000 Aug 21 06:38 big.txt
226 Directory send OK.
ftp> get big.txt # 下载大文件
local: big.txt remote: big.txt
227 Entering Passive Mode (172,25,5,10,129,207).
150 Opening BINARY mode data connection for big.txt (1048576000 bytes).
226 Transfer complete.
1048576000 bytes received in 28.5 secs (36766.79 Kbytes/sec)
5)服务端查看连接端口(本地的30000-35000端口用来数据通信):
[root@vsftpd-server tom]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 172.25.5.10:21 172.25.5.1:45388 ESTABLISHED 2844/vsftpd
tcp6 0 0 172.25.5.10:34574 172.25.5.1:46079 TIME_WAIT -
tcp6 0 0 172.25.5.10:33231 172.25.5.1:48023 ESTABLISHED 2846/vsftpd