歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> selinux導致ftp上傳失敗 工作中的真實案例

selinux導致ftp上傳失敗 工作中的真實案例

日期:2017/3/1 18:04:20   编辑:Linux技術
這是一台squid代理服務器(一台式機,安裝的是redhat 5.4 64位操作系統),每天下午4點一台服務器通過ftp上傳主機數據庫巡檢報告到這台代理PC機的一個用戶家目錄下的xunjian目錄下,這台PC再通過發送郵件的方式將巡檢報告發給組內成員,進行巡檢
此為背景,之前的selinux設置的為Permissive,不料同事中午睡覺的時候,腳這麼一碰,將這台代理PC重啟了,重啟後,連續2天的巡檢報告都沒有通過郵件收到,趕緊解決吧

1、手動的執行ftp上傳動作,報如下錯誤:553 Could not create file.

[email protected]:~/xunjian/0108> ftp 192.168.1.123
Connected to 192.168.1.123.
220 (vsFTPd 2.0.5)
Name (192.168.1.123:oracle): oracle
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>binary
200 Switching to Binary mode.
ftp> put xunjian_0108.zip
local: xunjian_0108.zip remote: xunjian_0108.zip
229 Entering Extended Passive Mode (|||10717|)
553 Could not create file.

2、代理PC的oracle家目錄,肯定是有讀寫權限的,因為是代理PC重啟導致的,突然想到selinux若開啟的話,是不允許用戶的家目錄進行ftp的,需要將ftp_home_dir這個sebool打開,如下所示:

[root@squid ~]# getenforce
Enforcing
[root@squid ~]# getsebool -a | grep ftp_home_dir
ftp_home_dir --> off
[root@squid ~]# setsebool ftp_home_dir on

3、這時候去上傳,就可以成功了,如下所示

[email protected]:~/xunjian/0108> ftp 192.168.1.123
Connected to 192.168.1.123.
220 (vsFTPd 2.0.5)
Name (192.168.1.123:oracle): oracle
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> bi
200 Switching to Binary mode.
ftp> put xunjian_0108.zip
local: xunjian_0108.zip remote: xunjian_0108.zip
229 Entering Extended Passive Mode (|||19974|)
150 Ok to send data.
100% |***********************************************************************| 577 KB 2.31 MB/s 00:00 ETA
226 File receive OK.
591290 bytes sent in 00:00 (2.18 MB/s)

4、另外一種方式,就是將selinux設置為Permissive

[root@squid ~]# getenforce
Enforcing
[root@squid ~]# setenforce 0
[root@squid ~]# getenforce
Permissive

5、同時在/etc/rc.local中添加這麼一行,那麼下次系統重啟後,就不會發生這樣的情況了

[root@squid ~]# which setenforce
/usr/sbin/setenforce
[root@squid ~]# cat /etc/rc.local | tail -n 1
/usr/sbin/setenforce 0

好啦,這樣就順利解決問題了,希望對一些朋友有所幫助
Copyright © Linux教程網 All Rights Reserved