建站不啰嗦,上手跟我做(二十七)安装 ftp 服务

安装 vsftpd,修改配置文件

[root@localhost ~]# yum -y install vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO							# 禁止匿名登录
ascii_upload_enable=YES
ascii_download_enable=YES					# ASCII模式开启
chroot_local_user=YES						# 限制主目录
user_config_dir=/etc/vsftpd/userconfig		# 用户目录配置文件目录

创建用户

[root@localhost ~]# useradd -s /sbin/nologin test
[root@localhost ~]# passwd test
Changing password for user test.
New password: 
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.

创建用户目录配置

[root@localhost ~]# mkdir /etc/vsftpd/userconfig
[root@localhost ~]# cd /etc/vsftpd/userconfig
[root@localhost userconfig]# vim test
local_root=/var/ftp/test

创建目录、设置权限

[root@localhost userconfig]# mkdir /var/ftp/test
[root@localhost userconfig]# setfacl -m u:test:rwx /var/ftp/test
[root@localhost userconfig]# getfacl /var/ftp/test
getfacl: Removing leading '/' from absolute path names
# file: var/ftp/test
# owner: root
# group: root
user::rwx
user:test:rwx
group::r-x
mask::rwx
other::r-x

[root@localhost userconfig]# cd /var/ftp/test
[root@localhost test]# echo hello,ftp! > test.txt
[root@localhost test]# ls
test.txt
[root@localhost test]# 

启动服务

[root@localhost test]# service vsftpd start

检查 /home/test 的权限

[root@localhost test]# chmod 777 /home/test

检查 ftp 的服务状态

[root@localhost test]# sestatus -b |grep ftp
allow_ftpd_anon_write                       off
allow_ftpd_full_access                      off
allow_ftpd_use_cifs                         off
allow_ftpd_use_nfs                          off
ftp_home_dir                                off
ftpd_connect_db                             off
ftpd_use_fusefs                             off
ftpd_use_passive_mode                       off
httpd_enable_ftp_server                     off
tftp_anon_write                             off
tftp_use_cifs                               off
tftp_use_nfs                                off

修改 ftp_home_dir 为 on

[root@localhost test]# sestatus -b |grep ftp
allow_ftpd_anon_write                       off
allow_ftpd_full_access                      off
allow_ftpd_use_cifs                         off
allow_ftpd_use_nfs                          off
ftp_home_dir                                on
ftpd_connect_db                             off
ftpd_use_fusefs                             off
ftpd_use_passive_mode                       off
httpd_enable_ftp_server                     off
tftp_anon_write                             off
tftp_use_cifs                               off
tftp_use_nfs                                off

重启 FTP 服务

[root@localhost test]# service vsftpd restart 
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
### 登录ftp服务
C:\Users\cjl>ftp 192.168.218.204
连接到 192.168.218.204。
220 (vsFTPd 2.2.2)
用户(192.168.218.204:(none)): test
331 Please specify the password.
密码:
230 Login successful.
ftp> ls

linux 登录 ftp

[root@localhost test]# ftp localhost
-bash: ftp: command not found
[root@localhost test]# yum install ftp
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
[root@localhost test]# ftp localhost
Trying ::1...
ftp: connect to address ::1Connection refused
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (localhost:root): test
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (127,0,0,1,149,196).
150 Here comes the directory listing.
-rw-r--r--    1 0        0              11 Nov 15 09:52 test.txt
226 Directory send OK.
ftp> 

可能存在的问题

ftp> mkdir data
550 Create directory operation failed.
ftp> put D:\data\M2M\M2M_01_31_20190702000000_20190702235959.txt
200 PORT command successful. Consider using PASV.
553 Could not create file.
[root@localhost local]# vim /etc/selinux/config
SELINUX=disabled

如果在想不重启系统的情况下关掉SELINUX,可以输入命令:
[root@localhost local]# setenforce 0
ftp> mkdir data
257 "/data" created
ftp> put D:\data\M2M\M2M_01_31_20190702000000_20190702235959.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 发送 83 字节,用时 0.00秒 27.67千字节/秒。

上一篇 建站不啰嗦,上手跟我做(二十六)定时任务备份 mysql 数据库
目录
下一篇 建站不啰嗦,上手跟我做(二十八)nacos 注册中心搭建