How can I set a default 'chmod' in a Linux terminal? - linux

A previous question just to understand what I'm doing: How to change permissions for a folder and its subfolders/files in one step
So if I change the chmod to 755 for chmod 75 /opt/lampp/htdocs and I restart the system I want the files to be in chmod 755.

Once set, Linux filesystem permissions are unaffected by rebooting the system, unless you have some non-standard software running at boot time which is going back to change them to some default.

Use:
sudo chmod -R a+rwx PathOfFolder

If some process is changing them at boot, place a changeback in /etc/rc.local.

Related

Change permission on /usr with a sudo chmod 644 /usr

I am a trainee programmer and I have sometimes my head in the clouds..
My collegues were messing with my professional computer with ssh connections. One of them told me that the best way to prevent it was to secure my computer. In order to do this, I accidentally change the permissions on the /usr directory.
What I did just for testing was :
sudo chmod 644 /usr
Now I can't use my computer anymore! I can't change the permission back since I am not sudo anymore. On my desktop all my applications shutdown.
Is there a way to revert a chmod 644 on /usr?
There is some important work related stuff on this computer and my internship will probably be terminated if I can't recover the access to important files.
Please help !!
This command need a Sudoers password:
sudo chmod 644 /usr
So either you have a sudo password and can change the right to this file with:
sudo chmod 755 /usr
Or you friends messed with you...
You can do it by:
adding your self to sudoers on boot...
https://askubuntu.com/questions/70442/how-do-i-add-myself-back-as-a-sudo-user

path /tmp does not correspond to a regular file

this happens when I have
an executable that is in the /tmp directory (say /tmp/a.out)
it is run by a root shell
linux
selinux on (default for RedHat, CentOS, etc)
Apparently trying to run an executable that sits in the /tmp/directory as root revokes the privileges. Any idea how to go around this issue, other than turning off selinux? Thanks
You can set file context on binary or directory (containing binary) that are in /tmp that you want to run.
sudo semanage fcontext -a -t bin_t /tmp/location
Then restorecon:
sudo restorecon -vR /tmp/location
Just have a look at the mount options for /tmp directory, most probably you have no-exec option on it (there are many security reasons of doing that, the first being that anyone can put a file in the /tmp directory)

How to use chmod in ~/.bashrc

I would like to change the permission of a file in the /sys directory but the permissions keep reseting after reboot. I tried to add a chmod in the ~/.bashrc so the permission would change upon booting, but I get an error (operation not permited) in terminal. What would be the right way to do this ? Does the ~/.bashrc get executed as root ?
This is my command in ~/.bashrc
chmod 664 /sys/class/backlight/intel_backlight/brightness
And this is the error I get:
chmod: changing permissions of ‘/sys/class/backlight/intel_backlight/brightness’
: Operation not permitted
~/.bashrc is run as the user when the user logs in. It is not run on boot.
If you want to change the permissions on a file, you need to have permission to do so. The message is telling you that you don't have permission -- only root can do so.
The simplest way to do something custom on boot-up is to stick it in the file /etc/rc.local. This script is run by root after booting up (so on every reboot), so you can just stick your chmod command in there.

Linux - how change chmod of /

How can I change chmod of /?
When I run
chmod 755 /
under root, I get
Operation not permitted
Why I need it?
I am installing (logged as root) apt-get install memcached and I get error:
failed to move /initrd.img:Permission denied at /var/lib/dpkg/info/linux-image-3.2.0-26-generic.postinst line 495.
I suppose that your root filesystem is mounted readonly.
You need to check it, for example, creating a file in /root:
# touch /root/hello
Then you will see if it is really so.
If it mounted readonly, you can try to remount it rewrite and see what happened:
# mount -o rw,remount /
Ok, how we've known after the discussion there were an immutable bit on the filesystem.
# lsattr -d /
----i--------e- /
You can remove this bit with chattr -i /. Don't forget to set it back after your operations:
# chattr -i /
# # something
# chattr +i /
Do you have root privileges? Mere mortals (i.e., regular users :-) are not permitted to make these changes
Try to use sudo which gives you super user privileges, as others will mention however this kind of stuff is like witchcraft and if it goes horribly wrong then chances are your system will be "unstable" to say the least.
Apt-get doesn't need to change permissions for / or first degree children. Which command do you
use yum tools for installing it automatically clear all the permission and other installing problems . use this command
1. Login as root
2. change permissions of \
chmod 777 *
3.install bmemcached
* yum install bmemcached**

how to only allow sudo on specify path?

in Linux:
I want to limited user only can do sudo on specify path.
sudo chmod works on /home/Krome/revA
but sudo chmod failed on /home/Krome
Thanks!
Restricting a user or process to a certain path can be done with chroot - the problem here is that after the chroot the commands in $PATH and dynamically loaded objects would no longer be accessible, so you'd need a statically linked shell which executes the chroot as well as the built-in commands that the user shall be able to issue.
I don't think it possible, and am pretty sure it's not reasonable.
chmod would work inside /home/Krome if it's the user's home folder.
I think you need a regular user (without sudo), and everything else can be managed by adding that user to groups and sharing some folders to those groups.
Add to /etc/sudoers something like the following line:
%users ALL = NOPASSWD: /bin/chmod [ugoa][-+=][rwxXst] /home/Krome/*
It basically says that all group users members can invoke sudo chmod in symbolic mode on anything under /home/Krome/ path.
See man sudo for more details.

Resources