linux配置ftp服務

來源:互聯網
上載者:User

Redhat9 配置FTP

2、編輯/etc/vsftpd/vsftpd.conf檔案
修改連接埠

Step1. 修改/etc/vsftpd/vsftpd.conf
`新增底下一行
listen_port=2121
Step2. 重新啟動vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
特定使用者peter、john 不得變更目錄
使用者的預設目錄為/home/username,若是我們不希望使用者在ftp 時能夠
切換到上一層目錄/home,則可參考以下步驟。
Step1. 修改/etc/vsftpd/vsftpd.conf
將底下三行
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
改為
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list //需新增此檔案
Step2. 新增一個檔案: /etc/vsftpd/chroot_list
內容增加兩行:
peter
john
Step3. 重新啟動vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
若是peter 欲切換到根目錄以外的目錄,則會出現以下警告:
ftp>; cd /home
550 Failed to change directory.
取消anonymous 登入
若是讀者的主機不希望使用者匿名登入,則可參考以下步驟。
Step1. 修改/etc/vsftpd/vsftpd.conf
將
anonymous_enable=YES
改為
anonymous_enable=NO


安排歡迎話語
若是我們希望使用者在登入時,能夠看到歡迎話語,可能包括對該主機的
說明,或是目錄的介紹,可參考以下步驟。
首先確定在/etc/vsftpd/vsftpd.conf 當中是否有底下這一行
dirmessage_enable=YES
RedHat9 的預設值是有上面這行的。
接著,在各目錄之中,新增名為.message 的檔案,再這邊假設有一個使用
者test1,且此使用者的根目錄下有個目錄名為abc,那首先我們在/home/test1
之下新增.message,內容如下:
Hello~ Welcome to the home directory
This is for test only...
接著,在/home/test1/abc 的目錄下新增.message,內容如下:
Welcome to abc's directory
This is subdir...
那麼,當使用者test1 登入時,會看到以下訊息:
230- Hello~ Welcome to the home directory
230-
230- This is for test only...
230-
若是切換到abc 的目錄,則會出現以下訊息:
250- Welcome to abc's directory
250-
250- This is subdir ...


對於每一個聯機,以獨立的process 來運作
一般啟動vsftp 時,我們只會看到一個名為vsftpd 的process 在運作,但若
是讀者希望每一個聯機,都能以獨立的process 來呈現,則可執行以下步驟。
Step1. 修改/etc/vsftpd/vsftpd.conf
新增底下一行
setproctitle_enable=YES
Step2. 重新啟動vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
使用ps -ef 的指令,可以看告不同使用者聯機的情形,如所示:
[root@home vsftpd]# ps -ef|grep ftp
root 2090 1 0 16:41 pts/0 00:00:00 vsftpd: LISTENER
nobody 2120 2090 0 17:18 ? 00:00:00 vsftpd: 192.168.10.244:
connected
test1 2122 2120 0 17:18 ? 00:00:00 vsftpd: 192.168.10.244/test1:
IDLE
nobody 2124 2090 0 17:19 ? 00:00:00 vsftpd: 192.168.10.244:
connected
test2 2126 2124 0 17:19 ? 00:00:00 vsftpd: 192.168.10.244/test2:
IDLE
root 2129 1343 0 17:20 pts/0 00:00:00 grep ftp
[root@home vsftpd]#
限制傳輸檔案的速度:原生使用者最高速度為200KBytes/s,匿名登入
者所能使用的最高速度為50KBytes/s
Step1. 修改/etc/vsftpd/vsftpd.conf
新增底下兩行
anon_max_rate=50000
local_max_rate=200000
Step2. 重新啟動vsftpd
[root@home vsftpd]# /sbin/service vsftpd restart
Shutting down vsftpd: OK ]
Starting vsftpd for vsftpd: OK ]
在這邊速度的單位為Bytes/s,其中anon_max_rate 所限制的是匿名登入的
使用者,而local_max_rate 所限制的是原生使用者。VSFTPD 對於速度的限
制,範圍大概在80%到120%之間,也就是我們限制最高速度為100KBytes/s,
但實際的速度可能在80KBytes/s 到120KBytes/s 之間,當然,若是頻寬不足
時,數值會低於此限制。
建置一個防火牆下的ftp server,使用PORT FTP mode:預設的ftp
port:21 以及ftp data port:20
啟動VSFTPD 之後執行以下兩行指令,只允許port 21 以及port 20 開放,
其它關閉。
iptables -A INPUT -p tcp -m multiport --dport 21,20 -j ACCEPT
iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
將vsftpd 併入XINETD
若是讀者希望將vsftpd 併入XINETD 之中,也就是7.x 版的預設設定,那
麼讀者可以執行以下步驟。
Step1. 修改/etc/vsftpd/vsftpd.conf
將
listen=YES
改為
listen=NO
Step2. 新增一個檔案: /etc/xinetd.d/vsftpd
內容如下:
service vsftpd
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
port = 21
log_on_success += PID HOST DURATION
log_on_failure += HOST
}
Step3. 重新啟動xinetd
[root@home vsftpd]# /sbin/service xinetd restart
Stopping xinetd: OK ]
Starting xinetd: OK ]
3、常見錯誤
ftp客戶串連常見故障現象
現象0:
> ftp: connect :串連被拒絕
原因: 服務沒啟動
解決: # chkconfig vsftpd on<Enter>

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

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

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

現象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.
原因: 使用者主目錄沒有許可權或沒有主目錄
解決: 正確設定使用者主目錄許可權

553 Could not create file.

要解決這個問題只要:
1. setsebool -P ftpd_disable_trans 1
2. service vsftpd restart

1、設定selinux
vi /etc/sysconfig/selinux
將其中的SELINUX=enforcing改為SELINUX=disabled
2、設定如下
setsebool -P allow_ftpd_full_access 1

chmod -R 765 /etc/home

1、 查看 SELinux 的狀態: sestatus -b | grep ftp

2、 在出現的結果中可以看到

ftp_home_dir off

tftpd_disable_trans off

之類。我們現在只要把其中之一設定為on就可以啦。

3、 setsebool -P ftpd_disable_trans on 或者 setsebool -P ftp_home_dir on

4、 重啟vsftpd: service vsftpd restart

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.