首先須要安裝測試用軟件vsftpd。下文將演示操做配置文件 /etc/vsftpd/vsftpd.conf 。vim
#安裝測試軟件vsftpd 過程省略 [root@promote ~]# yum install vsftpd -y #查看安裝配置文件 顯示不完整 [root@promote ~]# rpm -ql vsftpd | more /etc/logrotate.d/vsftpd /etc/pam.d/vsftpd /etc/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf # 內容過長,已刪除一部分 # /var/ftp /var/ftp/pub [root@promote ~]#
去掉#開頭註釋查看文件。推薦使用egrep,本文部份內容將使用egrep。app
編輯查看原始配置文件 [root@promote ~]# vim /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 [root@promote ~]# -v 表示取反 ^# 表示#開頭行 ^$ 表示空行 [root@promote ~]# grep -v "^#" /etc/vsftpd/vsftpd.conf anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=NO listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES [root@promote ~]#
去#註釋和去空格後效果以下。tcp
#使用egrep 只去掉#註釋 [root@promote ~]# egrep -v '^#' /etc/vsftpd/vsftpd.conf anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=NO listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES #去掉#註釋和空行 [root@promote ~]# egrep -v '^#|^$' /etc/vsftpd/vsftpd.conf anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES listen=NO listen_ipv6=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES [root@promote ~]#
查看結果輸出到文件。ide
#vsftpd.conf可選絕對或相對路徑 #例如egrep -v '^#|^$' /etc/vsftpd/vsftpd.conf >> /etc/vsftpd/vsftpd.conf [root@promote ~]# egrep -v '^#|^$' /etc/vsftpd/vsftpd.conf >> vsftpd.conf