• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 764
  • Last Modified:

Change Linux folder permissions (recursive) for one user

Hi,

I'd like to change the folder permissions to something like 755 for the folder /var/lib/mysql for the user "vkimura". What's the linux command to do this? I have a Centos and Ubuntu machine. Are they the same command?

So something like this:
chmod [-R] ### <filename or directory>

but specifically apply this command to only a user. I have to use su - to do this.

Thanks,
Victor
0
Victor Kimura
Asked:
Victor Kimura
8 Solutions
 
farzanjCommented:
Yes, the command to change user permissions is chmod, use -R to apply it recursively.  It is valid for both CentOS and Ubuntu.

chmod 755 <filename or directory>

To change user ownership, you can do

chown user:group <filename or directory>

Or

chown user: <filename or directory>
0
 
farzanjCommented:
To do so recursively so that it applies to all the files/folders inside a folder.

 chmod -R 755 <filename or directory>
0
 
farzanjCommented:
For any file or folder, you have to be the file/director owner or root.
0
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

 
farzanjCommented:
You can also use these commands with sudo, that way it would work just as if root did it.
Eg.
sudo chmod -R 755 <filename or directory>
0
 
Victor KimuraAuthor Commented:
Hi farzanj,

Thanks, that's helpful.

But I don't want to chown. The user mysql owns  the files and folder in /var/lib/myql but I want to keep it the same owner. I just wish to add my user 'vkimura' so that vkimura can also read, write, execute the files/folder in /var/lib/mysql.

Is there a way to do this? If I add vkimura to the group (also mysql) that owns /var/lib/mysql then won't vkimura also have access to to everything that the user mysql has access too? Instead, I only wish for vkimura to have read/write/execute permissions on /var/lib/mysql. How do I do this if it's possible?

0
 
hossamshaabanCommented:
you can use file access list,

# setfacl -m u:username:rwx /var/lib/mysql
0
 
farzanjCommented:
What hossamshaaban is file system ACLs.  You can certainly accomplish this, provided you have ACL's enabled on your filesystem.

So the precise command you would need are as under.




setfacl -R -m u:vkimura:rwx /var/lib/mysql

Open in new window

0
 
Jayachandran PalanisamyTechnical Consultant - LinuxCommented:
Hi,
You can add the user 'vkimura' under mysql group that means user vkimura 's secondary group is mysql so that the user vkimura will get same rights which mysql group has.
#vi /etc/group
Add user here,
mysql:x:27:vkimura,user1,user2

I hope this will help you.

Regards,
Jayachandran Palanisamy
*personal e-mail removed by Mod_MarlEE 1 Nov 2011*
0
 
farzanjCommented:
When you want to get access through a group, the permission that matter are file's group permissions.  Make sure that the group permissions for files/folders are what you need.
0
 
Victor KimuraAuthor Commented:
Thanks for your help.
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now