在CentOS上安装vsftpd

你在做什么?

我打算在CentOS上建立一个FTP服务器。考虑到安全性,我认为大多数情况下会选择被动模式进行设置,所以这次也选择了被动模式来搭建。

前提是一个已知的条件或假设,他影响或限制了后续的行动或思考。

操作系统

$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

网络

此次将使用AWS EC2进行构建,因此不需要进行iptables等设置。

建立或構建

安装

$ sudo yum install vsftpd

检查版本

$ vsftpd -v
vsftpd: version 3.0.2

你在哪里?

精灵在这里。

$ ll /usr/sbin/vsftpd 
-rwxr-xr-x. 1 root root 175480 10月 30  2018 /usr/sbin/vsftpd

这里有三个设定文件。

$ ll /etc/vsftpd/
合計 20
-rw-------. 1 root root  125 10月 30  2018 ftpusers
-rw-------. 1 root root  361 10月 30  2018 user_list
-rw-------. 1 root root 5116 10月 30  2018 vsftpd.conf
-rwxr--r--. 1 root root  338 10月 30  2018 vsftpd_conf_migrate.sh

文件在这里。

$ ll /usr/share/doc/vsftpd-3.0.2/
合計 160
-rw-r--r--. 1 root root  1392  2月  2  2008 AUDIT
-rw-r--r--. 1 root root  2908  2月  2  2008 BENCHMARKS
-rw-r--r--. 1 root root   822  3月 28  2012 BUGS
-rw-r--r--. 1 root root 18288  2月  2  2008 COPYING
-rw-r--r--. 1 root root 67038  9月 18  2012 Changelog
(略)

启动服务

安装之后当然没有启动。

$ sudo systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

启动。

$ sudo systemctl start vsftpd

$ sudo systemctl status vsftpd
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 水 2019-09-04 06:28:35 UTC; 4s ago
  Process: 8259 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 8260 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─8260 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

 9月 04 06:28:35 ip-192-168-2-251.ap-northeast-1.compute.internal systemd[1]: Starting Vsftpd ftp daemon...
 9月 04 06:28:35 ip-192-168-2-251.ap-northeast-1.compute.internal systemd[1]: Started Vsftpd ftp daemon.

请将FTP服务器设置为自动启动。

$ sudo systemctl is-enabled vsftpd
disabled

启用 huà)

$ sudo systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

为避免遗漏,我想确认一下。

$ sudo systemctl is-enabled vsftpd
enabled

直接使用

默认行为

如果网络是开放的,就可以直接匿名访问。

# 匿名FTPサーバーの設定
anonymous_enable=YES

比如,当从外部访问时,可以使用“匿名”用户进行访问。

$ ftp {FTP server IP}
Connected to {FTP server IP}.
220 (vsFTPd 3.0.2)
Name (hostusername): anonymous
331 Please specify the password.
Password: (何でも)
230 Login successful.
ftp> 

在这个时候,目录是’/var/ftp/’。
那么,可以放置文件吗?

ftp> put test
200 PORT command successful. Consider using PASV.
550 Permission denied.

嗯,那是理所当然的(放心)。

创建用户并禁用匿名选项。

复制后保存

$ sudo cp -p /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.org
# 匿名FTPサーバーの設定
anonymous_enable=NO

被动设置和用户创建

将客户端设置为在服务器上建立连接的被动模式,并明确创建用户。

我打算在本次安装中创建Linux用户和FTP用户。
首先,将用户添加到 /etc/vsftpd/user_list 文件中。用户名称为shinon。

sudo echo 'shinon' | sudo tee -a /etc/vsftpd/user_list

无论是谁,都默认存在。

…
operator
games
nobody
shinon

我将在稍后将用户列表更改为“userlist_deny=NO”,以使文件中所描述的用户能够获得许可列表。

此外,我们会限制用户无法使用上层级别的功能。
其他需要的项目如下。


#コメント外す
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
ls_recurse_enable=YES

#YESに変更
listen=YES

#コメントアウトする(IPv4とダブるとエラー)
#listen_ipv6=YES

#変更
userlist_deny=NO #許可リストにする
userlist_file=/etc/vsftpd/user_list

#今回セキュリティグループで制限しているためNOにする
tcp_wrappers=NO

#以下パッシブモードの追記する
pasv_promiscuous=YES
pasv_enable=YES
pasv_address={グローバルIP}
pasv_min_port=55000
pasv_max_port=55020

端口接收被动的21端口,但连接时使用范围如上所述。

此外,在/etc/vsftpd/chroot_list中写下要从控制中排除的用户。
由于没有这个配置文件,需要创建一个。

sudo echo 'shinon' | sudo tee -a /etc/vsftpd/chroot_list

我已经进行了追加。

shinon

登录,并尝试发送存放在本地的test文件。

$ ftp {FTPサーバーIP}
Connected to {FTPサーバーIP}.
220 (vsFTPd 3.0.2)
Name (hostusername): shinon
331 Please specify the password.
Password: 
230 Login successful.
ftp> put test
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.

总结

vsftpd是一个方便易用的FTP服务器,可以立即使用。我将在CentOS为基础的Linux服务器上记录服务器搭建过程。

非常感谢你。

填充

vsftpd是一个FTP服务器软件。

18.2.2. vsftpd 服务器 Red Hat Enterprise Linux 6 | 引自 Red Hat Customer Portal

唯一一個獨立的 FTP 伺服器,已預設安裝於 Red Hat Enterprise Linux。

请参考这里以获取更详细的信息。
vsftpd – 一款适用于类UNIX系统的安全快速的FTP服务器。

Very Secure Ftp Daemon (vsftpd) 是一个旨在提供高速和安全的FTP服务器的软件。

这是克里斯·埃文斯开发的。

广告
将在 10 秒后关闭
bannerAds