1.檢查centos是否安裝vsftpd
[root@localhost zhangzhuo]# rpm -aq vsftpd
vsftpd-3.0.2-22.el7.x86_64 #查詢的返回結果,表明已安裝
若要卸載Vfstpd:
[root@localhost zhangzhuo]# rpm -e vsftpd-3.0.22-22.el7.x86_64
由於我的vsftpd服務已搭建好,所以就不給演示刪除,但我之前配置錯誤,用此方法刪除是沒有問題的
查看是否卸載了vsftpd:
[root@localhost zhangzhuo]# /sbin/service vsftpd stop
[root@localhost zhangzhuo]# /sbin/service vsftpd start
#在卸載vsftpd之前要 先停止vsftpd
2.安裝vsftpd
[root@localhost zhangzhuo]# yum -y install vsftpd
3.修改vsftpd.conf文件
[root@localhost zhangzhuo]# vi /etc/vsftpd/vsftpd.conf
1 # Example config file /etc/vsftpd/vsftpd.conf 2 # 3 # The default compiled in settings are fairly paranoid. This sample file 4 # loosens things up a bit, to make the ftp daemon more usable. 5 # Please see vsftpd.conf.5 for all compiled in defaults. 6 # 7 # READ THIS: This example file is NOT an exhaustive list of vsftpd options. 8 # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's 9 # capabilities. 10 # 11 # Allow anonymous FTP? (Beware - allowed by default if you comment this out). 12 #anonymous_enable=YES 13 # 14 # Uncomment this to allow local users to log in. 15 # When SELinux is enforcing check for SE bool ftp_home_dir 16 local_enable=YES 17 # 18 # Uncomment this to enable any form of FTP write command. 19 write_enable=YES 20 # 21 # Default umask for local users is 077. You may wish to change this to 022, 22 # if your users expect that (022 is used by most other ftpd's) 23 local_umask=022 24 # 25 # Uncomment this to allow the anonymous FTP user to upload files. This only 26 # has an effect if the above global write enable is activated. Also, you will 27 # obviously need to create a directory writable by the FTP user. 28 # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access 29 #anon_upload_enable=YES 30 # 31 # Uncomment this if you want the anonymous FTP user to be able to create 32 # new directories. 33 #anon_mkdir_write_enable=YES 34 # 35 # Activate directory messages - messages given to remote users when they 36 # go into a certain directory. 37 dirmessage_enable=YES 38 # 39 # Activate logging of uploads/downloads. 40 xferlog_enable=YES 41 # 42 # Make sure PORT transfer connections originate from port 20 (ftp-data). 43 connect_from_port_20=YES 44 # 45 # If you want, you can arrange for uploaded anonymous files to be owned by 46 # a different user. Note! Using "root" for uploaded files is not 47 # recommended! 48 #chown_uploads=YES 49 #chown_username=whoever 50 # 51 # You may override where the log file goes if you like. The default is shown 52 # below. 53 #xferlog_file=/var/log/xferlog 54 # 55 # If you want, you can have your log file in standard ftpd xferlog format. 56 # Note that the default log file location is /var/log/xferlog in this case. 57 xferlog_std_format=YES 58 # 59 # You may change the default value for timing out an idle session. 60 idle_session_timeout=600 61 # 62 # You may change the default value for timing out a data connection. 63 data_connection_timeout=120 64 # 65 # It is recommended that you define on your system a unique user which the 66 # ftp server can use as a totally isolated and unprivileged user. 67 #nopriv_user=ftpsecure 68 # 69 # Enable this and the server will recognise asynchronous ABOR requests. Not 70 # recommended for security (the code is non-trivial). Not enabling it, 71 # however, may confuse older FTP clients. 72 #async_abor_enable=YES 73 # 74 # By default the server will pretend to allow ASCII mode but in fact ignore 75 # the request. Turn on the below options to have the server actually do ASCII 76 # mangling on files when in ASCII mode. 77 # Beware that on some FTP servers, ASCII support allows a denial of service 78 # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd 79 # predicted this attack and has always been safe, reporting the size of the 80 # raw file. 81 # ASCII mangling is a horrible feature of the protocol. 82 ascii_upload_enable=YES 83 ascii_download_enable=YES 84 # 85 # You may fully customise the login banner string: 86 ftpd_banner=Welcome to blah FTP service. 87 # 88 # You may specify a file of disallowed anonymous e-mail addresses. Apparently 89 # useful for combatting certain DoS attacks. 90 #deny_email_enable=YES 91 # (default follows) 92 #banned_email_file=/etc/vsftpd/banned_emails 93 # 94 # You may specify an explicit list of local users to chroot() to their home 95 # directory. If chroot_local_user is YES, then this list becomes a list of 96 # users to NOT chroot(). 97 # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that 98 # the user does not have write access to the top level directory within the 99 # chroot) 100 chroot_local_user=YES 101 #chroot_list_enable=YES 102 # (default follows) 103 #chroot_list_file=/etc/vsftpd/chroot_list 104 # 105 # You may activate the "-R" option to the builtin ls. This is disabled by 106 # default to avoid remote users being able to cause excessive I/O on large 107 # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume 108 # the presence of the "-R" option, so there is a strong case for enabling it. 109 ls_recurse_enable=YES 110 # 111 # When "listen" directive is enabled, vsftpd runs in standalone mode and 112 # listens on IPv4 sockets. This directive cannot be used in conjunction 113 # with the listen_ipv6 directive. 114 listen=YES 115 # 116 # This directive enables listening on IPv6 sockets. By default, listening 117 # on the IPv6 "any" address (::) will accept connections from both IPv6 118 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 119 # sockets. If you want that (perhaps because you want to listen on specific 120 # addresses) then you must run two copies of vsftpd with two configuration 121 122 # files. 123 # Make sure, that one of the listen options is commented !! 124 #listen_ipv6=YES 125 126 pam_service_name=vsftpd 127 userlist_enable=YES 128 userlist_deny=NO 129 local_root=/var/public_root 130 tcp_wrappers=YES 131 use_localtime=YES 132 allow_writeable_chroot=YES
最后一句,為了解決“當我們限定了用戶不能跳出其主目錄之后,使用該用戶登錄FTP時遇到的錯誤”:
1 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()
這個問題發生在最新的這是由於下面的更新造成的:
1 Add stronger checks for the configuration error of running with a writeable root directory inside a chroot()
從2.3.5之后,vsftpd增強了安全檢查,如果用戶被限定在了其主目錄下,則該用戶的主目錄不能再具有寫權限了!如果檢查發現還有寫權限,就會報該錯誤。
要修復這個錯誤,可以用命令chmod a-w /home/user去除用戶主目錄的寫權限,注意把目錄替換成你自己的。或者你可以在vsftpd的配置文件中增加標紅的最后一句話
3.添加ftp賬戶
為了方便記憶,這里設置的賬戶為vsftpd、密碼為123456
1 [root@localhost zhangzhuo]# useradd vsftpd -s /sbin/nologin 2 [root@localhost zhangzhuo]# passwd vsftpd
4.編輯user_list文件,允許vsftpd訪問ftp
1 [root@localhost zhangzhuo]# vi /etc/vsftpd/user_list
1 # vsftpd userlist 2 # If userlist_deny=NO, only allow users in this file 3 # If userlist_deny=YES (default), never allow users in this file, and 4 # do not even prompt for a password. 5 # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers 6 # for users that are denied. 7 root 8 bin 9 daemon 10 adm 11 lp 12 sync 13 shutdown 14 halt 15 mail 16 news 17 uucp 18 operator 19 games 20 nobody 21 vsftpd 22 ~ 23 ~ 24 ~
5.建立根目錄,設置訪問權限
1 [root@localhost zhangzhuo]# mkdir /var/public_root 2 [root@localhost zhangzhuo]# chown -R vsftpd /var/public_root 3 [root@localhost zhangzhuo]# chmod -R 755 /var/public_root
6.關閉防火牆或開放21端口
ftp設置好了之后,服務啟動了但連接失敗,ftp默認是21號端口,但Linux的21端口默認是關閉的,關閉防火可以解決,但不推薦
1 firewall-cmd –state ----> 查看防火牆狀態 2 service firewalld start ----> 啟動防火牆 3 service firewalld restart ----> 重啟防火牆 4 service firewalld stop -----> 關閉防火牆 5 firewall-cmd --query-port=21/tcp ----->查詢端口是否開放 6 firewall-cmd --permanent --add-port=21/tcp ----->開放21端口 7 firewall-cmd --permanent --remove-port=21/tcp ----->移除端口 8 firewall-cmd --reload ----->重啟防火牆(修改配置后要重啟防火牆)
7.開啟vsftpd服務
1 [root@localhost zhangzhuo]# service vsftpd start 2 [root@localhost zhangzhuo]# systemctl status vsftpd.service #查看vsftpd服務狀態 3 [root@localhost zhangzhuo]# systemctl restart vsftpd.service #重啟vsftpd服務
8.設置開機啟動vsftpd服務
1 [root@localhost zhangzhuo]# chkconfig vsftpd on
至此,ftp服務就搭建起來了,可以通過物理主機的dos命令行使用"ftp linux虛擬機IP"或者FileZilla軟件進行連接測試
博主也是菜鳥一只,若給您帶來幫助,不勝榮幸;若有什么問題,歡迎踩我,大家共同學習進步,提高技術,謝謝!