如果没有安装 vsftpd
sudo yum install ftp vsftpd
设置开机启动
chkconfig vsftpd on
设定ftp主目录和用户名
sudo useradd -d 规定的目录 -s /sbin/nologin 用户名
修改密码
passwd 用户名
修改配置文件
sudo vim /etc/vsftpd/vsftpd.conf
对应修改
# 是否运行匿名登录(NO)
2 anonymous_enable=NO
3 # 是否允许本地用户登录
4 local_enable=YES
5 # 允许ftp的任何写方式
6 write_enable=YES
7 # 文件创建只有的权限是755=(777-022)
8 local_umask=022
9 # 是否允许匿名用户上传文件
10 #anon_upload_enable=YES
11 # 是否允许匿名用户创建文件或者删除文件
12 #anon_mkdir_write_enable=YES
13 # 用户进入目录信息提示
14 dirmessage_enable=YES
15 # 是否允许vsftp的日志
16 xferlog_enable=YES
17 # Make sure PORT transfer connections originate from port 20 (ftp-data).
18 connect_from_port_20=YES
19 #
20 #chown_uploads=YES
21 #chown_username=whoever
22 # 日志文件的路径
23 xferlog_file=/var/log/xferlog
24 # 日志文件的格式
25 xferlog_std_format=YES
26 #
27 #idle_session_timeout=600
28 #
29 #data_connection_timeout=120
30 #
31 # It is recommended that you define on your system a unique user which the
32 # ftp server can use as a totally isolated and unprivileged user.
33 #nopriv_user=ftpsecure
34 #
35 # Enable this and the server will recognise asynchronous ABOR requests. Not
36 # recommended for security (the code is non-trivial). Not enabling it,
37 # however, may confuse older FTP clients.
38 #async_abor_enable=YES
39 #
40 # By default the server will pretend to allow ASCII mode but in fact ignore
41 # the request. Turn on the below options to have the server actually do ASCII
42 # mangling on files when in ASCII mode.
43 # Beware that on some FTP servers, ASCII support allows a denial of service
44 # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
45 # predicted this attack and has always been safe, reporting the size of the
46 # raw file.
47 # ASCII mangling is a horrible feature of the protocol.
48 #ascii_upload_enable=YES
49 #ascii_download_enable=YES
50 #
51 # You may fully customise the login banner string:
52 #ftpd_banner=Welcome to blah FTP service.
53 #
54 # You may specify a file of disallowed anonymous e-mail addresses. Apparently
55 # useful for combatting certain DoS attacks.
56 #deny_email_enable=YES
57 # (default follows)
58 #banned_email_file=/etc/vsftpd/banned_emails
59 #
60 # You may specify an explicit list of local users to chroot() to their home
61 # directory. If chroot_local_user is YES, then this list becomes a list of
62 # users to NOT chroot().
63 # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
64 # the user does not have write access to the top level directory within the
65 # chroot)
66 chroot_local_user=YES
67 chroot_list_enable=YES
68 # (default follows)
69 #chroot_list_file=/etc/vsftpd/chroot_list
70 #
71 # You may activate the "-R" option to the builtin ls. This is disabled by
72 # default to avoid remote users being able to cause excessive I/O on large
73 # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
74 # the presence of the "-R" option, so there is a strong case for enabling it.
75 #ls_recurse_enable=YES
76 #
77 # When "listen" directive is enabled, vsftpd runs in standalone mode and
78 # listens on IPv4 sockets. This directive cannot be used in conjunction
79 # with the listen_ipv6 directive.
80 # 只监听ipv4的地址
81 listen=YES
82 #
83 # This directive enables listening on IPv6 sockets. By default, listening
84 # on the IPv6 "any" address (::) will accept connections from both IPv6
85 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
86 # sockets. If you want that (perhaps because you want to listen on specific
87 # addresses) then you must run two copies of vsftpd with two configuration
88 # files.
89 # Make sure, that one of the listen options is commented !!
90 #listen_ipv6=YES
91
92 pam_service_name=vsftpd
93 userlist_enable=YES
94 tcp_wrappers=YES
95 # 下面是自己添加的
96 anon_root=/home/pageftp/open
97 virtual_use_local_privs=YES
98 guest_enable=YES
99 guest_username=pageftp
100 # 虚拟用户的配置文件(可以对每一个虚拟用户进行单独的权限配置)
101 user_config_dir=/etc/vsftpd/vconf/
102 chroot_local_user=YES
103 allow_writeable_chroot=YES
启动ftp服务
1 sudo systemctl enable vsftpd
2 sudo service vsftpd start
可能出现的问题
- 出现“500 OOPS: vsftpd: refusing to run with writable root inside chroot ()”错误
vi /etc/vsftpd.conf (或者是在/etc/vsftpd/vsftpd.conf,总之知道自己服务器的配置文件)
添加 allow_writeable_chroot=YES
保存退出
service vsftpd restart 重启vsftp服务,即可正常登录
- 出现不能修改目录的错误
检查是否目录没有开通相应权限
ftp相关命令
1、连接ftp服务器
- 格式:ftp [hostname | ip-address]a)在linux命令行下输入:ftp 网址/ip 询问你用户名和口令,分别输入用户名和相应密码,待认证通过即可。
2、下载文件
下载文件通常用get和mget这两条命令:
- get 格式:get [remote-file] [local-file]将文件从远端主机中传送至本地主机中.如要获取服务器上/ftp/1.rar,则ftp> get /ftp/1.rar 1.rar (回车)
- mget 格式:mget [remote-files]从远端主机接收一批文件至本地主机.如要获取服务器上/ftp下的所有文件,则ftp> cd /ftpftp> mget . (回车)
注意:文件都下载到了linux主机的当前目录下。
3、上传文件
- put 格式:put local-file [remote-file]将本地一个文件传送至远端主机中.如要把本地的1.zip传送到远端主机/ftp,并改名为1.rarftp> put 1.zip /ftp1.rar (回车)
- mput 格式:mput local-files将本地主机中一批文件传送至远端主机.如要把本地当前目录下所有rar文件上传到服务器/ftp 下ftp> cd /ftp (回车)ftp> mput *.rar (回车)
4、断开连接
- bye/by:中断与服务器的连接。
5、切换目录
-
lcd
查看本地目录 -
cd
查看远程目录 -
cd 目录
远程目录切换(可配置权限) -
cd ..
返回上级