Linux_3day

时间:2015-08-30 17:43:50   收藏:0   阅读:273

1.在Centos5.5下搭建ftp服务器

(1)安装vsftpd

[root@localhost home]#yum install vsftpd

(2)完成安装后执行

[root@xxzx /]# vi /etc/vsftpd/user_list

将root注释掉:#root

[root@xxzx /]# vi /etc/vsftpd/ftpusers

将root注释掉:#root

(3)设置ftp登录后所在的目录

[root@xxzx /]# setsebool -P ftpd_disable_trans=1
[root@xxzx vsftpd]# vi /etc/vsftpd/vsftpd.conf

在最后一行添加:local_root=/tmp

(4)重启服务

[root@xxzx vsftpd]# service vsftpd restart
Shutting down vsftpd:   [FAILED]
Starting vsftpd for vsftpd: [  OK  ]

vsftpd.conf配置说明

  1. vsftpd.ftpusers:位于/etc目录下。它指定了哪些用户账户不能访问FTP服务器,例如root等。

  2. vsftpd.user_list:位于/etc目录下。该文件里的用户账户在默认情况下也不能访问FTP服务器,仅当vsftpd.conf配置文件里启用userlist_enable=NO选项时才允许访问。

  3. vsftpd.conf:位于/etc/vsftpd目录下。来自定义用户登录控制、用户权限控制、超时设置、服务器功能选项、服务器性能选项、服务器响应消息等FTP服务器的配置。

高级设置


1. 用户登录控制


2. 用户权限控制


3.用户连接和超时选项


4.服务器日志和欢迎信息



实例1:

1. 创建一个用户test

adduser -d /tmp/test  -g ftp -s /sbin/nologin test#创建用户test,用户路径为/tmp/test,用户组为ftp,不能登录
[root@xxzx tmp]# passwd test
Changing password for user test.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

2. 限制用户目录,不得改变目录到上级

[root@xxzx tmp]# vi /etc/vsftpd/vsftpd.conf#编辑配置文件
chroot_list_enable=YES#注释去掉
chroot_list_file=/etc/vsftpd/chroot_list#注释去掉
[root@xxzx tmp]# vi /etc/vsftpd/chroot_list
test#填写需要限制路径的用户名
[root@xxzx tmp]# service vsftpd restart#重启服务
Shutting down vsftpd:  [  OK  ]
Starting vsftpd for vsftpd: [  OK  ]

3.限制匿名登录

[root@xxzx tmp]# vi /etc/vsftpd/vsftpd.conf#编辑配置文件
anonymous_enable=NO#不允许匿名登录
anon_upload_enable=NO#不允许匿名登录上传
anon_mkdir_write_enable=NO#不允许匿名登录创建文件夹
service vsftpd restart#重启vsftpd服务


4.最后为了防止服务器由于断电、重启等现象发生,导致ftp进程在开机后未启动,将其添加到开机启动文件中:

[root@xxzx tmp]# vi /etc/rc.local#编辑开机启动文件
service vsftpd start#在最后一行添加ftp服务启动命令,保存

5.登录测试

如果出现无法访问,尝试关闭防火墙测试:

临时生效,重启后复原

service iptables start#运行
service iptables stop#终止

永久性生效,重启后不会复原

chkconfig iptables on#开启
chkconfig iptables off#关闭

实例2:多用户

[root@xxzx /]# groupadd dep1
[root@xxzx /]# groupadd dep2
[root@xxzx /]# groupadd dep3
[root@xxzx /]# groupadd dep4
[root@xxzx /]# groupadd public#创建用户组
[root@xxzx /]# useradd -G dep1,public user1
[root@xxzx /]# useradd -G dep2,public user2
[root@xxzx /]# useradd -G dep3,public user3
[root@xxzx /]# useradd -G dep4,public user4
[root@xxzx /]# useradd -G dep4,public,dep1,dep2,dep3 admin#创建用户并关联组
[root@xxzx /]# mkdir -p /tmp/ftp/dep1
[root@xxzx /]# mkdir -p /tmp/ftp/dep2
[root@xxzx /]# mkdir -p /tmp/ftp/dep3
[root@xxzx /]# mkdir -p /tmp/ftp/dep4
[root@xxzx /]# mkdir -p /tmp/ftp/public#创建文件夹
[root@xxzx /]# chown user1:dep1 /tmp/ftp/dep1
[root@xxzx /]# chown user2:dep2 /tmp/ftp/dep2
[root@xxzx /]# chown user3:dep3 /tmp/ftp/dep3
[root@xxzx /]# chown user4:dep4 /tmp/ftp/dep4
[root@xxzx /]# chown admin:public /tmp/ftp/public#关联用户组和文件夹
[root@xxzx /]# chmod 770 /tmp/ftp/dep1
[root@xxzx /]# chmod 770 /tmp/ftp/dep2
[root@xxzx /]# chmod 770 /tmp/ftp/dep3
[root@xxzx /]# chmod 770 /tmp/ftp/dep4
[root@xxzx /]# chmod 770 /tmp/ftp/public#修改文件夹权限,同组用户及自己拥有权限
[root@xxzx /]# passwd user1
Changing password for user user1.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@xxzx /]# passwd user2
Changing password for user user2.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@xxzx /]# passwd user3
Changing password for user user3.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@xxzx /]# passwd user4
Changing password for user user4.
New UNIX password: 
BAD PASSWORD: it is WAY too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.
[root@xxzx /]# passwd admin
Changing password for user admin.
New UNIX password: 
BAD PASSWORD: it is too short
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.#修改密码
[root@xxzx /]# vi /etc/vsftpd/vsftpd.conf
local_root=/tmp/ftp#修改用户登录后显示的目录
user_config_dir=/etc/vsftpd/ftp_config/dir#设置用户拥有独立的配置
[root@xxzx /]# vi  /etc/vsftpd/ftp_config_dir/user1#设置用户独立权限
cmds_allowed=ABOR,ACCT,APPE,CWD,CDUP,HELP,LIST,MODE,MDTM,NOOP,NLST,PASS,PASV,PORT,PWD,QUIT,REIN,RETR,SITE,SIZE,STOR,STAT,STOU,STRU,SYST,TYPE,USER#用户的权限
[root@xxzx /]# cd /etc/vsftpd/ftp_config_dir
[root@xxzx ftp_config_dir]# cp user1 user2#将user1的权限拷贝给user2
[root@xxzx ftp_config_dir]# cp user1 user3
[root@xxzx ftp_config_dir]# cp user1 user4
[root@xxzx ~]# service vsftpd restart#重启服务




原文:http://keefe.blog.51cto.com/9548710/1689818

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!