我的環境:
A:RedHatEnterPRise6.2 ip:192.168.16.12 此機作測試端
B:RedHatEnterprise6.2 IP:192.168.16.13 此機做FTP服務端
B機上搭建FTP服務器:
下載并安裝vsftpd-2.2.2-6.el6_0.1.i686
[root@redhat6-3~]#rpm-ivhvsftpd-2.2.2-6.el6_0.1.i686.rpm
創建測試用戶:
[root@redhat6-3~]#useraddtuantuan-d/var/ftp/ttftp-s/sbin/nologin
[root@redhat6-3~]#useraddtuantuan-s/sbin/nologin
[root@redhat6-3~]#passwdtuantuan
NewpassWord:
Retypenewpassword:
passwd:allauthenticationtokensupdatedsuccessfully.
查看一下新創建的用戶配置
[root@redhat6-3~]#tail-1/etc/passwd
tuantuan:x:504:504::/var/ftp/ttftp:/sbin/nologin
修改配置文件:
首先來看vsftp的配置文件,常使用的配置如下:
[root@redhat6-3~]#grep-v"#"/etc/vsftpd/vsftpd.conf
anonymous_enable=YES //是否啟動匿名用戶登入
local_enable=YES //是否允許本地用戶登入
write_enable=YES //是否允許用戶寫入
local_umask=022 //用戶目錄下創建文件默認權限,此處默認權限是777-022=755
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 //是否啟用用/etc/hosts.allow或/etc/hosts.deny文件生效
以上是默認的ftp參數,我們還需添加以下參數來完成配置:
chroot_local_user=YES //是否禁止本地用戶離開自己的主目錄
xferlog_file=/var/log/vsftpd.log //設置ftp的日志路徑
idle_session_timeout=600 //設置回話等待時間
data_connection_timeout=120 //設置數據等待時間
ftpd_banner=WelcometoconnectmyFTP! //設置成功登入提示
完成配置后重啟一下ftp,查看進程并在A機上登入測試:
[root@redhat6-3~]#netstat-antp|grep21
tcp000.0.0.0:1110.0.0.0:*LISTEN1221/rpcbind
tcp000.0.0.0:210.0.0.0:*LISTEN1926/vsftpd
tcp00:::111:::*LISTEN1221/rpcbind
客戶端需安裝ftp-0.17-51.1.el6.i686來支持ftp命令
在A上:
[root@redhat6-2Packages]#rpm-ivhftp-0.17-51.1.el6.i686.rpm
[root@redhat6-2Packages]#ftp192.168.16.13
Connectedto192.168.16.13(192.168.16.13).
220WelcometoconnectmyFTP!
Name(192.168.16.13:root):tuantuan
331Pleasespecifythepassword.
Password:
230Loginsuccessful.
RemotesystemtypeisUNIX.
Usingbinarymodetotransferfiles.
help命令查看ftp的命令
ftp>help
Commandsmaybeabbreviated.Commandsare:
!debugmdirsendportsite
$dir mgetputsize
accountdisconnect mkdirpwdstatus
appendexitmlsquitstruct
asciiformmodequotesystem
bellgetmodtimerecvsunique
binary glob mputregettenex
bye hashnewerrstatustick
case help nmaprhelptrace
cd idle nlistrenametype
cdupimagentransresetuser
chmodlcdopenrestartumask
close lspromptrmdirverbose
cr macdefpassiverunique?
deletemdeleteproxysend
創建一個目錄,并想改目錄內傳送一個文件:
ftp>cdtest
250Directorysuccessfullychanged.
ftp>!ls
anaconda-ks.cfgLAMPMySQL-5.5.25.tar.gz
install.logmysql-5.1.66-linux-i686-glibc23.tar.gz
ftp>putmysql-5.5.25.tar.gz
local:mysql-5.5.25.tar.gzremote:mysql-5.5.25.tar.gz
227EnteringPassiveMode(192,168,16,13,216,59).
150Oktosenddata.
226Transfercomplete.
24639871bytessentin1.1secs(22359.01Kbytes/sec)
切換到服務端查看該目錄下的文件:
[root@redhat6-3~]#cd/var/ftp/ttftp/test/
[root@redhat6-3test]#ls
mysql-5.5.25.tar.gz
也可以在windows下登入該ftp,更加方便:
打開我的電腦輸入ftp://[email protected]
配置超級守護進程啟動vsftp
需要裝xinetd服務管理工具:
[root@redhat6-3~]#rpm-ivhxinetd-2.3.14-33.el6.i686.rpm
[root@redhat6-3~]#cp-rf/usr/share/doc/vsftpd-2.2.2/vsftpd.xinetd/etc/xinetd.d/vsftpd
[root@redhat6-3~]#vi/etc/xinetd.d/vsftpd
#default:off
#description:ThevsftpdFTPserverservesFTPconnections.Ituses/
#normal,unencryptedusernamesandpasswordsforauthentication.
serviceftp
{
socket_type=stream
wait=no
user=root
server=/usr/sbin/vsftpd
server_args=/etc/vsftpd/vsftpd.conf
nice=10
disable=no//將yes改為no即可
flags=IPv4
}
修改配置文件
#listen=YES
將listen注釋掉即可
建議write_enable=YES改為NO
將vsftpd的服務停掉:
[[email protected]]#servicevsftpdstop
Shuttingdownvsftpd:[OK]
重啟xinted服務:
[root@redhat6-3etc]#servicexinetdrestart
Stoppingxinetd:[OK]
Startingxinetd: [OK]
查看端口是否存在:
[root@redhat6-3etc]#netstat-antp|grep21
tcp000.0.0.0:1110.0.0.0:*LISTEN1221/rpcbind
tcp000.0.0.0:210.0.0.0:*LISTEN4369/xinetd
tcp00:::111:::*LISTEN1221/rpcbind
因為啟用超級進程來管理vsftp,所以這時候啟動vsftpd會報如下錯誤:
[root@redhat6-3etc]#servicevsftpdstart
Startingvsftpdforvsftpd:500OOPS:vsftpd:notconfiguredforstandalone,mustbestartedfrominetd
若不想啟用超級進程管理,將配置文件中的listen=YES注釋取消即可
測試端登入測試:
[root@redhat6-2~]#ftp192.168.16.13
Connectedto192.168.16.13(192.168.16.13).
220WelcometoconnectmyFTP!
Name(192.168.16.13:root):tuantuan
331Pleasespecifythepassword.
Password:
230Loginsuccessful.
RemotesystemtypeisUNIX.
Usingbinarymodetotransferfiles.
ftp>bye
221Goodbye.
windows登入測試:
同上次方法一樣打開我的電腦或cmd(調用瀏覽器)輸入:tp://[email protected]/
輸入用戶名和密碼后登入進行操作即可
簡單的ftp服務器配置完成!
新聞熱點
疑難解答