I recently installed Ubuntu server on my server to try out the linux as a new user. I followed a tutorial on how to set up the web server which said I need to chmod 777
the web server dir so that it can be written into.
Anyway, I created a new account for one dude to allow him to see some files on the server which I placed in his home dir:
adduser francis
After creating the account I checked what access he has with
groups francis
It said "francis : francis", so not a problem I thought, the ubuntu hasn't included him in any groups by default, which makes sense, it created him with no extra permissions security-wise, so everything is fine and dandy. A week later, in absolute and utter horror, I found out that even though he couldn't do things like SUDO or mess around in system directories, he had full access to almost everything else on the server. For example he had full read/write access to my web server files at /var/www (and thus passwords stored in php configs files etc) even though that directory is NOT in his home directory and I never added him into any groups which could access that directory, nor I granted him any special access to anything ever after doing the adduser.
Anyway, what is going on here? How do I kill his access to anything important? He should not be able to access stuff like /media or /var/www. I thought that new users were by default prevented from doing anything dangerous or snooping where they shouldn't be.
So the sum it up, I only need to allow him access to directories which I manually specify + to directories which he needs to function properly (his home dir, vim, nano etc..)
Thank you
This is as designed. And worse. chmod 777 means... "I'd like the owner, anyone in his group, and anyone at all to have read, write and execute permissions"
Which is pretty terrible.
And for a web server, 777 is not optimal. 755 (Owner has full permissions group and others have read + execute) is a common default but from what you've said you want at least read-write, or read-write execute for the owner (the web server user), and maybe the group, and no permissions for the user. There's a more complete questions on what appropriate permissions levels are on serverfault but consider something like 640 or 740.
that said, you could also put the user in his own little world - setting up chroot to keep the user in his own space in the system. There's guides floating around for doing this - for example oli's excellent answer here which may be an option depending on your needs.
Essentially, it breaks down like this:
So, read permissions only would be 4, read and write would be 6, read and execute would be 5, and all (read, write, execute) is 7. This is how you compute a permission octet value for an owner, owner's group, or everyone.
When applying those permissions with
chmod
to a file or directory location, the numbers computed above are applied like this, with an octet each for owner, group, and everyone:So if I wanted to give myself and my group read, write and execute permissions to a folder that I owned, but I didn't want everyone to even be able to read it, I'd use:
For more information, check the man page for chmod:
As others have mentioned you should not have permissions set to 777
Here's a helpful reference sheet that i use.
In order to share files with a person you gave a login to, you don't need to do anything in particular. On a default Debian installation, users have access to each others' home directories.
For instance,
Permissions on my home directory are read (r) and access (x) for any user on my system. Only I additionally have write (w) access.
Also, the default
umask
on Ubuntu is such that files and directories that users create are world readable by default. You could set theumask
to077
if you didn't want that.What this means that in a default setup, if user
you
wants to share document~/README.txt
with me, then there's nothingyou
needs to do. I can simply view it:I can't edit or remove the file, but I can copy it to a location where I have write permission. Then I own the copy:
There are good reasons why most of the system is world readable by default, as I've explained in another answer on AskUbuntu. However, on a shared system it may make sense to make home directories inaccessible to non-owners:
... as many users apparently aren't aware of the default - QED ;-). It would be wiser though to make users aware that file permissions don't protect secrets.
In Ubuntu, any user has superuser privilege who are added in the group 'sudo', Please check it to ensure that no other user are added in this group.
To secure your files and directory from other users you can set permission as suggested by Mr. Journeyman Geek in above answer.
You can also use special permissions to secure your files and directories from others.