1

I have a web server and it using by few developers. Web-site is under website user. Other users are like user1, user2 etc. I have given sudo access to user1, user2.. to access website.

The issue I'm having now is users fails to copy scripts from website because some scripts not allows to read directly by the users. And even if I try to cp using sudo it fails because website don't have write permission to users directories.

I do not want to change the file permission due to some security seasons. i saw somewhere that I can do this using tar, but couldn't figure out.

Can someone help...

Thanks!

  • Do you have root access? – Hydranix Aug 24 '16 at 10:47
  • When you do sudo cp, you are not running as website but root, so, permissions shouldn't be an issue. Are they all on the same filesystem? Is the website and the user's ssh sessions running on different containers? Can you post a terminal transcript showing how it fails? – rbanffy Aug 24 '16 at 12:57
  • Hydranix Yes I'm root. rbanffy All this system is on debian server. We actually allow users to do sudo -u website cp. So they never run command as root. – Yasiru G Aug 25 '16 at 3:52
1

You can do (as user1) something like

sudo -u website cat ~website/somefile > ~user1/somefile

Note that ~user1/somefile will be firstly created by user running the shell (user1), and the cat will be executed as website

You can use tar(1) with same trick, for multiple files:

sudo -u website tar cf - ~website/foo ~website/bar | tar xf -

Run as user1 in his directory, that will "create" tar archive on stdout as website, and the another tar (without sudo, so running as same user as the one running the shell, that is user1) would unpack that virtual tar file to current directory (to which user1 can write).

UPDATE Note that tar will create subdirectories leading to a file, you can reduce that behaviour by specifying -C so tar will entet specified directory before starting:

sudo -u website tar -C ~website -cf - foo bar | tar xf -

This way, foo and bar will be created in current directory without leading subdirectories (but if you added blah/baz, it would create blah as subdir in which baz resides)

  • Thanks a lot Matija. You save my day. cat command solution is good to cp single file. I think tar is good for multiple files. However I tried your tar command for a particular file like below, it result was copied entire /home dir set. Command : sudo -u website tar cf - /home/website/DB.php | tar xf - – Yasiru G Aug 25 '16 at 4:22
  • @YasiruG no, I do not think it did copy whole /home. But it did create all the leading subdirectories for DB.php. See update to the answer for how to avoid that. – Matija Nalis Aug 25 '16 at 10:30
  • yup, you are correct. Thanks for that. I think you need to do small correction. command should be sudo -u website tar cf -C ~website foo bar | tar xf - – Yasiru G Aug 29 '16 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.