ftp服务在运维工作中还是十分常用的。下面记录下安装配置过程。关于主动被动原理可以看一下我的wiki vsftp是一个主打安全的ftp服务,所以配置文件会复杂一些。下面是适用于一般场景的配置,使用虚拟用户进行登录操作,更多定制需要需要自行进行修改。
安装
- My Env
- AWS AMI
- YUM Repo: epel
- Red Hat Enterprise Linux Server release 7.3 (Maipo)
- Check and Install vsftp pkg
1 2
rpm -q vsftpd yum install vsftpd -y
- Stop Firewall and SElinux
1 2 3 4 5 6
setenforce 0 # forver stop vi /etc/selinux/config #SELINUX=disabled # Stop firewall systemctl stop firewalld.service systemctl disable firewalld.service
配置修改
- 主配置文件修改如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
anonymous_enable=No local_enable=YES allow_writeable_chroot=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES chroot_local_user=YES chroot_list_enable=YES listen=YES pam_service_name=vsftpd userlist_enable=YES tcp_wrappers=YES listen_port=21 idle_session_timeout=300 data_connection_timeout=120 guest_enable=YES guest_username=ftpuser user_config_dir=/etc/vsftpd/vuser_conf virtual_use_local_privs=YES pasv_address="Your Public IP" pasv_min_port=10060 pasv_max_port=10090 accept_timeout=5 connect_timeout=5
- 添加ftp用户
1 2 3
useradd -g root -M -d /data/ftp_server -s /sbin/nologin ftpuser echo "rPUdeubeKCPwRAhpVt8GWLpG" |passwd --stdin ftpuser chown -R ftpuser.root /data/ftp_server/
- Config virture User
1 2 3 4 5 6 7 8 9
touch /etc/vsftpd/vuser_passwd vi /etc/vsftpd/vuser_passwd #user #password db_load -T -t hash -f /etc/vsftpd/vuser_passwd /etc/vsftpd/vuser_passwd.db chmod 600 /etc/vsftpd/vuser_passwd.db mkdir /etc/vsftpd/vuser_conf cd /etc/vsftpd/vuser_conf touch tai-yunying
- 修改pam.d下的ftp配置
1 2 3 4 5 6 7 8 9 10
#%PAM-1.0 #session optional pam_keyinit.so force revoke #auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed #auth required pam_shells.so #auth include password-auth #account include password-auth #session required pam_loginuid.so #session include password-auth auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser_passwd
- 启动服务
1
systemctl restart vsftpd.service
About Base Yum
- Base Yum Repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[base] name=CentOS-$7 - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os baseurl=http://mirrors.163.com/centos/7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$7 - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$7 - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$7 - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
报错解决
- 227 Entering Passive Mode
- Unit NetworkManager-dispatcher.service has begun starting up.
Jul 28 06:12:45 ip-10-222-0-61.taiyouxi.net dbus[501]: [system] Successfully activated service ‘org.freedesktop.nm_dispatcher’centos7中vsftp的配置文件默认将 listen_ipv6=YES 这一行没有注释掉,而我们目前的网络环境还不支持ipv6,从而导致出现错误无法启动,所以解决方法是将 listen_ipv6=YES更改为:listen_ipv6=NO,或将这一行注释掉
- 被动模式报错
425 Security: Bad IP connecting. 解决:修改vsftp服务器端主配置文件,添加字段(原因,被动模式客户端拿到了服务器端的内网地址所以无法建立连接) pasv_address=61.52.112.30
配置默认目录说明
- 配置文件说明
目录文件 说明 /usr/sbin/vsftpd VSFTPD的主程序 /etc/rc.d/init.d/vsftpd 启动脚本 /etc/vsftpd/vsftpd.conf 主配置文件 /etc/pam.d/vsftpd PAM认证文件 /etc/vsftpd.ftpusers 禁止使用VSFTPD的用户列表文件 /etc/vsftpd.user_list 禁止或允许使用VSFTPD的用户列表文件 /var/ftp 匿名用户主目录 /var/ftp/pub 匿名用户的下载目录
FTP命令
- 命令详解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
ftp> ascii # 设定以ASCII方式传送文件(缺省值) ftp> bell # 每完成一次文件传送,报警提示. ftp> binary # 设定以二进制方式传送文件. ftp> bye # 终止主机FTP进程,并退出FTP管理方式. ftp> case # 当为ON时,用MGET命令拷贝的文件名到本地机器中,全部转换为小写字母. ftp> cd # 同UNIX的CD命令. ftp> cdup # 返回上一级目录. ftp> chmod # 改变远端主机的文件权限. ftp> close # 终止远端的FTP进程,返回到FTP命令状态, 所有的宏定义都被删除. ftp> delete # 删除远端主机中的文件. ftp> dir [remote-directory] [local-file] # 列出当前远端主机目录中的文件.如果有本地文件,就将结果写至本地文件. ftp> get [remote-file] [local-file] # 从远端主机中传送至本地主机中. ftp> help [command] # 输出命令的解释. ftp> lcd # 改变当前本地主机的工作目录,如果缺省,就转到当前用户的HOME目录. ftp> ls [remote-directory] [local-file] # 同DIR. ftp> macdef # 定义宏命令. ftp> mdelete [remote-files] # 删除一批文件. ftp> mget [remote-files] # 从远端主机接收一批文件至本地主机. ftp> mkdir directory-name # 在远端主机中建立目录. ftp> mput local-files # 将本地主机中一批文件传送至远端主机. ftp> open host [port] # 重新建立一个新的连接. ftp> prompt # 交互提示模式. ftp> put local-file [remote-file] # 将本地一个文件传送至远端主机中. ftp> pwd # 列出当前远端主机目录. ftp> quit # 同BYE. ftp> recv remote-file [local-file] # 同GET. ftp> rename [from] [to] # 改变远端主机中的文件名. ftp> rmdir directory-name # 删除远端主机中的目录. ftp> send local-file [remote-file] # 同PUT. ftp> status # 显示当前FTP的状态. ftp> system # 显示远端主机系统类型. ftp> user user-name [password] [account] # 重新以别的用户名登录远端主机. ftp> ? [command] # 同HELP. [command]指定需要帮助的命令名称。如果没有指定 command,ftp 将显示全部命令的列表。 ftp> ! # 从 ftp 子系统退出到外壳。
参考连接
以上