Redhat/CentOS中ftp安裝及使用詳解

來源:互聯網
上載者:User

FTP伺服器的安裝與配置(Ubuntu)
1.查詢是否安裝vsftpd: rpm -qa |grep vsftpd

(rpm的安裝:apt-get install rpm)

或者查詢當前ftp進程:ps -ef|grep vsftpd

2.安裝vsftpd伺服器: rpm -ivh vsftpd-*.rpm 或從互連網尋找對應資源直接安裝vsftpd:apt-get install vsftpd

++++++++++++++++++++++++++++

可以通過配置yum進行線上安裝包.

[root@szmspv1 yum.repos.d]# pwd
/etc/yum.repos.d
[root@szmspv1 yum.repos.d]# more rhel54.repo
[Server]
name=Red Hat Enterprise Linux Server
baseurl=ftp://172.26.0.11/Server64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

+++++++++++++++++++++++++++++++++++++++++++++++++

3.測試

root@localhost root:~# ftp localhost
Connected to localhost.
220 (vsFTPd 2.2.2)
Name (localhost:root): root
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>bye
221 Goodbye.

4.vsftpd伺服器的啟動、停止、重啟、狀態
service vsftpd start 或./etc/init.d/vsftpd start
service vsftpd stop 或./etc/init.d/vsftpd stop
service vsftpd restart 或./etc/init.d/vsftpd restart
service vsftpd status 或./etc/init.d/vsftpd status

5.vsftpd的三個主設定檔
/etc/vsftpd.conf //伺服器的主設定檔
/etc/ftpd.ftpusers //此檔案內的使用者都不能訪問vsftpd伺服器
/etc/vsftpd.user_list //可能會被拒絕訪問服務喊叫或允許訪問


6.vsftpd.conf的配置參數
anonymous_enable=YES //啟用匿名使用者
local_enable=YES //允許本機使用者訪問vsftpd伺服器
write_enable=YES //允許上傳
download_enable=YES //允許下載
anon_upload_enable=YES //允許匿名使用者上傳
anon_mkdir_write_enable=YES //允許匿名使用者建立目錄和上傳
anon_other_write_enable=NO //不允許匿名使用者刪除和改名
local_max_rate=20000 //本機使用者的最大傳輸速率,單位是位元組/秒
anon_max_rate=5000 //匿名使用者的最大傳輸速率,單位是位元組/秒
local_umask=022 //去掉寫的許可權
file_open_mode=0666 //上傳檔案的許可權
xferlog_enable=YES //維護記錄檔,詳細記錄上傳和下載操作
xferlog_std_format=YES //傳輸記錄檔將以標準的xferlog格式書寫,記錄檔默

認為/var/log/xferlog
hide_ids=YES //隱藏檔案夾和目錄屬主
port_enable=YES //允許使用主動傳輸模式
pasv_min_port=(1024<port<65535) //指定PASV模式可以使用的最小連接埠
pasv_max_port=(1024<port<65535) //指定PASV模式可以使用的最大連接埠
connect_from_port_20=YES //定義FTP傳輸資料的連接埠,預設是20
ascii_download_enable=NO //設定不可使用ASCII模式下載
listen=YES //讓FTP工作在獨立模式下

pam_service_name=vsftpd //使用者設定檔認證
userlist_enable=YES
tcp_wrappers=YES //將使用wrappers作為主機存取控制方式
idle_session_timeout=600 //表明空閑時間為600秒
data_connection_timeout=120 //表明資料連線逾時時間為120秒
chroot_local_user=YES //使用者登入後不能訪問自己目錄以外的檔案或目錄
listen_port=4444 //修改FTP伺服器的連接埠號碼

7.設定FTP伺服器在3、5層級上自動運行

chkconfig --level 3 5 vsftpd on

8.ftp客戶串連常見故障現象
現象0:
> ftp: connect :串連被拒絕
原因: 服務沒啟動
解決: # chkconfig vsftpd on

現象1:
500 OOPS: cannot open user list file
原因: 不存在檔案“/etc/vsftpd.user_list”或檔案中不存在該帳戶
解決: # echo username >> /etc/vsftpd.user_list

