FTP(File Transfer Protocol)即文件传输协议,也是属于客户机/服务器(Clinet/Server,即C/S)模型的服务或应用程序,用于Internet上的控制文件的双向传输。同时,也是一个应用程序(Application)。基于不同操作系统又不同的FTP应用程序,而这些应用程序都遵守同一种协议以传输文件。
常用功能:"Download"和"Upload",即下载文件和上传文件等功能。
虚拟系统:Ubuntu 16.04 LTS
方法和步骤:
1.安装FTP服务
$ sudo apt-get install vsftpd

2.创建共享文件夹(共享文件夹目录已存在的情况下,请忽略此步骤)
PS:此步骤在<Ubuntu16.04搭建NFS文件共享服务器的方法>有介绍,Samba服务也是共享/sharedfile文件夹
1 $ sudo mkdir /ftp # 创建你要共享的目录(共享文件夹,因为我在根目录创建ftp目录,所以需要使用root权限) 2 $ sudo chmod 777 /ftp # 我将该目录权限全部开放(根据个人需求配置权限) 3 $ ls -l / # 查看ftp共享目录和权限
3.修改/etc/vsftpd.conf配置文件
$ sudo vi /etc/vsftpd.conf
# Example config file /etc/vsftpd.conf # # The default compiled in settings are fairly paranoid. This sample file # loosens things up a bit, to make the ftp daemon more usable. # Please see vsftpd.conf.5 for all compiled in defaults. # # READ THIS: This example file is NOT an exhaustive list of vsftpd options. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's # capabilities. # # # Run standalone? vsftpd can run either from an inetd or as a standalone # daemon started from an initscript. # 阻止 vsftpd 在独立模式下运行 listen=NO # # This directive enables listening on IPv6 sockets. By default, listening # on the IPv6 "any" address (::) will accept connections from both IPv6 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 # sockets. If you want that (perhaps because you want to listen on specific # addresses) then you must run two copies of vsftpd with two configuration # files. # vsftpd 将监听 ipv6 而不散 ipv4 listen_ipv6=YES # # 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. # 启用可以修改文件的 FTP命令(默认关闭,此命令默认注释) 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) # 本地用户新增档案时的umask值(默认关闭,此命令默认注释) 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 # # 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). # 在服务器上针对 PORT 类型的连接使用端口 20(FTP 数据) 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. # Note that the default log file location is /var/log/xferlog in this case. 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 on some FTP servers, ASCII support allows a denial of service # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd # predicted this attack and has always been safe, reporting the size of the # raw file. # ASCII mangling is a horrible feature of the protocol. #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 restrict local users to their home directories. See the FAQ for # the possible risks in this before using chroot_local_user or # chroot_list_enable below. #chroot_local_user=YES # # 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(). # (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) # 不单独建立ftp用户,直接使用Ubuntu桌面用户就可以登录(默认关闭,此两条命令默认注释) chroot_local_user=YES chroot_list_enable=NO # (default follows) # 能够登录的用户名单(默认关闭,此命令默认注释) chroot_list_file=/etc/vsftpd.chroot_list # 需要创建vsftpd.chroot_list文件,在文件中添加登录ftp服务的用户名 # chroot_local_user=YES chroot_list_enable=YES 1.所有用户被限制在其主目录下 2.chroot_list_file用户列表作为例外用户,不受限制(默认此种模式) # chroot_local_user=YES chroot_list_enable=NO 1.所有用户被限制在其主目录下 2.chroot_list_file用户列表不使用,没有例外用户 # chroot_local_user=NO chroot_list_enable=YES 1.所有用户不被限制在其主目录下 2.chroot_list_file用户列表作为例外用户,反而受到限制 # chroot_local_user=YES chroot_list_enable=YES 1.所有用户不被限制在其主目录下 2.chroot_list_file用户列表不使用,没有任何例外用户 # # 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 # # Customization # # Some of vsftpd's settings don't fit the filesystem layout by # default. # # 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. # vsfftpd PAM服务的名称(默认vsftpd) #pam_service_name=vsftpd pam_service_name=ftp # # 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. # 使用UTF-8文件系统(默认关闭,此命令默认注释) utf8_filesystem=YES # 锁定一个共享目录(添加日期:2018年09月20日,添加者:Angus) local_root=/ftp # 给共享目录添加写权限(添加日期:2018年09月20日,添加者:Angus)
# 如果Ubuntu12.04LTS系统chroot_local_user和chroot_list_enable皆为YES时,必须注释或删除allow_writeable_chroot
allow_writeable_chroot=YES
download_enable=YES
PS:无需添加ftp用户,直接使用Ubuntu桌面用户即可登录。以上内容直接粘贴复制即可使用!
Ubuntu12.04LTS 64bit系统:
1.chroot_local_user和chroot_list_enable皆为YES时,且必须注释或删除allow_writeable_chroot
2.记得在/etc目录下ftpusers 和vsftpd.chroot_list文件添加相关信息。
ftpusers文件内容参考:
# /etc/ftpusers: list of users disallowed FTP access. See ftpusers(5). #root daemon bin sys sync games man lp mail news uucp nobody
vsftpd.chroot_list文件内容参考:
#root
user
xxx(用户名)
4.查看vsftp服务运行状态和重启
4.1.查看vsftp服务运行状态
4.1.1.使用ps命令,查看进程
ps -ef|grep vstfp
如果显示ftp的进程号,表示ftp为启动状态。
4.1.2.使用service命令
service vsftpd status
- 显示信息为is running(表示为启动状态)
- 如果为 is stopped(表示为关闭状态)
4.2.重启ftp服务
4.2.1.可以杀进程
kill -9 pid # 杀死进程 该pid为ftp的进程号 service vsftpd start # 启动服务
4.2.2. 可以将vsftpd服务先关闭,再启动
1 $ sudo service vsftpd stop # 关闭服务 2 $ sudo service vsftpd start # 启动服务
4.2.3.任选以下命令重启
1 $ sudo service vsftpd restart # 重启服务 2 $ sudo /etc/init.d/vsftpd restart # 重启服务
5.浏览器登录ftp服务器
ftp://192.168.1.118/

输入用户名和密码,登录成功,可以看到共享的文件。

浙公网安备 33010602011771号