SFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP.
安全性是编写VSFTP的初衷,除了这与生俱来的安全特性以外,高速与高稳定性也是VSFTP的两个重要特点。
在速度方面,使用ASCII代码的模式下载数据时,VSFTP的速度是Wu-FTP的两倍,如果Linux主机使用2.4.*的内核,在千兆以太网上的下载速度可达86MB/S。
在稳定方面,VSFTP就更加的出色,VSFTP在单机(非集群)上支持4000个以上的并发用户同时连接,根据Red Hat的Ftp服务器的数据,VSFTP服务器可以支持15000个并发用户
安装vsftp
[root@localhost ~]# rpm -qa |grep ftp
gvfs-obexftp-1.4.3-15.el6.i686
[root@localhost ~]# mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
可以查看这个包的信息
[root@localhost Packages]# rpm -qip gvfs-obexftp-1.4.3-15.el6.i686.rpm
安装服务端
[root@localhost Packages]# rpm -ivh /media/cdrom/Packages/vsftpd-2.2.2-11.el6_3.1.i686.rpm
Preparing... ########################################### [100%]
1:vsftpd ########################################### [100%]
安装有关客户端 (该实验也可以在相同主机上)
[root@localhost Packages]# ll /media/cdrom/Packages/ |grep ftp
-r--r--r--. 2 root root 56856 Nov 9 2012 ftp-0.17-53.el6.i686.rpm
-r--r--r--. 2 root root 72784 Jul 31 2012 gvfs-obexftp-1.4.3-15.el6.i686.rpm
-r--r--r--. 2 root root 752916 Jul 2 2011 lftp-4.0.9-1.el6.i686.rpm
-r--r--r--. 2 root root 31508 Sep 25 2011 tftp-0.49-7.el6.i686.rpm
-r--r--r--. 2 root root 39276 Sep 25 2011 tftp-server-0.49-7.el6.i686.rpm
-r--r--r--. 2 root root 160540 Feb 19 2013 vsftpd-2.2.2-11.el6_3.1.i686.rpm
[root@localhost Packages]# rpm -ivh /media/cdrom/Packages/ftp-0.17-53.el6.i686.rpm
Preparing... ########################################### [100%]
1:ftp ########################################### [100%]
[root@localhost Packages]# rpm -ivh /media/cdrom/Packages/lftp-4.0.9-1.el6.i686.rpm
Preparing... ########################################### [100%]
1:lftp ########################################### [100%]
新增加一块硬盘sdb
Disk identifier: 0x000238d5
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 1175 9128960 83 Linux
/dev/sda3 1175 1306 1048576 82 Linux swap / Solaris
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
在新加的磁盘能看到之后,接下来分别是分区,格式化,和挂载(临时或永久性)编辑/etc/fstab
[root@localhost ~]# vim /etc/fstab
如图表示/dev/sdb1/ 挂载到mnt/part1 文件类型为自动识别,并且以usrquota来指明启动文件系统时支持磁盘配额模式。0 0 表示参数默认 0表示dump(备份)频率。0表示不备份,1表示每天,2表示不定期
另一个0表示是否进行fsck的开机磁盘完整性检查
wKiom1MApMeBfJPUAAAZTNrjRlU142.jpg
然后当我们以-a参数挂载时,此文件会被主动测试挂载(auto参数作用)
[root@localhost ~]# mkdir /mnt/part1
[root@localhost ~]# mount -a
因为要在该磁盘上做磁盘配置,所以要生成磁盘配额文件,我们可能要先安装配额产生要用的命令包
[root@localhost part1]# rpm -qa |grep quota
quota-3.17-18.el6.i686
先关闭selinux否则会报错:如下
quotacheck: Cannot create new quotafile /mnt/part1/aquota.user.new: Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
[root@localhost part1]# ll
total 12
drwx------. 2 root root 12288 Feb 15 01:29 lost+found
[root@localhost part1]# cd
[root@localhost ~]# cd /mnt/part1
[root@localhost part1]# setenforce 0
[root@localhost part1]# quotacheck -augvc
-a表示该盘中所有的(所以要在相关分区的挂载点下执行),-u计算用户在该盘所占的空间,-g计算组的,-v详细信息,-c忽略原有的
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/mnt/part1] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Old group file not found. Usage will not be substracted.
quotacheck: Checked 3 directories and 2 files
quotacheck: Old file not found.
[root@localhost part1]# ll
total 19
-rw-------. 1 root root 6144 Feb 15 03:18 aquota.user
drwx------. 2 root root 12288 Feb 15 01:29 lost+found
因aquota.user为二进制文件所以,我们想编辑他的话要用额外命令来编辑它,edquota -u 表示针对某一个用户的, -g某一个组的,-p表示拷贝
[root@localhost part1]# useradd user1
[root@localhost part1]# passwd user1
Changing password for user user1.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# edquato -u user1
wKioL1MApifDwjxTAAAvQpN3YW4996.jpg
wKiom1MAp2eAtHMyAAAwrwxKjuc791.jpg
如图中所示该文件中的soft表示软件限制,即它是警告级别的限制,达到该值时,用户每次登录时都会收到警告,而hard为硬件限制,即达到该值时硬盘会自动锁住,而一般系统在出现soft警告时会出现一个grace time,一般为7天,7天未做处理也会锁住,如图分别有blocks 限制和inodes限制
blocks 为0表示已用的块为0 inodes也是
[root@localhost part1]# useradd user2
[root@localhost part1]# passwd user2
Changing password for user user2.
New password:
BAD PASSWORD: it is too short
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost part1]# edquota -p user1 -u user2
[root@localhost part1]# edquota -u user2
[root@localhost part1]# quotaon /dev/sdb1
加入开机自动检测中
[root@localhost part1]# echo "quotaon /dev/sdb1" >>/etc/rc.d/rc.local
[root@localhost part1]# mkdir public
[root@localhost part1]# ll
total 22
-rw-------. 1 root root 7168 Feb 15 04:10 aquota.user
drwx------. 2 root root 12288 Feb 15 01:29 lost+found
drwxr-xr-x. 2 root root 1024 Feb 15 04:15 public
当我们新建一个目录时默认的本地权限中其他人(other)就是没有写入权限的,所以,接下来我们要做的就是怎么讲public作为匿名登录的目录
[root@localhost part1]# vim /etc/vsftpd/vsftpd.conf
改为如图内容
wKioL1MAqD7zvcKtAAA8wPkyMgA936.jpg
[root@localhost part1]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@localhost part1]# cd ./public/
[root@localhost public]# touch f1.txt
[root@localhost public]# touch f2.txt
[root@localhost public]# setenforce 0
[root@localhost public]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
在ftp的ftpuser和user_list文件中也可以编辑和登录用户有关的权限设置,在tcp_wrapper上做来源控制(vim /etc/hosts.allow,/etc.hosts.deny)
将用户的默认登录目录改为该用户的家目录
[root@localhost home]# mv user1 /mnt/part1/
[root@localhost home]# mv user2 /mnt/part1/
[root@localhost home]# vim /etc/passwd
[root@localhost home]# cd /mnt/part1/
[root@localhost part1]# mkdir ./home
[root@localhost part1]# mv user1 user2 ./home
登录测试,如图(注意此时即使是在本机上登录,如果是使用ip登录,而不是回环地址的话,一样是登录不上的,这是默认设置的原因)
wKiom1MAqNPT0aLmAACC9_eh7R4180.jpg
有关命令
wKioL1MAqU3gf9u-AABHU6CMvWo474.jpg
无写入权限
wKioL1MAqofBaUqjAACj-S4xnq4855.jpg
[root@localhost home]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost home]# useradd -D -b /mnt/part1/home
[root@localhost home]# useradd user3
[root@localhost home]# grep user3 /etc/passwd
user3:x:503:504::/mnt/part1/home/user3:/bin/bash
wKiom1MAqnbTA8hEAAAZRAE9vk0928.jpg
这样以后新加的用户就会自动将家目录移至以上所示目录下,并默认登录到这
wKiom1MAq4XDX1i-AABa7hHqCok806.jpg
测试磁盘配额
因为前面设置的只有10M(实际达不到10M),所以我们很容易看到磁盘的限额情况
wKiom1MArDyx2aAsAACPYyaEBdo696.jpg
还要把这个文件删除,以留出空间测试后面的,所以再用dd产生文件要在其他目录下
其他结果及步骤如下
wKioL1MAq3vRBx9ZAACt_6hHvwI277.jpg
wKioL1MArRTTX5aCAAAyYFdrmCs587.jpg
以管理员身份查看磁盘配额
wKiom1MArU2xBHG9AACD6nUCn7I016.jpg
[root@localhost public]# vim /etc/vsftpd/vsftpd.conf
wKioL1MArXXARR6IAAAqzzSyARM995.jpg
[root@localhost public]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@localhost public]# dd if=/dev/zero of=f3 bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0178166 s, 58.9 MB/s
[root@localhost public]# mv f3 ../home/user1
[root@localhost public]# cd /tmp
[root@localhost tmp]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): user1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (127,0,0,1,127,184).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1048576 Feb 16 02:09 f3
226 Directory send OK.
ftp> get f3
local: f3 remote: f3
227 Entering Passive Mode (127,0,0,1,116,177).
150 Opening BINARY mode data connection for f3 (1048576 bytes).
226 Transfer complete.
1048576 bytes received in 0.998 secs (1050.89 Kbytes/sec)
[root@localhost public]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get f3
local: f3 remote: f3
227 Entering Passive Mode (127,0,0,1,149,174).
150 Opening BINARY mode data connection for f3 (131072 bytes).
226 Transfer complete.
131072 bytes received in 0.656 secs (109.79 Kbytes/sec)
最大连接数测试(3)如图
[root@localhost public]# vim /etc/vsftpd/vsftpd.conf
wKiom1MArinzaZldAAAzdwWXYe4293.jpg
[root@localhost public]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
wKioL1MArk-gEtGkAABoQvtNyjI130.jpg
每个ip的最大连接数测试(2)如下
wKioL1MAriPClQlaAAEBOxChwDc040.jpg
[root@localhost public]# ftp 192.168.2.199
Connected to 192.168.2.199 (192.168.2.199).
421 There are too many connections from your internet address.
ftp> bye
支持配置目录的概念(针对每一个用户),在里面的针对用户的配置,将覆盖先前的系统配置,如annoymous
wKiom1MArsbiw0tqAAAYhLpp_tc950.jpg
[root@localhost public]# cd /etc/vsftpd/
[root@localhost vsftpd]# mkdir dir
[root@localhost vsftpd]# vim ./dir
[root@localhost vsftpd]# cd ./dir
[root@localhost dir]# vim user1
wKioL1MArsiRaoQ9AAANdMrDp3I804.jpg
[root@localhost dir]# vim user2
wKioL1MArtfyywYOAAAP7ByH9XA856.jpg
[root@localhost tmp]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): user2
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (127,0,0,1,146,163).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 131072 Feb 16 05:04 f3
226 Directory send OK.
ftp> get f3
local: f3 remote: f3
227 Entering Passive Mode (127,0,0,1,147,100).
150 Opening BINARY mode data connection for f3 (131072 bytes).
226 Transfer complete.
131072 bytes received in 33.4 secs (3.93 Kbytes/sec)
ftp> bye
[root@localhost tmp]# rm f3 (注意磁盘空间)
rm: remove regular file `f3'? y
[root@localhost tmp]# ftp 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1).
220 (vsFTPd 2.2.2)
Name (127.0.0.1:root): user2
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering Passive Mode (127,0,0,1,183,105).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 131072 Feb 16 05:04 f3
226 Directory send OK.
ftp> get f3
local: f3 remote: f3
227 Entering Passive Mode (127,0,0,1,173,103).
150 Opening BINARY mode data connection for f3 (131072 bytes).
226 Transfer complete.
131072 bytes received in 0.0655 secs (2000.89 Kbytes/sec)
ftp> bye
还可以通过上述配置文件来界定被动访问的最小最大端口(便于防火墙的端口控制)
pasv_max_port=
pasv_min_port=
知识补充:
(比特(bit,简称b也叫位),8个bit一组构成1个byte(叫字节)。一般键盘上的每个字符占用2个字节,一个汉字一般占用4个字节。再往上就是1024进位了,1024字节=1kb
1024kb=1mb
1024mb=1G
注意:MiB和MB,KiB和KB等的区别:
1KB(kilobyte)=1000byte, 1KiB(kibibyte)=1024byte
1MB(megabyte)=1000000byte, 1MiB(mebibyte)=1048576byte
硬盘生产商是以GB(十进制,即10的3次方=1000,如1MB=1000KB)计算的,而电脑(操作系统)是以GiB(2进制,即2的10次方,如1MiB=1024KiB)计算的,但国内用户一般理解为1MB=1024KB, 所以为了便于中文化的理解,翻译MiB为MB也是可以的。
同样根据硬盘厂商与用户对于1MB大小的不同理解,所以好多160G的硬盘实际容量按计算机实际的1MB=1024KB算都不到160G,这也可以解释为什么新买的硬盘“缺斤短两”并没有它所标示的那么大。
宽带网络中,运营商们所说的1M带宽是指1Mbps(megabits per second,兆比特每秒)。bps是bit per Second的缩写,也就是每秒多少“位”(bit)的意思。是用来计算资料传输速率的单“位”。举例来说,电信局通常说的1M的宽,所使用的单位就是bps,我们都知道一个字节等于8位,而我们电脑的存储单位使用的是字节,也就是理论上每秒可以向硬盘下载1X1024/8=128KB/sec的数据。但这也只是理论上的速度。实际上则要再扣约12%的数据头信息(包Ethernet Header,IP Header,TCP Header,ATM Header等),各种各样的控制讯号。所以传输速度上限应112KB/sec左右,而不应该望文生义地理解为“每秒钟可以传送1M字节的数据。所以千万不要迷信广告,传输单位的写法上,B和b分别代表Bytes和bits,两者定义不同,差距是8倍)
阅读(1855) | 评论(0) | 转发(0) |