Ubuntu系统部署FTP服务器
1,安装FTP
- 执行以下命令安装ftp服务
sudo apt-get install vsftpd
- 检查是否安装成功
vsftpd -v
- 出现版本信息表示安装成功
2,编辑配置文件
- 使用下面命令进入配置文件
注: 这里笔者使用的vim编辑器,童鞋们也可使使用其他的编辑器
sudo vim /etc/vsftpd.conf
-
(1)开启以下功能:
-
write_enable=YES:表示允许对FTP服务器执行写操作,包括上传、删除和重命名文件等操作。
# Uncomment this to enable any form of FTP write command.
write_enable=YES
-
chroot_local_user=YES:这个配置指定了只有本地用户(即系统用户)才会被限制在其主目录中。如果设置为YES,那么FTP用户将被限制在其主目录下,无法访问根目录以外的文件或目录。
-
chroot_list_enable=YES:这个配置指定了是否启用chroot_list_file中列出的用户列表的chroot限制。
-
chroot_list_file=/etc/vsftpd.chroot_list:这个配置指定了包含需要被chroot限制的用户列表的文件路径。如果chroot_list_enable设置为YES,那么在chroot_list_file中列出的用户将被限制在其主目录中。
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
- (2)加入根目录
这句配置指定了vsftpd的根目录为/home/python/ftpfile。这意味着当用户连接到ftp服务器时,他们将被限制在这个目录下,无法访问根目录以外的文件或目录。
local_root=/home/python/ftpfile
注:下面是我的配置文件(完整)开启功能
#
# Run standalone? vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=NO
#
# Allow anonymous FTP? (Disabled by default).
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
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in your local time zone. The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=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
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
# This option should be the name of a directory which is empty. Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
#utf8_filesystem=YES
local_root=/home/python/ftpfile
3,添加用户及密码
- 1,给自己的系统添加新用户(方便演示ftp使用)
lisi是我取的用户名,随便取记住就行
sudo useradd -m lisi
- 2,配置密码
输入下面命令会让你输入密码
sudo passwd lisi
4,在chroot_list中添加用户
sudo vim /etc/vsftpd.chroot_list
在该文件加入lisi
5,重启服务
sudo /etc/init.d/vsftpd restart
出现以下信息就ok了
测试
- 使用ifconfig命令找到自己主机的ip地址
- 使用ftp ip地址命令
ftp 192.168.XX.XX
- 然后输入配置好的用户名和密码,出现ftp>就成功访问了。