現象2:
530 Permission denied.
Login failed.
原因: “/etc/vsftpd.user_list”檔案中不存在當前登陸使用者
解決: # echo username >> /etc/vsftpd.user_list

現象3:
500 OOPS: cannot open chroot() user list file
Login failed.
原因: 不存在檔案“/etc/vsftpd.chroot_list”
解決: # echo username >> /etc/vsftpd.chroot_list

現象4:
500 OOPS: missing value in config file
Connection closed by remote host.
原因: “=”等號前值有問題,或只有一個空格
解決: 修正相應的值即可,可能過 diff 來比較尋找

現象5:
500 OOPS: bad bool value in config file
Connection closed by remote host.
原因: “=”等號後值有問題
解決: 將“=”等號後值確認修改

現象6:
500 OOPS: unrecognised variable in config file
Connection closed by remote host.
原因: 參數前有空格
解決: 將參數前空格刪除

現象7、
確認存在“local_enable=YES”,但本機使用者無法登陸
原因: 驗證參數被誤刪除
解決: 添加“pam_service_name=vsftpd”

現象8、
500 OOPS: chdir
500 OOPS: child died
Connection closed by remote host.
原因: 使用者主目錄沒有許可權或沒有主目錄
解決: 正確設定使用者主目錄許可權

9.vsftpd虛擬使用者帳號的設定步驟
(1).建立虛擬使用者口令庫檔案
vi /pub/vu_list.txt
wang5
123
zhao6
456
(2).產生vsftpd的認證檔案
db_load -T -t hash -f /pub/vu_list.txt /etc/vsftpd/vu_list.db
chmod 600 /etc/vsftpd/vu_list.db
(3).建立虛擬使用者所需的PAM設定檔
vi /etc/pam.d/vsftpd.vu
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vu_list
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vu_list
(4).建立虛擬使用者所要訪問的目錄並設定相應許可權
useradd ftpuser
(5).設定vsftpd.conf設定檔
guest_username=ftpuser
pam_service_name=vsftpd.vu
(6).重啟vsftpd伺服器
service vsftpd restart

10.對虛擬使用者佈建不同許可權
(1).設定vsftpd.conf檔案
user_config_dir=/etc/vsftpd_vu
(2).建立目錄
mkdir /etc/vsftpd_vu
(3).進入目錄進行編輯
cd /etc/vsftpd_vu
vi wang5
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES

vi zhao6
anon_world_readable_only=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
10.配置基於IP的虛擬ftp伺服器
(1).綁定其它IP
ifconfig eth0:0 192.168.1.71
(2).建立虛擬FTP伺服器目錄
mkdir -p /var/ftp2/pub1
(3).建立虛擬伺服器的匿名使用者所映射的本機使用者
ftp2
useradd -d /var/ftp2 -M ftp2
(4).修改原獨立運行伺服器的設定檔
listen_address=192.168.1.70
(5).複製產生虛擬伺服器的主設定檔
cp /etc/vsftpd.conf /etc/vsftpd/vsftpd2.conf
(6).設定虛擬伺服器的IP並使虛擬伺服器的匿名使用者映射到本機使用者ftp2
vi /etc/vsftpd/vsftpd2.conf
pam_service_name=vsftpd
listen_address=192.168.1.71
ftp_username=ftp2
(7).重啟服務生效:service vsftpd restart

DOS下使用ftp命令:

1. 切換到指定目錄下
2. 串連目標ftp伺服器:ftp 10.137.97.29
3. 輸入帳號、密碼
4. 切換傳輸方式,二進位傳輸使用bin命令
5. 上傳檔案:put test_setup.zip

下載檔案:get **.zip
6. 退出ftp:bye

7. cd 切換目錄

8. del 刪除檔案

9. dir 查看遠程主機目前的目錄

10. ascii 使用ascii方式傳輸檔案

11. mput、mget: 將多個檔案上傳、下載

12. mkdir 在遠程主機中建立目錄

13. pwd 顯示遠程主機的當前工作目錄路徑

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.