我目前正在編寫一個bash shell腳本來將svn版本庫的最新版本傳輸到一個web服務器上。這是通過使用svn導出到服務器A並使用web服務器rsync來完成的,使用足夠的權限(服務器A和Web服務器)創建了一個特殊用戶(稱爲sync_user)來執行這些更新。 該腳本使用「蘇sync_user」執行SVN出口和rsync作爲sync_user:rsync pop_dir「/ home/user_x」失敗:權限被拒絕,爲什麼?
export -f sync_section
su sync_user -c "sync_section $source $tmp $dest"
其中sync_section是在腳本的功能:
# critical section which performs the actual website update (export & sync)
# takes 3 parameters: source, tmp, dest
function sync_section {
source=$1
tmp=$2
tmp_old=$tmp"_old"
dest=$3
#enter critical section
set -e
# export to temp folder on server A
svn export -q --force $source $tmp --native-eol LF
# rsync with remote live website folder.
rsync -avzhiO $tmp $dest
# clean up
rm -rf $tmp_old
mv -f $tmp $tmp_old
# exit critical section
set +e
}
的想法是,大家誰有權更新/同步Web服務器知道sync_user的密碼,因此可以進入「su sync_user」部分。
在理論上聽起來不錯,但Rsync是不滿意這個設置,使我有以下錯誤信息:(user_x是調用腳本的用戶)
#### rsync output:
building file list ... rsync: pop_dir "/home/user_x" failed: Permission denied (13)
rsync error: errors selecting input/output files, dirs (code 3) at flist.c(1314) [sender=2.6.8]
一些googeling後,我發現,這個問題我我是由rsync引起的,因爲它要求sync_user對腳本調用方的主目錄具有完全訪問權限。 這是正確的嗎?如果是的話,爲什麼?有沒有解決它的辦法?
注意:用戶的主目錄在腳本中完全沒有使用。只使用服務器A上的/ tmp /和網絡服務器上的/ var/www/vhosts /。