Ubuntu Server搭建FTP服务器(2) --本地用户FTP服务器架设
参考:ubuntu中文wiki百科,网址:wiki.ubuntu.org.cn
环境:Ubuntu 9.04 Server+VSFTPD 2.0.7
slmagicbox@ubuntu904server:~$ uname -a
Linux ubuntu904server 2.6.28-11-server #42-Ubuntu SMP Fri Apr 17 02:48:10 UTC 2009 i686 GNU/Linux
slmagicbox@ubuntu904server:~$ dpkg -l | grep vsftpd
ii vsftpd 2.0.7-0ubuntu1 The Very Secure FTP Daemon
原始配置文件/etc/vsftpd.conf:
本配置文件为安装vsftpd后默认生成的,
以“#”开头为注释项
# Example config file /etc/vsftpd.conf listen=YES #以standalone模式运行vsftpd #listen_ipv6=YES anonymous_enable=YES #允许匿名用户访问 #local_enable=YES #write_enable=YES #local_umask=022 #anon_upload_enable=YES #anon_mkdir_write_enable=YES dirmessage_enable=YES #当用户首次进入FTP服务器的目录时,显示该目录下的message消息,默认为.message文件,可以用message_file来定义 xferlog_enable=YES #启用日志,默认路径/var/log/vsftpd.log connect_from_port_20=YES #数据连接使用默认的ftp-data端口(20端口) #chown_uploads=YES #chown_username=whoever #xferlog_file=/var/log/vsftpd.log #xferlog_std_format=YES #idle_session_timeout=600 #data_connection_timeout=120 #nopriv_user=ftpsecure #async_abor_enable=YES #ascii_upload_enable=YES #ascii_download_enable=YES #ftpd_banner=Welcome to blah FTP service. #deny_email_enable=YES #banned_email_file=/etc/vsftpd.banned_emails
# chroot_list_enable below. #chroot_local_user=YES #chroot_list_enable=YES #chroot_list_file=/etc/vsftpd.chroot_list #ls_recurse_enable=YES
# Debian customization secure_chroot_dir=/var/run/vsftpd #忽略 pam_service_name=vsftpd #忽略 rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem #忽略 rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key #忽略 |
修改后功能:
1)不允许匿名,本地用户可上传
anonymous_enable=NO
#注释掉的话,默认为允许
anon_upload_enable=NO
#anonymous_enable=YES时起作用,注释掉的话,默认为允许,前提是全局上传权限开启(write_enable=YES)
anon_mkdir_write_enable=NO
#anonymous_enable=YES时起作用,注释掉的话,默认为允许,前提是全局上传权限开启(write_enable=YES)
local_enable=YES
write_enable=YES
local_umask=022
#默认为077
功能验证:
1)匿名用户无法登录
2)本地用户登录成功,并可浏览整个文件系统,ftp权限由系统权限来控制
3)在本地用户主目录下上传一个文件,并且创建一个文件夹,观察两者权限。
slmagicbox@ubuntu904server:~$
ls -l
drwxr-xr-x 2 slmagicbox slmagicbox 4096 2009-05-11 16:43 test1
#文件夹权限为 777-022=744
-rw-r--r-- 1 slmagicbox slmagicbox 0 2009-05-11 16:43 test2
#文件权限为 666-022=644
4) 添加一个本地用户ftptest1,让其可以ftp登录
slmagicbox@ubuntu904server:~$
sudo useradd ftptest1 -m
#创建一个新的本地用户ftptest1,-m参数为创建该用户home文件夹(/home/ftptest1),ftp用户必须有home目录,否则会报500 OOPS: cannot change directory:/home/ftptest1 的错误
slmagicbox@ubuntu904server:/home$
sudo passwd ftptest1 #为ftptest1用户设置密码
输入新的 UNIX 口令:
重新输入新的 UNIX 口令:
passwd: password updated successfully
slmagicbox@XXX:~$
ftp 192.168.0.111
Connected to 192.168.0.111.
220 (vsFTPd 2.0.7)
Name (192.168.0.111:slmagicbox):
ftptest1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
#登录成功
5)现在本地用户可以ftp了,但是让一个ftp用户在你的服务器上到处逛,是不是感觉不放心呢?是否可以将ftp用户限定在他们的home目录下呢?这就要用到ch_root功能了。
编辑配置文件/etc/vsftpd.conf:
chroot_local_user=YES
slmagicbox@ubuntu904server:~$
sudo /etc/init.d/vsftpd restart
#重启一下服务,让配置更新
slmagicbox@FY-IT-Wangzh:~$
ftp 192.168.0.111
Connected to 192.168.0.111.
220 (vsFTPd 2.0.7)
Name (192.168.0.111:slmagicbox): ftptest1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> cd /home
550 Failed to change directory.
#用户被限定在自己的目录下活动了
6)上面的效果是不是你想要的呢,但是管理员自己能不能有个特权呢,可以不被限制在home目录下呢?
编辑配置文件/etc/vsftpd.conf:
chroot_local_user=YES
chroot_list_enable=YES
#启用chroot_list,列在该文件里的用户排除在外,不限制在个人目录下
chroot_list_file=/etc/vsftpd.chroot_list
#定义chroot_list文件位置
创建并编辑/etc/vsftpd.chroot_list:
slmagicbox@ubuntu904server:/etc$ echo "slmagicbox" | sudo tee -a vsftpd.chroot_list
#把你希望排除在外的用户加入/etc/vsftpd.chroot_list
slmagicbox@ubuntu904server:~$
sudo /etc/init.d/vsftpd restart
7) 仅靠local_enable=YES来控制本地用户可以访问ftp,使得服务器上的所有用户都有权限来访问ftp。你是不是希望可以控制,哪些用户可以访问,哪些用户不可访问?让我们继续
编辑配置文件/etc/vsftpd.conf:
userlist_enable=YES #启用ftp用户列表
userlist_deny=NO #不采用deny用户列表方式。userlist_deny可以理解为在userlist_file中列出的用户是被deny掉的,不允许访问ftp的,这里设置为NO,即表示该列表中的用户不是被deny掉的,是有权限访问ftp的。可能有点搞,简单点的理解就是userlist_deny设置是否采用黑名单,YES为采用;NO为不采用黑名单,即采用白名单。这里采用白名单,只有在userlist_file中列出的用户才有权访问ftp.
userlist_file=/etc/vsftpd.user_list #定义userlist_file文件存放位置
创建并编辑/etc/vsftpd.user_list:
slmagicbox@ubuntu904server:~$ cd /etc/
slmagicbox@ubuntu904server:/etc$ sudo touch vsftpd.user_list
slmagicbox@ubuntu904server:/etc$ echo "slmagicbox" |sudo tee -a vsftpd.user_list
slmagicbox@ubuntu904server:~$
sudo /etc/init.d/vsftpd restart
看一下效果吧,应该只有slmagicbox可以访问ftp。之后,把需要访问ftp的用户加入/etc/vsftpd.user_list就行了,这样控制就简单了,不遵守纪律的,管理员随时可以把你请出去,别想用上ftp,嚯嚯!!