单独(Standalone)运行方式(默认)
启动方法:
service vsftp start
验证成功:
[root@myhost etc]# telnet 127.0.0.1
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
[root@myhost etc]#
也可以采用xinetd方式运行
修改/etc/xinetd.d/vsftpd里的disable,改为disable=no.然后执行service xinetd restart重启ftp。
两者差别:standalone一次性启动,运行期间一直驻留在内存中,优点是对接入信号反应快,缺点是损耗了一定的系统资源,因此经常应用于对实时反应要求较高的专业FTP服务器。xinetd恰恰相反,由于只在外部连接发送请求时才调用FTP进程,因此不适合应用在同时连接数量较多的系统。
2、编辑/etc/vsftpd/vsftpd.conf文件
修改端口
Step1. 修改/etc/vsftpd/vsftpd.conf
`新增底下一行
listen_port=2121
Step2. 重新启动vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
特定使用者peter、john 不得变更目录
使用者的预设目录为/home/username,若是我们不希望使用者在ftp 时能够
切换到上一层目录/home,则可参考以下步骤。
Step1. 修改/etc/vsftpd/vsftpd.conf
将底下三行
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
改为
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list //需新增此文件
Step2. 新增一个档案: /etc/vsftpd/chroot_list
内容增加两行:
peter
john
Step3. 重新启动vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
若是peter 欲切换到根目录以外的目录,则会出现以下警告:
ftp>; cd /home
550 Failed to change directory.
取消anonymous 登入
若是读者的主机不希望使用者匿名登入,则可参考以下步骤。
Step1. 修改/etc/vsftpd/vsftpd.conf
将
anonymous_enable=YES
改为
anonymous_enable=NO
安排欢迎话语
若是我们希望使用者在登入时,能够看到欢迎话语,可能包括对该主机的
说明,或是目录的介绍,可参考以下步骤。
首先确定在/etc/vsftpd/vsftpd.conf 当中是否有底下这一行
dirmessage_enable=YES
RedHat9 的默认值是有上面这行的。
接着,在各目录之中,新增名为.message 的档案,再这边假设有一个使用
者test1,且此使用者的根目录下有个目录名为abc,那首先我们在/home/test1
之下新增.message,内容如下:
Hello~ Welcome to the home directory
This is for test only...
接着,在/home/test1/abc 的目录下新增.message,内容如下:
Welcome to abc's directory
This is subdir...
那么,当使用者test1 登入时,会看到以下讯息:
230- Hello~ Welcome to the home directory
230-
230- This is for test only...
230-
若是切换到abc 的目录,则会出现以下讯息:
250- Welcome to abc's directory
250-
250- This is subdir ...
对于每一个联机,以独立的process 来运作
一般启动vsftp 时,我们只会看到一个名为vsftpd 的process 在运作,但若
是读者希望每一个联机,都能以独立的process 来呈现,则可执行以下步骤。
Step1. 修改/etc/vsftpd/vsftpd.conf
新增底下一行
setproctitle_enable=YES
Step2. 重新启动vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
使用ps -ef 的指令,可以看告不同使用者联机的情形,如下图所示:
[root@home vsftpd]# ps -ef|grep ftp
root 2090 1 0 16:41 pts/0 00:00:00 vsftpd: LISTENER
nobody 2120 2090 0 17:18 ? 00:00:00 vsftpd: 192.168.10.244:
connected
test1 2122 2120 0 17:18 ? 00:00:00 vsftpd: 192.168.10.244/test1:
IDLE
nobody 2124 2090 0 17:19 ? 00:00:00 vsftpd: 192.168.10.244:
connected
test2 2126 2124 0 17:19 ? 00:00:00 vsftpd: 192.168.10.244/test2:
IDLE
root 2129 1343 0 17:20 pts/0 00:00:00 grep ftp
[root@home vsftpd]#
限制传输档案的速度:本机的使用者最高速度为200KBytes/s,匿名登入
者所能使用的最高速度为50KBytes/s
Step1. 修改/etc/vsftpd/vsftpd.conf
新增底下两行
anon_max_rate=50000
local_max_rate=200000
Step2. 重新启动vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
在这边速度的单位为Bytes/s,其中anon_max_rate 所限制的是匿名登入的
使用者,而local_max_rate 所限制的是本机的使用者。VSFTPD 对于速度的限
制,范围大概在80%到120%之间,也就是我们限制最高速度为100KBytes/s,
但实际的速度可能在80KBytes/s 到120KBytes/s 之间,当然,若是频宽不足
时,数值会低于此限制。
建置一个防火墙下的ftp server,使用PORT FTP mode:预设的ftp
port:21 以及ftp data port:20
启动VSFTPD 之后执行以下两行指令,只允许port 21 以及port 20 开放,
其它关闭。
iptables -A INPUT -p tcp -m multiport --dport 21,20 -j ACCEPT
iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
将vsftpd 并入XINETD
若是读者希望将vsftpd 并入XINETD 之中,也就是7.x 版的预设设定,那
么读者可以执行以下步骤。
Step1. 修改/etc/vsftpd/vsftpd.conf
将
listen=YES
改为
listen=NO
Step2. 新增一个档案: /etc/xinetd.d/vsftpd
内容如下:
service vsftpd
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
port = 21
log_on_success += PID HOST DURATION
log_on_failure += HOST
}
Step3. 重新启动xinetd
[root@home vsftpd]# /sbin/service xinetd restart
Stopping xinetd: OK ]
Starting xinetd: OK ]
3、常见错误
ftp客户连接常见故障现象
现象0:
> ftp: connect :连接被拒绝
原因: 服务没启动
解决: # chkconfig vsftpd on<Enter>
现象1:
500 OOPS: cannot open user list file
原因: 不存在文件“/etc/vsftpd.user_list”或文件中不存在该帐户
解决: # echo username >> /etc/vsftpd.user_list<Enter>
现象2:
530 Permission denied.
Login failed.
原因: “/etc/vsftpd.user_list”文件中不存在当前登陆用户
解决: # echo username >> /etc/vsftpd.user_list<Enter>
现象3:
500 OOPS: cannot open chroot() user list file
Login failed.
原因: 不存在文件“/etc/vsftpd.chroot_list”
解决: # echo username >> /etc/vsftpd.chroot_list<Enter>
现象4:
500 OOPS: missing value in config file
Connection closed by remote host.
原因: “=”等号前值有问题,或只有一个空格
解决: 修正相应的值即可,可能过 diff 来比较查找
现象5:
500 OOPS: bad bool value in config file
Connection closed by remote host.
原因: “=”等号后值有问题
解决: 将“=”等号后值确认修改
现象6:
500 OOPS: unrecognised variable in config file
Connection closed by remote host.
原因: 参数前有空格
解决: 将参数前空格删除
现象7、
确认存在“local_enable=YES”,但本地用户无法登陆
原因: 验证参数被误删除
解决: 添加“pam_service_name=vsftpd”
现象8、
500 OOPS: chdir
500 OOPS: child died
Connection closed by remote host.
原因: 用户主目录没有权限或没有主目录
解决: 正确设置用户主目录权限
4、我的配置文件
/etc/vsftpd/vsftpd.conf
[root@myhost vsftpd]# more vsftpd.conf
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are very paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
#
# Allow anonymous FTP?
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that turning on ascii_download_enable enables malicious remote parties
# to consume your I/O resources, by issuing the command "SIZE /big/file" in
# ASCII mode.
# These ASCII options are split into upload and download because you may wish
# to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
# without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
# on the client anyway..
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
pam_service_name=vsftpd
userlist_enable=YES
#enable for standalone mode
listen=YES
tcp_wrappers=YES
listen_port=2121
userlist_deny=YES
[root@myhost vsftpd]#
/etc/vsftpd.chroot_list 可以登陆上层目录
[root@myhost etc]# more vsftpd.chroot_list
root
[root@myhost etc]#
/etc/vsftpd.user_list 位于/etc目录下。该文件里的用户账户在默认情况下也不能访问FTP服务器,仅当vsftpd .conf配置文件里启用userlist_enable=NO选项时才允许访问。
[root@myhost etc]# more vsftpd.user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd.ftpusers
# for users that are denied.
#root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
[root@myhost etc]#
/etc/vsftpd.ftpusers 位于/etc目录下。它指定了哪些用户账户不能访问FTP服务器,例如root等。
[root@myhost etc]# more vsftpd.ftpusers
# Users that are not allowed to login via ftp
#root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
[root@myhost etc]#