【问题标题】:rsync pop_dir "/home/user_x" failed: permission denied, why?rsync pop_dir "/home/user_x" 失败:权限被拒绝,为什么?
【发布时间】:2012-09-04 03:55:06
【问题描述】:

我目前正在编写一个 bash shell 脚本来将我们的 svn 存储库的最新版本传输到网络服务器。这是通过使用 svn export 到服务器 A 并将其与网络服务器同步来完成的,创建了一个特殊用户(称为 sync_user),在每一端(服务器 A 和网络服务器)都有足够的权限来执行这些更新。 该脚本使用“su sync_user”来执行 svn export 和 rsync 作为 sync_user :

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
}

这个想法是每个有权更新/同步网络服务器的人都知道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]

经过一番谷歌搜索后,我发现我遇到的问题是由 rsync 引起的,因为它要求 sync_user 对脚本调用者的主目录具有完全访问权限。 那是对的吗?如果是这样,为什么?是否有解决方法?

注意:脚本中根本不使用用户的主目录。仅使用服务器 A 上的 /tmp/ 和网络服务器上的 /var/www/vhosts/。

【问题讨论】:

    标签: svn unix permissions rsync


    【解决方案1】:

    好吧,经过一番折腾,我们设法解决了这个问题。 这完全是用户权限问题,与 rsync 本身无关。

    当运行“su sync_user ...”时,活动终端指向调用脚本的用户(user_x)的主目录。由于 sync_user 甚至不允许在该文件夹中,因此不允许运行某些命令(如 rsync 或 ls),这会导致错误消息。

    为了修复它,我在运行“sync_section 脚本”之前添加了一个“cd ~”:

    su sync_user -c "cd ~; sync_section $source $tmp $dest"
    

    脚本现在就像一个魅力:)

    我希望这对未来的人有所帮助!

    【讨论】:

      猜你喜欢
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 2015-03-25
      • 2014-11-04
      • 2012-03-27
      相关资源
      最近更新 更多