Rsync pop_dir "/ home / user_x" failed: permission is allowed, why?

I am currently writing a bash shell script to port the latest version of our svn repository to a web server. This is done by exporting svn to server A and rsync'ing it with a web server. To perform these updates, a special user (called sync_user) was created with sufficient permissions for each side (server A and web server). The script uses "su sync_user" to export svn and rsync as sync_user:

export -f sync_section su sync_user -c "sync_section $source $tmp $dest" 

where sync_section is a function in the script:

 # 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 } 

The idea is that everyone who has permission to update / synchronize the web server knows the sync_user password, so they can enter the "su sync_user" section.

Sounds good in theory, but rsync is not happy with this setting and gives me the following error message: (user_x is the user calling the script)

 #### 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] 

After some googeling, I found that the problem I am facing is caused by rsync, as it requires sync_user to have full permissions in the caller’s home directory script. It's right? and if so, why? and is there any work for this?

Note. The user's home directory is not used at all in the script. Only / tmp / is used on server A and / var / www / vhosts / on the web server.

+6
source share
1 answer

Good, therefore, after we moved forward and backward, we were able to solve the problem. This is completely a user rights issue and has nothing to do with rsync per se.

When running 'su sync_user ...', the active terminal pointed to the user's home directory, which calls script (user_x). Since sync_user is not even allowed to be in this folder, it is therefore not allowed to run some commands (for example, rsync, or ls), which causes an error message.

To fix this, I added 'cd ~' before running the 'sync_section script:

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

And the script now works like a charm :)

I hope this helps someone in the future!

+2
source

Source: https://habr.com/ru/post/925102/


All Articles