Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am facing a strange issue with Linux users (non root). Let me explain this in a bit detail.
I have mysql 5.1.47 running and I need to give read only access so few users who can query mysql database and generate CSV on their home directory, and that user must have read/write access to that directory. For example I created a user 'testing' and directory is created like /home/testing. Now I have to do chmod 777 /home/testing in order to enable mysql to generate CSV in this directory. But issue is that any other user come to this directory (/home/testing) through its FTP login can delete any file. Whereas this directory is home directory of 'testing' user and only he/she must have full access and all other non root users must not able to delete any file in this directory. How to achieve this?
I have to do chmod 777 /home/testing in order to enable mysql to generate CSV
No you don't. And chmodding something 777 is always lets-not-think-about-the-consequences bad advice: you could for instance let the user produces the CSV file to a temporary location ('mktemp'), chown it to a group the FTP user can access, then let the FTP user 'install' it with the required access rights.
Actually that doesn't fulfill my requirement. Let me try to explain in simple way. I have a production system where MySQL Database is running. I want to give read only access(through mysql read only user) to MySQL where a person can connect to mysql and generate CSVs from MySQL Queries somewhere. So I need to create OS user as well where user can generate CSVs using MySQL Query. Now problem is here, MySQL don't generate CSVs in directory where its not chmod 777 but when I do chmod 777 on user home directory mysql start generating CSVs but all other OS users (non root) also got full access to that directory. I only want to give write access to MySQL and that os User onky.
I hope it will be clear now and you can suggest me its solution as it is driving me crazy.
MySQL don't generate CSVs in directory where its not chmod 777 but when I do chmod 777 on user home directory mysql start generating CSVs
Do you understand what making the directory permissions 777 does? The permissions are set up according to owner/group/other with 3 bits for read,write, and execute; 777 allows everybody ALL of these abilities which is why everyone can access each others folders! MySQL does not require 777 access, it requires write (and possibly execute on directories) access.
A much safer approach would be to either create a GROUP (the middle permission) that allows MySQL access to that directory and to play both the MySQL system user and the desired user(s) in that group. Similarly, each user has a group associated with them. You could add MySQL to their group, though this is a little less secure.
Unspawn's suggestion is similar, in that it uses group permissions to solve the 777 issue and it addresses the mysql having write access to home folders by creating a common area for the creation of the CSV files where each user can transfer their data from. You could expand upon this to create subdirectories for each user where MySQL and ONLY THAT USER could access. This would achieve all of your stated goals while maximizing the security.
I have a production system where MySQL Database is running. I want to give read only access(through mysql read only user) to MySQL where a person can connect to mysql and generate CSVs from MySQL Queries somewhere. So I need to create OS user as well where user can generate CSVs using MySQL Query.
How about setting up something like phpMySQL? That would let them create CSV files directly on their own machines with no need for an OS user. You would have to make sure that phpMySQL was locked down tightly, but it might be a more secure approach than having 777 directories.
<edit>
Actually, why don't you open up MySQL for TCP/IP connections and let the people access it that way. The more I think about it the less I think you need to have people logged into the MySQL server to do their work. MySQL was designed to be accessed remotely, so you should think about doing that.
</edit>
I tried the same but no luck. I make a group and added mysql user and other os user to that group. Now I change group of the directory to new one and tried to generate CSV through MySQL but it still gives me Error # 13. I would be very thankful if you can give me commands to implement that.
Thanks for your reply. I can't install PHPMySQL as it is not under my control.
People already accessing MySQL remotely but to generate CSV, MySQL generate it on the same server where it is installed. Thats why I need to create OS user so that MySQL generates CSV in user home directory and user can login through FTP and Picks the files and no other user can have access to that directory.
I believe that Error 13 is a permissions issue. It looks like the directory permissions should have been taken care of with the last step. Do you perchance have another security application like Apparmor blocking it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.