所以这是我第一次bash脚本尝试,并且我正在尝试将OS X上的项目文件夹rsync同步到运行ubuntu 14.04的开发服务器上。 当我尝试将rsync作为用户的“开发人员”时,我在目标服务器上遇到一些权限错误,但是当我以用户“ubuntu”的身份执行操作时,我也得到了这些错误。 由于EC2上的默认云服务器设置,我无法尝试作为root用户。
这是我的shell脚本。
#!/bin/bash rsync -r —l -t -z -v -e "ssh [email protected]" --exclude “/Applications/MAMP/htdocs/finalall/nbproject/” --delete /Applications/MAMP/htdocs/finalall/ :/var/www/html afplay "/System/Library/Sounds/Morse.aiff"
这是我的错误:
building file list ... rsync: link_stat "/Users/xxxxx/?\#200\#224l" failed: No such file or directory (2) done IO error encountered -- skipping file deletion rsync: failed to set times on "/var/www/html/.": Operation not permitted (1) ./ rsync: recv_generator: mkdir "/var/www/html/nbproject" failed: Permission denied (13) *** Skipping any contents from this failed directory *** testerterst.php nbproject/ rsync: mkstemp "/var/www/html/.testerterst.php.TISozV" failed: Permission denied (13) sent 493 bytes received 54 bytes 1094.00 bytes/sec total size is 971 speedup is 1.78 rsync error: some files could not be transferred (code 23) at /SourceCache/rsync/rsync-42/rsync/main.c(992) [sender=2.6.9]
这里是(某些)sudo cat / etc / group的输出
ssh:x:108: landscape:x:109: admin:x:110: ubuntu:x:1000: ssl-cert:x:111: developer:x:1001:
真诚的感谢您的帮助。 非常感谢,非常感谢。
输出到ls -lZd / /var/ /var/www/ /var/www/html/是:
drwxr-xr-x 22 root root ? 4096 Aug 5 19:53 / drwxr-xr-x 13 root root ? 4096 Aug 5 20:00 /var/ drwxr-xr-x 3 root root ? 4096 Aug 5 20:00 /var/www/ drwxr-xr-x 2 root root ? 4096 Aug 5 20:17 /var/www/html/
您没有对目标服务器上的/ var / www / html的写入权限,因为该文件夹属于root,而其他人只具有读取/执行权限。
解决这个问题的最好方法是将该目录的所有者更改为您的ssh用户:
chown -R developer. /var/www/html
这将/ var / www / html及其所有子目录的所有者更改为开发人员用户及其默认组。
如果还有其他用户需要对同一个目录进行写入访问,我build议将它们放在一个组中,然后更改文件夹的权限以允许同一组中的每个人都可以写入权限。 以下向您展示如何做到这一点。
groupadd devs #Adds a group called devs useradd -G devs ubuntu #Adds the devs group to the ubuntu user chown -R .devs /var/www/html #Changes only the group of the directory to devs chmod -R 775 /var/www/html #Allows the owner and group of the directory full access, everybody else only has read/execute
而不是改变目录的所有权,你可以在两个阶段做到这一点:
假设服务器是在你的本地〜/ .ssh / config中定义的:
# rsync sourceDir to the home dir of yourname on theserver. # ':' after 'theserver' invokes ssh as transport. $ rsync -<options> sourceDir yourname@theserver:. # You will be prompted for your theserver password for the cp. # Change the cp source and dest to suit your needs. $ ssh -t theserver "sudo cp -r sourceDir /var/www/. && rm -rf sourceDir"