1

I am trying to give the user tomcat8 write and read access to a specific folder on my server. I tried this command:

sudo chmod -R tomcat8 /usr/local/javaagent/appagent/ver2/logs/Tomcat1

However it gives me

chmod: invalid mode: `tomcat8'

Why doesn't this work? Isn't this the standard chmod?

  • Won't that screw up the permissions for other users if I change the owner of that folder? @edwinksl – Mike Korza Jul 31 '16 at 10:52
  • 1
    @MikeKorza chmod needs the permissions, like 777 or 755, and such. – dadexix86 Jul 31 '16 at 10:55
  • It will not change permissions, it will change the owner. If you use chmon, you need to specify permissions you want to give, not a user. Read man chmod. – Pilot6 Jul 31 '16 at 10:55
  • @MikeKorza Oops, I misread what you intended to do. As dadexix86 and Pilot6 said, chmod is correct but you need to specify permissions correctly. See help.ubuntu.com/community/FilePermissions for some examples. – edwinksl Jul 31 '16 at 10:57
  • chmod doesn't provide the granularity to specify permissions for an individual user - only for the file's owner (o), group (g), or "other" (o). Probably the way to achieve what you want is to give the file's group rw permission, and make user tomcat8 a member of the group. Beyond that there are ACLs. – steeldriver Jul 31 '16 at 11:03
5

You can't do this only with chmod. You can, however, make a new group and change the group ownership of the directory, add the user to that group and then give the group the permissions you want on the directory, so you can give privilege to only that group.

To create a group tomcat and add the user tomcat8 to it:

sudo groupadd tomcat && sudo adduser tomcat8 tomcat

You may also want to add yourself (and any other users who need read write access here) to the group with sudo adduser [username] tomcat

Now change the group ownership of the directory:

sudo chown :tomcat /usr/local/javaagent/appagent/ver2/logs/Tomcat1

Don't forget the colon - this is to change only the group ownership.

Now change permissions, for example, you add read and write permissions to the group like this:

sudo chmod g+rw /usr/local/javaagent/appagent/ver2/logs/Tomcat1

From your question I'm not sure what you want the other settings to be. I recommend reading man chmod and this guide to permissions to understand better what you are doing.

Directories need execute permissions to be entered and searchable, so you most likely want octal 775 (so all users can read and search but only group can write) or 770 (so only owner and group have any permissions - keeping the directory private)

Don't use -R as it's unlikely you want all files to have execute permission.

You probably do want to add the setgid bit though, so that files created here by all users inherit the same group ownership as the directory:

chmod g+s /usr/local/javaagent/appagent/ver2/logs/Tomcat1

Or using octal, in one step:

chmod 2775 /usr/local/javaagent/appagent/ver2/logs/Tomcat1

which gives these permissions:

drwxrwsr-x

(the s in that position is the setgid bit) or

chmod 2770 /usr/local/javaagent/appagent/ver2/logs/Tomcat1

which gives

drwxrws---

To check permissions and owners on the directory, use ls -ld:

ls -ld /usr/local/javaagent/appagent/ver2/logs/Tomcat1

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.