debian9.6搭建ftp服务器和安装ftp客户端

        ftp服务器是用于共享文件的,可以上传文件,也可以下载文件。vsftp服务器是其中一种,我这边就安装它。

一,搭建ftp服务器:

1,安装

guoyanzhang@bogon:~$ sudo apt-get install vsftpd

  2,配置(cat的结果是我的配置内容)

guoyanzhang@bogon:~$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
guoyanzhang@bogon:~$ sudo cat /etc/vsftpd.conf
[sudo] guoyanzhang 的密码:
# begin my configurations

listen=YES
listen_address=192.168.1.92
anonymous_enable=NO
local_umask=022
local_enable=YES
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
utf8_filesystem=YES
tcp_wrappers=YES

userlist_file=/etc/vsftpd.user_list

chroot_list_file=/etc/vsftpd.chroot_list
local_root=/home/guoyanzhang/myftp

# end my configurations

3,新建ftp根目录,并增加权限

guoyanzhang@bogon:~$ pwd
/home/guoyanzhang
guoyanzhang@bogon:~$ sudo mkdir -m 777 myftp

4,重启,停止,启动服务器

guoyanzhang@bogon:~$ sudo /etc/init.d/vsftpd restart
[ ok ] Restarting vsftpd (via systemctl): vsftpd.service.
guoyanzhang@bogon:~$ sudo /etc/init.d/vsftpd stop
[ ok ] Stopping vsftpd (via systemctl): vsftpd.service.
guoyanzhang@bogon:~$ sudo /etc/init.d/vsftpd start
[ ok ] Starting vsftpd (via systemctl): vsftpd.service.

5,添加用户名和密码

guoyanzhang@bogon:~$ sudo useradd -d /home/guoyanzhang/myftp gyz
guoyanzhang@bogon:~$ sudo passwd gyz
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码

6, 新建文件vsftpd.user_list,cat的内容就是刚刚添加的用户名

guoyanzhang@bogon:~$ sudo cat /etc/vsftpd.user_list 
gyz

 7,新建文件vsftpd.chroot_list(针对问题500),不需要添加任何用户,如果添加,这个用户可以访问ftp根文件之外的文件

guoyanzhang@bogon:~$ sudo vim /etc/vsftpd.chroot_list 

 8,针对可能出现的问题(530),修改文件:

guoyanzhang@bogon:~$ sudo vim /etc/selinux/config
#SELINUX=permissive
SELINUX=disable

 9,针对530问题,删除文件,适合于ubuntu/debian系统:

guoyanzhang@bogon:~$ sudo rm /etc/pam.d/vsftpd 

因为ubuntu/debian启用了PAM,所在用到vsftp时需要用到 /etc/pam.d/vsftpd 这个文件(默认源码安装的不会有这个文件),因此除了匿名用户外本地用户无法登录。所以解决的办法就是删除这个文件

二,安装ftp客户端:

guoyanzhang@bogon:~$ ftp 192.168.1.92
bash: ftp: 未找到命令
guoyanzhang@bogon:~$ sudo apt-get install ftp
guoyanzhang@bogon:~$ ftp 192.168.1.92
Connected to 192.168.1.92.
220 (vsFTPd 3.0.3)
Name (192.168.1.92:guoyanzhang):

开始是没有ftp这个命令的,所以安装一下,即客户端。

三,本机测试:

guoyanzhang@bogon:~$ ftp 192.168.1.92
Connected to 192.168.1.92.
220 (vsFTPd 3.0.3)
Name (192.168.1.92:guoyanzhang): gyz
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/home/guoyanzhang/myftp" is the current directory
ftp> bye
221 Goodbye.

参考1:FTP服务器

参考2:Linux下搭建FTP服务器(Ubuntu16.04)

参考3:http://www.phpfans.net/ask/fansa1/1761721543.html

参考4:https://www.aliyun.com/jiaocheng/118890.htm

 附录:

FTP 数字代码的意义
110 重新启动标记应答。
120 服务在多久时间内ready。
125 数据链路埠开启,准备传送。
150 文件状态正常,开启数据连接端口。
200 命令执行成功。
202 命令执行失败。
211 系统状态或是系统求助响应。
212 目录的状态。
213 文件的状态。
214 求助的讯息。
215 名称系统类型。
220 新的联机服务ready。
221 服务的控制连接埠关闭,可以注销。
225 数据连结开启,但无传输动作。
226 关闭数据连接端口,请求的文件操作成功。
227 进入passive mode。
230 使用者登入。
250 请求的文件操作完成。
257 显示目前的路径名称。
331 用户名称正确,需要密码。
332 登入时需要账号信息。
350 请求的操作需要进一部的命令。
421 无法提供服务,关闭控制连结。
425 无法开启数据链路。
426 关闭联机,终止传输。
450 请求的操作未执行。
451 命令终止:有本地的错误。
452 未执行命令:磁盘空间不足。
500 格式错误,无法识别命令。
501 参数语法错误。
502 命令执行失败。
503 命令顺序错误。
504 命令所接的参数不正确。
530 未登入。
532 储存文件需要账户登入。
550 未执行请求的操作。
551 请求的命令终止,类型未知。
552 请求的文件终止,储存位溢出。
553 未执行请求的的命令,名称不正确。

猜你喜欢

转载自blog.csdn.net/weixin_39465823/article/details/86100848