Linux搭建ftp服务器

一、允许匿名用户登录
安装vsftpd(一个开源免费的ftp服务器)
[root@instance-3hte1xi0 ~]# yum install vsftpd -y
安装ftp客户端
[root@instance-3hte1xi0 vsftpd]# yum install ftp -y
创建匿名用户的目录
[root@instance-3hte1xi0 vsftpd]# mkdir /var/Jack
更改目录的所属组和用户
[root@instance-3hte1xi0 vsftpd]# chown root:root /var/Jack
只赋予读的权限
[root@instance-3hte1xi0 vsftpd]# chmod -R 755 /var/Jack
创建一个测试的文件
[root@instance-3hte1xi0 vsftpd]# touch /var/Jack/ab.txt
[root@instance-3hte1xi0 ~]# vi /etc/vsftpd/vsftpd.conf
以下是vsftpd.conf的内容(根据自己的情况进行改动,#表示注释的内容,匿名用户默认只有读的权限,没有写入的权限,允许匿名用户写入是非常不安全的):

#允许本地用户登录
local_enable=YES
#允许写入
write_enable=YES
#本地用户创建文件或目录的掩码
local_umask=022

#允许匿名用户登录
anonymous_enable=YES
#允许匿名用户上传,默认是NO
#anon_upload_enable=YES
#允许匿名用户创建目录,默认是NO
#anon_mkdir_write_enable=YES

#当用户进入某个目录时,会提示要注意的内容
dirmessage_enable=YES
#允许记录日志
xferlog_enable=YES
#日志的位置
xferlog_file=/var/log/xferlog
xferlog_std_format=YES

#从20端口连接
connect_from_port_20=YES

#chown_uploads=YES
#chown_username=whoever

#设置本地用户的根目录
local_root=/var/Jack
#设置匿名用户的根目录
anon_root=/var/Jack

#data_connection_timeout=120
#nopriv_user=ftpsecure

#async_abor_enable=YES

#ascii_upload_enable=YES
#ascii_download_enable=YES

#登录ftp时的欢迎信息
#ftpd_banner=Welcome to blah FTP service.

#deny_email_enable=YES
#banned_email_file=/etc/vsftpd/banned_emails

#将用户限制在家目录内
#chroot_local_user=YES
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd/chroot_list

#ls_recurse_enable=YES

listen=YES

#listen_ipv6=YES

pam_service_name=vsftpd
#userlist_enable为YES且userlist_deny为NO时,表示只允许userlist文件中的用户登录。同理:userlist_deny为YES时(默认是YES),表示禁止userlist文件中的用户登录。
userlist_enable=YES
#userlist_deny=NO
tcp_wrappers=YES

启动vsftpd服务
[root@instance-3hte1xi0 vsftpd]# service vsftpd start
[root@instance-3hte1xi0 vsftpd]# ftp localhost
账号是anonymous,表示匿名用户,密码是空(直接按回车)
Name (localhost:root): anonymous
查看目录和文件,可以用ls或dir,更多命令可以用help查看
ftp> ls
227 Entering Passive Mode (127,0,0,1,247,53).
150 Here comes the directory listing.
-rw-r--r--    1 0        0               0 Aug 20 15:35 ab.txt
226 Directory send OK.
可以看到刚才创建的ab.txt
如果要允许写入和创建目录,就去掉下面两行的#,然后把根目录权限改成可写入,不过并不建议这样做
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES


二、不允许匿名用户登录(必须要账号才能登录)
创建根目录
[root@instance-3hte1xi0 vsftpd]# mkdir /var/Leo
赋予写的权限
[root@instance-3hte1xi0 ~]# chmod -R o+w /var/Leo
创建一个测试的文件
[root@instance-3hte1xi0 vsftpd]# touch /var/Leo/bc.txt
添加ftp用户,禁止本地登录
[root@instance-3hte1xi0 vsftpd]# useradd -s /sbin/nologin user1
[root@instance-3hte1xi0 vsftpd]# passwd user1
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
创建chroot_list文件
[root@instance-3hte1xi0 vsftpd]# touch /etc/vsftpd/chroot_list
[root@instance-3hte1xi0 vsftpd]# vi /etc/vsftpd/chroot_list
把user1添加进文件里面
[root@instance-3hte1xi0 vsftpd]# vi /etc/vsftpd/vsftpd.conf
以下是vsftpd.conf的内容(根据自己的情况进行改动,与上面的区别:1. anonymous_enable=NO 2.chroot_local_user相关设置)
#允许本地用户登录
local_enable=YES
#允许写入
write_enable=YES
#本地用户创建文件或目录的掩码
local_umask=022

#允许匿名用户登录
anonymous_enable=NO
#允许匿名用户上传,默认是NO
#anon_upload_enable=YES
#允许匿名用户创建目录,默认是NO
#anon_mkdir_write_enable=YES

#当用户进入某个目录时,会提示要注意的内容
dirmessage_enable=YES
#允许记录日志
xferlog_enable=YES
#日志的位置
xferlog_file=/var/log/xferlog
xferlog_std_format=YES

#从20端口连接
connect_from_port_20=YES

#chown_uploads=YES
#chown_username=whoever

#设置本地用户的根目录
local_root=/var/Leo
#设置匿名用户的根目录
#anon_root=/var/Jack

#data_connection_timeout=120
#nopriv_user=ftpsecure

#async_abor_enable=YES

#ascii_upload_enable=YES
#ascii_download_enable=YES

#登录ftp时的欢迎信息
#ftpd_banner=Welcome to blah FTP service.

#deny_email_enable=YES
#banned_email_file=/etc/vsftpd/banned_emails

#将用户限制在家目录内
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

#ls_recurse_enable=YES

listen=YES

#listen_ipv6=YES

pam_service_name=vsftpd
#userlist_enable为YES且userlist_deny为NO时,表示只允许userlist文件中的用户登录。同理:userlist_deny为YES时(默认是YES),表示禁止userlist文件中的用户登录。
userlist_enable=YES
#userlist_deny=NO
tcp_wrappers=YES

重启vsftpd服务
[root@instance-3hte1xi0 vsftpd]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@instance-3hte1xi0 vsftpd]# 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): user1
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,200,210).
150 Here comes the directory listing.
-rw-r--r--    1 0        0               0 Aug 20 16:26 bc.txt
226 Directory send OK.
可以看到刚才创建的bc.txt

参考资料:https://www.linuxidc.com/Linux/2017-06/144900.htm

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值