Centos下搭建ftp服务器
完全不用那么麻煩,直接可以用xshell中自帶的傳輸文件功能,下載客戶端xftp安裝就行,不用配置,可以在windows系統(tǒng)向Linux系統(tǒng)的任何文件地方上傳下載文件,簡單方便,大大節(jié)約時間,
vsftpd是什么鬼,配置麻煩浪費(fèi)時間。
xshell 強(qiáng)大的安全終端模擬軟件;xftp強(qiáng)大的安全的可靠的SFTP、FTP文件傳輸軟件(當(dāng)然還得現(xiàn)在Linux系統(tǒng)下安裝vsftpd服務(wù)器)。
?
?
?
一. ?FTP 說明
???? linux 系統(tǒng)下常用的FTP 是vsftp, 即Very Security File Transfer Protocol. 還有一個是proftp(Profession ftp)。 我們這里也是簡單的說明下vsftp的配置。
?vsftp提供3種遠(yuǎn)程的登錄方式:
?(1)匿名登錄方式
??? ???????? 就是不需要用戶名,密碼。就能登錄到服務(wù)器電腦里面
(2)本地用戶方式
????????????? 需要帳戶名和密碼才能登錄。而且,這個帳戶名和密碼,都是在你linux系統(tǒng)里面,已經(jīng)有的用戶。
?(3)虛擬用戶方式
??? ? 同樣需要用戶名和密碼才能登錄。但是和上面的區(qū)別就是,這個用戶名和密碼,在你linux系統(tǒng)中是沒有的(沒有該用戶帳號)
二.? Vsftp的安裝配置
2.1? 安裝
vsftp 的安裝包,可以在安裝里找到。 用yum 安裝過程也很簡單。
?????? 安裝命令:yum install vsftpd
2.2. 相關(guān)命令
2.2.1 啟動與關(guān)閉
[root@singledb ~]# service vsftpd start
Starting vsftpd for vsftpd:??????????????????????????????? [? OK? ]
[root@singledb ~]# service vsftpd stop
Shutting down vsftpd:????????????????????????????????????? [? OK? ]
[root@singledb ~]# service vsftpd restart
Shutting down vsftpd:????????????????????????????????????? [FAILED]
Starting vsftpd for vsftpd:??????????????????????????????? [? OK? ]
[root@singledb ~]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:??????????????????????????????? [FAILED]
[root@singledb ~]# /etc/init.d/vsftpd stop
Shutting down vsftpd:????????????????????????????????????? [? OK? ]
[root@singledb ~]# /etc/init.d/vsftpd restart
Shutting down vsftpd:????????????????????????????????????? [FAILED]
Starting vsftpd for vsftpd:??????????????????????????????? [? OK? ]
[root@singledb ~]# /etc/init.d/vsftpd status
vsftpd (pid 3931) is running...
[root@singledb ~]#
2.2.2. 其他命令
--查看vsftpd 啟動狀態(tài)
[root@singledb ~]# chkconfig --list vsftpd
vsftpd????????? 0:off?? 1:off?? 2:off?? 3:off?? 4:off?? 5:off?? 6:off
[root@singledb ~]# chkconfig? vsftpd on
[root@singledb ~]# chkconfig --list vsftpd
vsftpd????????? 0:off?? 1:off?? 2:on??? 3:on??? 4:on??? 5:on??? 6:off
?????? 這里看到,默認(rèn)情況下從2到5設(shè)置為on了。2到5是多用戶級別。 這個對應(yīng)的是linux不同的運(yùn)行級別。
我們也可以加level 選項(xiàng)來指定:
[root@singledb ~]# chkconfig --level 0 vsftpd on???
[root@singledb ~]# chkconfig --list vsftpd?????
vsftpd????????? 0:on??? 1:off?? 2:on??? 3:on??? 4:on??? 5:on??? 6:off
我們看到0已經(jīng)設(shè)置為on了。
我們可以使用man chkconfig 來查看幫助:
--level levels
??? Specifies the run levels an operation should pertain to. It is? given? as? a string of numbers from 0 to 7. For example, --level 35 specifies runlevels 3????????????? and 5.
?????? 傳統(tǒng)的init 定義了7個運(yùn)行級(run level),每一個級別都代表系統(tǒng)應(yīng)該補(bǔ)充運(yùn)行的某些特定服務(wù):
????????????? (1)0級是完全關(guān)閉系統(tǒng)的級別
????????????? (2)1級或者S級代表單用戶模式
????????????? (3)2-5 級 是多用戶級別
????????????? (4)6級 是 重新引導(dǎo)的級別
關(guān)于Linux 的運(yùn)行級別,在我的Blog:
?????? Linux 開機(jī)引導(dǎo)與關(guān)機(jī)過程(5.1 init 和運(yùn)行級)
???????http://blog.csdn.net/tianlesoftware/archive/2010/10/24/5962460.aspx
(1)查看防火墻
??? 我一般都是把系統(tǒng)的防火墻關(guān)閉了。 因?yàn)殚_了會有很多限制。
[root@singledb ~]# /etc/init.d/iptables status
Table: nat
Chain PREROUTING (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
Chain POSTROUTING (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? MASQUERADE? all? --? 192.168.122.0/24??? !192.168.122.0/24???
Chain OUTPUT (policy ACCEPT)
num? target???? prot opt source?????????????? destination???? ????
Table: filter
Chain INPUT (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:53
2??? ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0??????? ???tcp dpt:53
3??? ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:67
4??? ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? tcp dpt:67
Chain FORWARD (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? ACCEPT???? all? --? 0.0.0.0/0??????????? 192.168.122.0/24??? state RELATED,ESTABLISHED
2??? ACCEPT???? all? --? 192.168.122.0/24???? 0.0.0.0/0??????????
3??? ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
4??? REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-port-unreachable
5??? REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT)
num? target???? prot opt source???????? ??????destination????????
You have new mail in /var/spool/mail/root
--添加開放21號端口:
[root@singledb ~]# /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
[root@singledb ~]# /etc/init.d/iptables status? ??????????????????????
Table: nat
Chain PREROUTING (policy ACCEPT)
num? target???? prot opt source?????????????? destination ????????
Chain POSTROUTING (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? MASQUERADE? all? --? 192.168.122.0/24??? !192.168.122.0/24???
Chain OUTPUT (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
Table: filter
Chain INPUT (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? tcp dpt:21
2??? ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:53
3??? ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? tcp dpt:53
4??? ACCEPT???? udp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? udp dpt:67
5??? ACCEPT???? tcp? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? tcp dpt:67
Chain FORWARD (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
1??? ACCEPT???? all? --? 0.0.0.0/0??????????? 192.168.122.0/24??? state RELATED,ESTABLISHED
2??? ACCEPT???? all? --? 192.168.122.0/24???? 0.0.0.0/0? ?????????
3??? ACCEPT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0??????????
4??? REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-port-unreachable
5??? REJECT???? all? --? 0.0.0.0/0??????????? 0.0.0.0/0?????????? reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT)
num? target???? prot opt source?????????????? destination????????
--保存配置
[root@singledb ~]# /etc/rc.d/init.d/iptables save
Saving firewall rules to /etc/sysconfig/iptables:????????? [? OK? ]
--重啟防火墻:
[root@singledb ~]# service iptables {start|stop|restart}
(2)查看關(guān)閉selinux
[root@singledb ~]# sestatus
SELinux status:??? ?????????????disabled
我這里在安裝操作系統(tǒng)的時候就關(guān)閉了selinux,如果沒有關(guān)閉,可以修改如下文件來關(guān)閉:
[root@singledb ~]# cat /etc/sysconfig/selinux(查看用cat,修改用vi)
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#?????? enforcing - SELinux security policy is enforced.
#?????? permissive - SELinux prints warnings instead of enforcing.
#?????? disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#?????? targeted - Only targeted network daemons are protected.
#?????? strict - Full SELinux protection.
SELINUXTYPE=targeted
[root@singledb ~]#
保存退出并重啟系統(tǒng)reboot
三. ?FTP配置文件
FTP 安裝好之后,在/etc/vsftpd/目錄下會有如下文件:
[root@singledb ~]# cd /etc/vsftpd/
[root@singledb vsftpd]# ls
ftpusers? user_list? vsftpd.conf? vsftpd_conf_migrate.sh
[root@singledb vsftpd]#
vsftpd.conf: 主配置文件
ftpusers: 指定哪些用戶不能訪問FTP服務(wù)器
user_list: 指定的用戶是否可以訪問ftp服務(wù)器由vsftpd.conf文件中的userlist_deny的取值來決定。
[root@singledb vsftpd]# cat user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
我們過濾掉#的注釋后,查看一下vsftpd.conf 文件:
[root@singledb ftp]# cat /etc/vsftpd/vsftpd.conf |grep -v '^#';
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=yes
tcp_wrappers=YES(以上三個可能需手動添加)
至于這些參數(shù)的意思,在注釋里有詳細(xì)的說明。
我們可以在vsftpd.conf 文件設(shè)置如下參數(shù):
(1)ftpd_banner=welcome to ftp service :設(shè)置連接服務(wù)器后的歡迎信息
(2)idle_session_timeout=60 :限制遠(yuǎn)程的客戶機(jī)連接后,所建立的控制連接,在多長時間沒有做任何的操作就會中斷(秒)
(3)data_connection_timeout=120 :設(shè)置客戶機(jī)在進(jìn)行數(shù)據(jù)傳輸時,設(shè)置空閑的數(shù)據(jù)中斷時間
(4)accept_timeout=60 設(shè)置在多長時間后自動建立連接
(5)connect_timeout=60 設(shè)置數(shù)據(jù)連接的最大激活時間,多長時間斷開,為別人所使用;
(6)max_clients=200 指明服務(wù)器總的客戶并發(fā)連接數(shù)為200
(7)max_per_ip=3 指明每個客戶機(jī)的最大連接數(shù)為3
(8)local_max_rate=50000(50kbytes/sec)? 本地用戶最大傳輸速率限制
(9)anon_max_rate=30000匿名用戶的最大傳輸速率限制
(10)pasv_min_port=端口
(11)pasv-max-prot=端口號 定義最大與最小端口,為0表示任意端口;為客戶端連接指明端口;
(12)listen_address=IP地址 設(shè)置ftp服務(wù)來監(jiān)聽的地址,客戶端可以用哪個地址來連接;
(13)listen_port=端口號 設(shè)置FTP工作的端口號,默認(rèn)的為21
(14)chroot_local_user=YES 設(shè)置所有的本地用戶可以chroot
(15)chroot_local_user=NO 設(shè)置指定用戶能夠chroot
(16)chroot_list_enable=YES
(17)chroot_list_file=/etc/vsftpd/chroot_list(只有/etc/vsftpd/chroot_list中的指定的用戶才能執(zhí)行 )
(18)local_root=path 無論哪個用戶都能登錄的用戶,定義登錄帳號的主目錄, 若沒有指定,則每一個用戶則進(jìn)入到個人用戶主目錄;
(19)chroot_local_user=yes/no 是否鎖定本地系統(tǒng)帳號用戶主目錄(所有);鎖定后,用戶只能訪問用戶的主目錄/home/user,不能利用cd命令向上轉(zhuǎn);只能向下;
(20)chroot_list_enable=yes/no 鎖定指定文件中用戶的主目錄(部分),文件:/chroot_list_file=path 中指定;
(21)userlist_enable=YES/NO 是否加載用戶列表文件;
(22)userlist_deny=YES 表示上面所加載的用戶是否允許拒絕登錄;
(23)userlist_file=/etc/vsftpd/user_list 列表文件
限制IP 訪問FTP:
#vi /etc/hosts.allow
vsftpd:192.168.5.128:DENY 設(shè)置該IP地址不可以訪問ftp服務(wù)
FTP 訪問時間限制:
#cp /usr/share/doc/vsftpd-1.1.3/vsftpd.xinetd /etc/xinetd.d/vsftpd
#vi /etc/xinetd.d/vsftpd/
修改 disable = no
access_time = hour:min-hour:min (添加配置訪問的時間限制(注:與vsftpd.conf中l(wèi)isten=NO相對應(yīng))
例: access_time = 8:30-11:30 17:30-21:30 表示只有這兩個時間段可以訪問ftp
ftp的配置基本上只有這些了。
?????? 默認(rèn)情況下,ftp根目錄是/var/ftp。 如果要修改這個目錄位置,可以更改/etc/passwd 文件:
[root@singledb ftp]# cat /etc/passwd | grep ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
創(chuàng)建一個用戶來訪問FTP,并指定該用戶的FTP 目錄:(可以默認(rèn))
[root@singledb u02]# useradd -d /u02/qsftp qs
[root@singledb u02]# passwd qs
Changing password for user qs.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
這里指定的是/u02/qsftp 這個目錄,要注意個目錄的權(quán)限(一定要將目錄權(quán)限改為777 chmod 777 /u02/qsftp,否則可能可以下載,但不能上傳)
更改用戶不能telnet,只能ftp:
?????? usermod -s /sbin/nologin username?? //用戶只能ftp,不能telnet
?????? usermod -s /sbin/bash username????? //用戶恢復(fù)正常
禁止用戶ssh登陸
?????? useradd username -s /bin/false??
更改用戶主目錄:
?????? usermod -d /bbb username??????????? //把用戶的主目錄定為/bbb
?
可能遇到的錯誤:
錯誤500,vsftpd: refusing to run with writable anonymous root:(修改目錄權(quán)限所致)
修正這個錯誤,應(yīng)該用下面的辦法;
[root@localhost ~]# chown root:root /var/ftp
[root@localhost ~]# chmod 755 /var/ftp
具體詳細(xì)解釋:http://blog.chinaunix.net/uid-21855486-id-3047232.html
?
轉(zhuǎn)載于:https://www.cnblogs.com/lsy-ai/p/5161070.html
總結(jié)
以上是生活随笔為你收集整理的Centos下搭建ftp服务器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 刮奖的实现;(刮开上层图层蒙版,露出底部
- 下一篇: 如何使用Navicat恢复数据库脚本