selinux導(dǎo)致ftp上傳失敗 工作中的真實案例
發(fā)布日期:2022-03-28 19:27 | 文章來源:腳本之家
這是一臺squid代理服務(wù)器(一臺式機,安裝的是redhat 5.4 64位操作系統(tǒng)),每天下午4點一臺服務(wù)器通過ftp上傳主機數(shù)據(jù)庫巡檢報告到這臺代理PC機的一個用戶家目錄下的xunjian目錄下,這臺PC再通過發(fā)送郵件的方式將巡檢報告發(fā)給組內(nèi)成員,進行巡檢
此為背景,之前的selinux設(shè)置的為Permissive,不料同事中午睡覺的時候,腳這么一碰,將這臺代理PC重啟了,重啟后,連續(xù)2天的巡檢報告都沒有通過郵件收到,趕緊解決吧
1、手動的執(zhí)行ftp上傳動作,報如下錯誤:553 Could not create file.
sshuser@station90.example.com:~/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家目錄,肯定是有讀寫權(quán)限的,因為是代理PC重啟導(dǎo)致的,突然想到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、這時候去上傳,就可以成功了,如下所示
sshuser@station90.example.com:~/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設(shè)置為Permissive
[root@squid ~]# getenforce
Enforcing
[root@squid ~]# setenforce 0
[root@squid ~]# getenforce
Permissive
5、同時在/etc/rc.local中添加這么一行,那么下次系統(tǒng)重啟后,就不會發(fā)生這樣的情況了
[root@squid ~]# which setenforce
/usr/sbin/setenforce
[root@squid ~]# cat /etc/rc.local | tail -n 1
/usr/sbin/setenforce 0
好啦,這樣就順利解決問題了,希望對一些朋友有所幫助
此為背景,之前的selinux設(shè)置的為Permissive,不料同事中午睡覺的時候,腳這么一碰,將這臺代理PC重啟了,重啟后,連續(xù)2天的巡檢報告都沒有通過郵件收到,趕緊解決吧
1、手動的執(zhí)行ftp上傳動作,報如下錯誤:553 Could not create file.
sshuser@station90.example.com:~/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家目錄,肯定是有讀寫權(quán)限的,因為是代理PC重啟導(dǎo)致的,突然想到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、這時候去上傳,就可以成功了,如下所示
sshuser@station90.example.com:~/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設(shè)置為Permissive
[root@squid ~]# getenforce
Enforcing
[root@squid ~]# setenforce 0
[root@squid ~]# getenforce
Permissive
5、同時在/etc/rc.local中添加這么一行,那么下次系統(tǒng)重啟后,就不會發(fā)生這樣的情況了
[root@squid ~]# which setenforce
/usr/sbin/setenforce
[root@squid ~]# cat /etc/rc.local | tail -n 1
/usr/sbin/setenforce 0
好啦,這樣就順利解決問題了,希望對一些朋友有所幫助
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章