|
|
环境:
redhat linux 9.0
Linux 2.4.20-8 #1 Thu Mar 13 17:18:24 EST 2003 i686 athlon i386 GNU/Linux
RH9.0自带RPM包 vsftpd-1.1.3-8,在安装盘的第三张中
一、检查安装
[root@stdio /]#rpm -qa vsftpd* //查看有没有安装
[root@stdio /]#rpm -ivh vsftpd-1.1.3-8.i386.rpm
二、控制vsftpd服务
1、[root@stdio /]#service vsftpd start/stop/restart //表示启动/停止/重启vsftpd服务
2、让vsftpd开机就启动:
[root@stdio /]#ntsysv //定制开机启动项
然后选中vsftpd,在[]有个*号表示选中。
三、vsftpd服务的主要配置文件是/etc/vsftpd/下的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=YES
#
# 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_local_user=YES
#Input the above option mean that the system user can't access other system file but can access their own file
#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
#The follow option allow the max client number at the same time.
max_clients=10
#The follow option allow the max Link-Number per IP at the same time
max_per_ip=2
#The follow option allow the max speed of donwload by anonymous user.
#set follow mean 20480bit
#anon_max_rate=20480
#The follow option allow the max speed of donwload by local user.
#local_max_rate=20480
二、为vsftp添加虚拟用户,即添加的用户不能登录系统,而只能登录vsftp。
1、[root@stdio /]#adduser testftp
[root@stdio /]#passwd testftp
Changing password for user testftp.
New password: //键入用户testftp的密码
BAD PASSWORD: it's WAY too short
Retype new password: //重新键入用户testftp的密码
passwd: all authentication tokens updated successfully. //表示密码设置成功
2、vi /etc/passwd找到testftp用户的那一行,即:
testftp:x:500:500::/home/testftp:/bin/bash
修改为:
testftp:x:500:50:FTP User:/home/testftp:/sbin/nologin
其中:testftp表示用户名;x表示加密;500表示UID;50表示GID,这里50表示FTP组;FTP User表示对用户的说明;/home/testftp表示用户的主目录;/bin/bash表示用户登录系统后首先启动的shell,nologin表示不能登录系统。
3、测试:
[root@stdio /]# ftp 192.168.1.104
Connected to 192.168.1.104 (192.168.1.104).
220 (vsFTPd 1.1.3)
Name (192.168.1.104:root): testftp
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
表示成功登录vsftp服务
注:为VSFTP添加虚拟用户,也可以不用修改文件的方式,如下:
[root@stdio /]#adduser -g ftp -s /sbin/nologin testftp
[root@stdio /]#passwd testftp
Changing password for user testftp.
New password: //键入用户testftp的密码
BAD PASSWORD: it's WAY too short
Retype new password: //重新键入用户testftp的密码
passwd: all authentication tokens updated successfully. //表示密码设置成功
三、访问ftp的几种方法
1、第一种方法就是text访问,也就是用ftp命令来访问。这个前面已经说过了。
2、第二种方法是以客户端FTP软件来访问,在linux中有gftp。在本例中,我的FTP地址是通过局域网访问的。地址栏中,添上192.168.0.1,端口是21,用户名和密码的添写,如果您是用匿名登入,请不要添写用户名和密码。如果用普通用户登入,这个是必须要用用户名和密码的。
3、第三种办法是和浏览器访问:如果匿名登入,就直接用下面的方法:
ftp://192.168.1.104
如果是用户登入方式,应该是
ftp://testftp@192.168.0.1
然后提示输入密码。
4、如果想让在互联网上的用户能访问到,如果您是用ADSL来访问互联网,要查找到您的动态IP,用下面的办法
[root@linuxsir001 root]# ifconfig ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:218.61.7.23 P-t-P:218.61.7.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:24245 errors:0 dropped:0 overruns:0 frame:0
TX packets:20411 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:23103297 (22.0 Mb) TX bytes:3588337 (3.4 Mb)
从上面的可以知道,能让在internet访问的地址是:218.61.7.23
四、把用户限制在自己的目录中。我们所建的系统用户都有上传和下载的权限,而且用户目录无限制,可以浏览其他目录的内容 。因此如果系统用户的账号给盗用,利用系统账号可以浏览并下载服务器中很多重要的内容。所以我们要把系统用户限制在自己的目录中。下面是不做限制的情况(可以访问其它目录):
ftp> cdup //返回上一级目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,1,104,64,93)
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Apr 28 07:27 bin
drwxr-xr-x 4 0 0 1024 Apr 24 22:28 boot
drwxr-xr-x 20 0 0 118784 Apr 29 06:43 dev
dr-x------ 1 0 0 8192 Apr 26 11:46 e
drwxr-xr-x 58 0 0 4096 Apr 29 06:43 etc
drwxr-xr-x 14 0 0 8192 Jan 01 1970 f
dr-x------ 1 0 0 12288 Apr 26 02:00 g
dr-x------ 1 0 0 12288 Apr 23 13:05 h
drwxr-xr-x 3 0 0 4096 Apr 29 06:50 home
drwxr-xr-x 2 0 0 4096 Jan 24 2003 initrd
drwxr-xr-x 9 0 0 4096 Apr 24 22:32 lib
drwx------ 2 0 0 16384 Apr 24 22:24 lost+found
drwxr-xr-x 2 0 0 4096 Jan 28 2003 misc
drwxr-xr-x 4 0 0 4096 Apr 24 14:44 mnt
drwxr-xr-x 3 0 0 4096 Apr 25 09:40 opt
dr-xr-xr-x 108 0 0 0 Apr 29 2006 proc
drwxr-x--- 25 0 0 4096 Apr 29 07:42 root
drwxr-xr-x 2 0 0 8192 Apr 24 22:30 sbin
drwxrwxrwt 10 0 0 4096 Apr 29 07:57 tmp
drwxr-xr-x 17 0 0 4096 Apr 28 07:59 usr
drwxr-xr-x 20 0 0 4096 Apr 28 15:05 var
226 Directory send OK.
开始限制用户:
1、我们把固定用户限制在自己的目录中:
我们要自己建一个文件,这个文件的路径可以自己设,但要和/etc/vsftpd/vsftpd.conf文件中chroot_list_file的值一致。这里我们采用默认的,即把vsftpd.chroot_list这个文件放在/etc目录中。那么我们
[root@stdio root]# vi /etc/vsftpd.chroot_list
把testftp这个用户限制在自己家目录中,而其它的FTP用户不做此限制。在vsftpd.chroot_list这个文件中,把testftp添上去就行,注意,每个用户占一行。
testftp
然后改/etc/vsftpd/vsftpd.conf文件,找如下的两行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
把前面的#号去掉,也就是这样的
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
如果没有这样的两行,就可以自己添加上去也是一样的。
设置好后,重启vsFTPD服务器。
测试结果如下,表示不能访问其它目录:
[root@stdio root]# ftp 192.168.1.104
Connected to 192.168.1.104 (192.168.1.104).
220 (vsFTPd 1.1.3)
Name (192.168.1.104:root): testftp
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,1,104,21,109)
150 Here comes the directory listing.
226 Directory send OK.
ftp> cdup //返回上一级目录
250 Directory successfully changed.
ftp> ls //查看该目录内容
227 Entering Passive Mode (192,168,1,104,167,234)
150 Here comes the directory listing.
226 Directory send OK.
ftp> cdup //返回上一级目录
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,1,104,176,190)
150 Here comes the directory listing.
226 Directory send OK.
ftp> cdup
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,1,104,207,207)
150 Here comes the directory listing.
226 Directory send OK.
2、把所有系统用户限制在自己的目录中,只要在/etc/vsftpd/vsftpd.conf中加入chroot_local_user=YES即可。
五、打开vsFTP服务器的日志功能:
把下面xferlog_file前面的#号对掉,把vsftp的log功能打开,这样我们就能在/var/log目录下查看vsftpd.log。这是vsFTP的日志功能,对于系统管理员来说是极为重要的。
#xferlog_file=/var/log/vsftpd.log
六、让vsFTP服务器限制链接数,以及每个IP最大的链接数
在/etc/vsftpd/vsftpd.conf中加入下面的两行
max_clients=数字 //表示vsFTP最大支持连接数
max_per_ip=数字 //每个IP最大支持的连接数。
如:让vsFTP最大支持链接数为10个,每个IP最多能支持5个链接,所以我们应该在vsftpd.conf中加上如下的两行:
max_clients=10
max_per_ip=5
七、限制下载的速度
anon_max_rate=数字 //匿名的下载速度
local_max_rate=数字 //vsFTP服务器上普通用户的下载速度
注:数字的单位是字节。比如让匿名用户和vsFTP上的用户都以20KB下载,所以这个数字应该是1024x20=20480
所以我们要在vsftpd.conf中加入下面的两行
anon_max_rate=20480
local_max_rate=20480
八、改变帐号的目录到其它地方。默认帐号ftp的目录是/var/ftp,新建的用户的默认目录是在“/home/用户名”下面。现在让我们来改变这二个目录,有二种方法可以改变这个目录:
第一种方法:修改/etc/passwd文件.
1、执行vi /etc/passwd
2、找到ftp那一行:
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
这句话的含义在上面已说,这里不赘述。把/var/ftp改成你想要作为ftp用户目录。比如我这里改成/f
ftp:x:14:50:FTP User:/f:/sbin/nologin。 至于其它新建用户也同理可改变其默认目录。
第二种方法:添加用户时改变默认目录
1、新建一个文件夹跟用户:
[root@stdio root]# mkdir /mnt/ftp1 //新建一个文件夹作为用户ftp1的目录
[root@stdio root]# adduser -d /mnt/ftp1 -g ftp -s /sbin/nologin ftp1
2、改变权限
[root@stdio root]#chmod 755 /mnt/ftp1
3、同时可以改变系统默认ftp用户ftp的目录。
删除ftp用户
#userdel -r ftp
[root@stdio root]# adduser -d /mnt/ftp -g ftp -s /sbin/nologin ftp
九、定制登录的欢迎信息。
1、 vi /etc/vsftpd/vsftpd.conf找到
dirmessage_enable=YES
把前面的#去掉。
2、在用户目录下新建一个文件.message,在这个文件下添加你想要的用户登录时看到的信息!如:
欢迎登录FTP,有什么不足或建议,请多多指教。
测试:
[root@stdio root]# ftp 192.168.1.101
Connected to 192.168.1.101 (192.168.1.101).
220 (vsFTPd 1.1.3)
Name (192.168.1.101:root): ftp
331 Please specify the password.
Password:
230-欢迎登录stdio FTP
230-有什么不足或建议,请多多指教
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
阅读次数:819
上海雨祺信息科技有限公司
发布日期: 2008-12-1
|
|