I have two directories on a virtual machine. One of them is my home/user directory, the other is the /var/www/html folder which renders the public website.

Every time I upload files for my web app to my user directory, I then have to sudo cp them to the protected html folder. I was wondering whether a symlink would streamline this process by automatically putting the files in the html folder if I associated it with my user directory folder. Is this what symlinks do? Can they place files from one directory into another even if its protected?

  • This is not a programming question.
    – unwind
    Oct 26, 2011 at 13:48
  • Stackoverflow is for programming questions, which this isn't. The moderation team here will hopefully move your question to Superuser soon; please wait for the move and do not double-post it.
    – derobert
    Oct 26, 2011 at 13:49
  • Also, if this doesn't get moved soon, you can hit "flag" to flag it for moderator attention yourself, and ask for the move.
    – derobert
    Oct 26, 2011 at 13:59

3 Answers 3


Theoretically it would work yes. However replacing your home directory by a symlink to /var/www/ is a terrible idea!

  • 1
    No, actually, it wouldn't, because symlinks don't give you access to anything you wouldn't otherwise have access to.
    – derobert
    Oct 26, 2011 at 13:51
  • The problem is more that it wouldn't allow you to put anything in your home directory [bashrc etc] that's not going in /var/www. This is twice as much of a problem if he needs sudo to access the www directory, since it would mean he doesn't have a home directory that he has access to at all.
    – Random832
    Oct 26, 2011 at 13:55
  • 1
    @Random832: I agree with rahmu, it's a terrible idea. It'd take weeks to finish listing all the things it'd break, and all the security issues it would cause (were it not for everything trying to write to your new "home" returning -EPERM).
    – derobert
    Oct 26, 2011 at 13:58
  • Do you have any suggestions as to what might be a good idea that'll save time? I can manually type out the sudo cp each time, but I thought there might be a more efficient method.
    – hohner
    Oct 26, 2011 at 14:03
  • 1
    There are many things that can be done. I wish I had time to write a complete answer now, but unfortunately I'm at work now. If you get no real answer by this evening, I'll post a few ideas :)
    – rahmu
    Oct 26, 2011 at 14:05

A symlink could streamline your process; depending on a number of things. There are better methods.

Symlinks: Is /home on the same file system as /var/www? If it's not, then a symlink won't work. Symlinks don't lower the permissions of the target. If you can't write to it with your normal permissions, then making a symlink won't give you those permissions.

Upload files directly to /var/www/html: You could make a user dedicated to uploads. Grant that user permission to write to /var/www/html. You can lock down that user to only /var/www/html by chrooting ssh.

Automate your cp: Use a cron job to copy over the files for you. Have the cron run every 15 minutes. Upload your files and 15 mintues later they're live.


If you manage the virtual machine and have root access, you can reconfigure the webserver to serve files directly from a subdirectory on your home folder. In this case you should be very careful on configuring the webserver so web users can't "escape" from your web root.

I put emphasis on subdirectory because, as others pointed out, is a very bad idea to serve the entire content of your home folder on the web.

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.