【Ftp学习】ubuntu 使用vsftpd 创建FTP服务(用户名密码登录,限制列出目录)
ubuntu 使用vsftpd 创建FTP服务
vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点。vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux、BSD、Solaris、 HP-UNIX等系统上面,是一个完全免费的、开放源代码的ftp服务器软件,支持很多其他的 FTP 服务器所不支持的特征。比如:非常高的安全性需求、带宽限制、良好的可伸缩性、可创建虚拟用户、支持IPv6、速率高等。
vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。
摘自百度百科-vsftpd
ubuntu 安装 vsftpd
$ sudo apt-get install vsftpd
使用apt安装即可。
配置vsftpd
备份vsftpd.config
$ sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.orig
编辑vsftpd.config
手动修改配置,根据下方的patch文件改一下。
$ sudo vim /etc/vsftpd.config
但是既然做了程序员就要懒一点,能自动就自动好了将配置好的文件与原始文件使用diff 生成的patch 文件,保存到本地,用patch命令更新即可。
1 --- /etc/vsftpd.conf.orig 2018-02-08 13:39:05.983282023 +0800 2 +++ /etc/vsftpd.conf 2018-02-10 11:14:15.584088172 +0800 3 @@ -28,11 +28,11 @@ 4 local_enable=YES 5 # 6 # Uncomment this to enable any form of FTP write command. 7 -#write_enable=YES 8 +write_enable=YES 9 # 10 # Default umask for local users is 077. You may wish to change this to 022, 11 # if your users expect that (022 is used by most other ftpd's) 12 -#local_umask=022 13 +local_umask=022 14 # 15 # Uncomment this to allow the anonymous FTP user to upload files. This only 16 # has an effect if the above global write enable is activated. Also, you will 17 @@ -67,11 +67,11 @@ 18 # 19 # You may override where the log file goes if you like. The default is shown 20 # below. 21 -#xferlog_file=/var/log/vsftpd.log 22 +xferlog_file=/var/log/vsftpd.log 23 # 24 # If you want, you can have your log file in standard ftpd xferlog format. 25 # Note that the default log file location is /var/log/xferlog in this case. 26 -#xferlog_std_format=YES 27 +xferlog_std_format=YES 28 # 29 # You may change the default value for timing out an idle session. 30 #idle_session_timeout=600 31 @@ -100,7 +100,7 @@ 32 #ascii_download_enable=YES 33 # 34 # You may fully customise the login banner string: 35 -#ftpd_banner=Welcome to blah FTP service. 36 +ftpd_banner=Welcome Lincoln Linux FTP Service. 37 # 38 # You may specify a file of disallowed anonymous e-mail addresses. Apparently 39 # useful for combatting certain DoS attacks. 40 @@ -120,9 +120,9 @@ 41 # the user does not have write access to the top level directory within the 42 # chroot) 43 #chroot_local_user=YES 44 -#chroot_list_enable=YES 45 +chroot_list_enable=YES 46 # (default follows) 47 -#chroot_list_file=/etc/vsftpd.chroot_list 48 +chroot_list_file=/etc/vsftpd.chroot_list 49 # 50 # You may activate the "-R" option to the builtin ls. This is disabled by 51 # default to avoid remote users being able to cause excessive I/O on large 52 @@ -142,7 +142,7 @@ 53 secure_chroot_dir=/var/run/vsftpd/empty 54 # 55 # This string is the name of the PAM service vsftpd will use. 56 -pam_service_name=vsftpd 57 +pam_service_name=ftp 58 # 59 # This option specifies the location of the RSA certificate to use for SSL 60 # encrypted connections. 61 @@ -152,4 +152,8 @@ 62 63 # 64 # Uncomment this to indicate that vsftpd use a utf8 filesystem. 65 -#utf8_filesystem=YES 66 +utf8_filesystem=YES 67 +userlist_enable=YES 68 +userlist_deny=NO 69 +userlist_file=/etc/vsftpd.user_list 70 +allow_writeable_chroot=YES
懒得手动改,可以将上面的patch 文件保存到机器上,然后使用
1 $ cd / 2 $ sudo patch -p0 < [patch文件路径] 3 这样就将配置更新了。 4 5 创建登录用户 6 #先创建ftp目录 7 $ sudo mkdir /home/ftpdir 8 #添加用户 9 $ sudo useradd -d /home/ftpdir -s /bin/bash ftpuser 10 #设置用户密码 11 $ sudo passwd ftpuser 12 #设置ftp目录用户权限 13 $ sudo chown ftpuser:ftpuser /home/ftpdir 14 15 添加vsftpd 登录用户 16 #新建文件/etc/vsftpd.user_list,用于存放允许访问ftp的用户: 17 $ sudo touch /etc/vsftpd.user_list 18 $ sudo vim /etc/vsftpd.user_list 19 在/etc/vsftpd.user_list中添加允许登录ftp 的用户 20 ftpuser 21 22 添加vsftpd登录用户对目录树的权限 23 #新建文件/etc/vsftpd.chroot_list,设置可列出、切换目录的用户: 24 $ sudo touch /etc/vsftpd.chroot_list 25 $ sudo vim /etc/vsftpd.chroot_list 26 在/etc/vsftpd.chroot_list 设置可列出、切换目录的用户 27 ftpuser
重启 vsftpd 服务
1 $ sudo service vsftpd restart
验证ftp服务
————————————————
版权声明:本文为CSDN博主「迦蓝叶」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/soslinken/article/details/79304076
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!