linux搭建ftp服务器

参考链接:https://www.freesion.com/article/41911387635/

创建用户参考:https://blog.csdn.net/zhx_0323/article/details/128098365;https://blog.csdn.net/hanmo22357/article/details/127739340

一、下载安装配置

1.下载

1.1 下载服务端(链接: https://pan.baidu.com/s/19ec7yab3WMsK-gb7Auh-DA  密码: hnom)

1.2 下载客户端(链接: https://pan.baidu.com/s/1cqM45TsSem5iGrImCfBhrQ  密码: qglt)

注:客户端必须安装,否则ftp命令无法使用(-bash: ftp: command not found)

2.上传安装包到服务器,放在安装目录,比如/home/ 下

3.执行安装命令

1 #fpt服务端安装   
2 [root@fan102 ~]# rpm -Uvh vsftpd-3.0.2-27.el7.x86_64.rpm
3 #fpt客户端安装   
4 [root@fan102 ~]# rpm -Uvh ftp-0.17-67.el7.x86_64.rpm

4.修改配置文件

复制代码
 1 #修改服务端配置文件   
 2 [root@fan102 ~]# vi /etc/vsftpd/vsftpd.conf
 3 #anonymous_enable=YES修改为anonymous_enable=NO
 4 #添加内容如下 
 5 reverse_lookup_enable=NO
 6 pam_service_name=vsftpd
 7 userlist_enable=NO
 8 tcp_wrappers=YES 
 9 #listen_port=21 
10 #默认端口号是21,如果需要改端口号,则需编辑 /etc/services 文件,将其中的 ftp 21/tcp 改为对应的端口号
复制代码

 

5.启动

1 #服务启动
2 [root@fan102 ~]# systemctl start vsftpd.service

 

二、新增用户

 

复制代码
 1 #新增用户并指定文件用户文件,示例用户为ftpuser
 2 [root@fan102 ~]# useradd -d /home/vsftpd ftpuser
 3 #设置密码,先输用户名,回车后再输密码
 4 [root@fan102 ~]# passwd ftpuser 123456
 5 #限定用户不能telnet,只能ftp
 6 [root@fan102 ~]# usermod -s /sbin/nologin ftpuser
 7 #用户ftpuser恢复正常(这一步很关键,否则登录不了)
 8 [root@fan102 ~]# usermod -s /sbin/bash ftpuser
 9 #更改用户ftpuser的主目录为/home/vsftpd(这一步可以跟第一步合并)
10 [root@fan102 ~]# usermod -d /home/vsftpd ftpuser
11 #将该用户加入到用户列表中
12 [root@fan102 ~]# vi /etc/vsftpd/user_list
13 #修改配置文件/etc/pam.d/vsftpd
14 [root@fan102 ~]# vi /etc/pam.d/vsftpd
15 #第三行 auth required pam_shells.so改为auth required pam_nologin.so
复制代码

 

三、登录校验

1.重启服务器

1 #服务重启
2 [root@fan102 ~]# systemctl restart vsftpd.service

 

2.连接服务端

复制代码
 1 #连接ftp服务
 2 [root@fan102 ~]# ftp 172.16.1.102 21
 3 Connected to 172.31.12.215 (172.31.12.215).
 4 220 (vsFTPd 3.0.2)
 5 Name (172.31.12.215:root): zion
 6 331 Please specify the password.
 7 Password:
 8 230 Login successful.
 9 Remote system type is UNIX.
10 Using binary mode to transfer files.
11 ftp> quit
12 221 Goodbye.
复制代码

230代表成功

 

四、登录失败

1.错误代码:530

530 Login incorrect

1 #查看日志
2 [root@fan102 ~]# tail /var/log/secure

日志内容:pam_unix(vsftpd:auth): authenticatio,pam_unix(vsftpd:auth): check pass

pam_unix(vsftpd:auth): authentication failure,logname= uid=0

原因

这个是因为你创建的用户是不需要登陆的你设置了nologin,然后登陆的时候会去/etc/passwd下面检查这个用户,必须为/etc/shells类型才能登陆。所以你就报错了,现在你应该去这里改

解决

复制代码
 1 #修改配置文件
 2 [root@fan102 ~]# vi /etc/pam.d/vsftpd
 3 #第四行 设置为nologin,或者注释掉
 4  
 5 #%PAM-1.0
 6 session optional pam_keyinit.so force revoke
 7 auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
 8 auth required pam_nologin.so
 9 auth include password-auth
10 account include password-auth
11 session required pam_loginuid.so
12 session include password-auth
复制代码

 

2.错误代码:500

500 OOPS: could not read chroot() list file:/etc/vsftpd/chroot_list

原因:用户没有变更根目录的权限,ftp用户默认的根目录是/home/zion,如果要切换登陆目录,需要给予权限

解决

第一步:

1 #修改配置文件
2 [root@fan102 ~]# /etc/vsftpd/vsftpd.conf
3 
4 #内容如下
5 chroot_local_user=YES
6 chroot_list_enable=YES
7 chroot_list_file=/etc/vsftpd/chroot_list

 

第二步:在/etc/vsftpd/vsftpd创建chroot_list并将用户(zion)加入该文件

1 #创建chroot_list并将用户加入该文件
2 [root@fan102 ~]# /etc/vsftpd/chroot_list
3  
4 #文件内容
5 ftpuser

 

posted on   德邦总管  阅读(336)  评论(2编辑  收藏  举报

相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
< 2025年2月 >
26 27 28 29 30 31 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 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示