Chmod in Shell Script does not work - linux

i am running a small server using Ubuntu 12.04. I am logged in as a non-root user via SSH public key authentication. This server runs apache which is supposed to run a symfony2 website.
I want to write a shell script that ensures that every file and directory in my symfony2 app has the right owner and the right access rights. The script I use is this:
#!/bin/bash
chown -R www-data:www-data portal
chmod -R 755 portal
php portal/bin/console cache:clear --env=dev
php portal/bin/console cache:clear --env=prod
The script has been granted the exec right via chmod +x setup (setup is the name of the script)
I try to execute it as an root via ./setup.
There are no error messages displayed. But after running it the chown and chmod does not seem to work. the owner is still the same (root:root)
If I execute these commands manually in the console they work.
Why is this? What can I do to solve the problem?
Kind regards
Thomas

Related

Laravel persistent permissions for php artisan config:cache file creation

I've followed this guide to set permissions for Laravel 9 running on WSL2 through docker. Everything works great, but whenever I run
php artisan config:cache
The /bootstrap/cache/config.php file does not get updated as you would expect.
ls -l returns the following after running config:cache:
-rw-r--r-- 1 www-data www-data 26933 Nov 16 08:10 config.php
The linked guide above sets the folder permissions to -rwxrwxr--, which then gets overrode by the config:cache command.
Is there any way to persist the permissions on this file without having to run chmod every single time I modify the .ENV or config files?
EDIT
After digging around some more, it looks like everything BUT the 'debug' variable is being updated in the bootstrap/cache/config.php file. Manually changing the debug value to true and re-running php artisan config:cache will revert debug back to false. I'm 100% sure my .ENV is set to true, as well as the backup in my config/app.php file. I'm running in the 'local' environment.
How do I get that debug value to persist?
Run
sudo chmod -R 777 /bootstrap/cache/config.php
sudo chmod -R 777 /bootstrap/cache
You can also run
sudo php artisan config:clear
sudo php artisan optimize:clear

Provide Hadoop full access to Admin from Root in CentOS

I have installed Hadoop-2.8.0 being root in below directory.
/root/hadoop-2.8.0
I have a user named "KrishnaMahi". He is admin. He is in below directory.
/home/krishnamahi
I want to provide full access of Hadoop to admin. How shall I provide full access to admin without giving root password? I am using CentOS 7. Please help me with a solution.
Under the root user execute the following command
chown -R krishnamahi:krishnamahi /root/hadoop-2.8.0
and then execute the next command to be the root user without password
visudo
Insert this code at the last line
krishnamahi ALL=(ALL) NOPASSWD:ALL
save changes & exit
Execute the following once command
sudo chown -R krishnamahi:krishnamahi /root/hadoop-2.8.0
Then the user have full access to the hadoop directory.

Rsync mkdir permission denied

I am trying to use "Rsync" to copy my spark directory to all the slave machines by this command:
rsync -avL --progress /path/to/spark-0.9.0-incubating ubuntu#<Public_ip_of_slave>:/usr/local`
I am following the instructions on this site:
http://docs.sigmoidanalytics.com/index.php/Setup_hadoop_2.0.0-cdh4.2.0_and_spark_0.9.0_on_ubuntu_aws_cluster"
but I am facing an error which is permission denied to make the folders in the destination.
Can anyone help me?
The ubuntu user (which you are using for scp) does not have the appropriate directory permissions on /usr/local at the remote server.
Misconfiguration can result in security issues so changing the directory permission of /usr/local is not recommended. If you wish to do so run:
ssh ubuntu#remote-server 'sudo chown root:ubuntu /usr/local'
where remote-server is the hostname or IP of the remote server and assuming that ubuntu is an administrator. You may also allow all others to write to the directory:
ssh ubuntu#remote-server 'sudo chmod o+w /usr/local'
but this is more dangerous than the previous option.
Alternatively, you may copy it into your home directory first then issue a sudo command to move the files into /usr/local:
rsync -avL --progress /path/to/spark-0.9.0-incubating ubuntu#remote-server:~
ssh ubuntu#remote-server 'sudo mv ~/spark-0.9.0-incubating /usr/local'
~ will be expanded to the home directory of the user, which in this case is likely to be /home/ubuntu/.
Do remember to change the permissions of /usr/local/spark-0.9.0-incubating as appropriate to allow access to authorized users using the chmod command.

Cherokee: accessing uwsgi configuration file

I'm running into a permissions problem with Cherokee+uWSGI on Ubuntu Server 13.10 intended for a Django production environment. When I start uWSGI manually as root user prior to launching cherokee, everything goes smooth:
sudo uwsgi --ini /home/instytut21/instytut21l/instytut21/uwsgi.ini
But when I try to access the site through the server (running as www-data) without that, I keep getting a 503 Service Unavailable response and the following message in the logs:
sudo cat /var/log/cherokee/instytut21.error.log
realpath() of /home/instytut21/instytut21.pl/instytut21/uwsgi.ini failed:
[core/utils.c line 3574]
I've spent a good while trying to figure out what causes the problem. I've tried giving ownership to $USER:www-data and www-data:www-data with all kinds of file permissions ranging from 600 to 777.
I don't want to run the server as root for security reasons. How can I make the ini file accessible to cherokee?
I finally found a solution to a similar problem at www-data permissions? . I slightly modified it and solved my problem by executing the following commands.
Own the whole directory by me and group www-data:
sudo chown -R $USER:www-data /home/instytut21/instytut21.pl/
Grant all permissions to the group:
sudo chmod -R g+rwx /home/instytut21/instytut21.pl/
Ensure all uploaded filed get the same permissions:
sudo chmod -R g+s /home/instytut21/instytut21.pl/

How can I run Jboss as a daemon on a virtual machine?

What I've done so far according to these instructions is unziped and moved jboss into my /usr/local/ directory. Then I put the jboss_init_redhat.sh script in /etc/init.d/ as jboss and edited the script to meet my configurations. I then run /etc/init.d/jboss start and all it says is
JBOSS_CMD_START = cd /usr/local/jboss-4.2.3.GA//bin; /usr/local/jboss-4.2.3.GA//bin/run.sh -c default -b 0.0.0.0
and then nothing happens. Also if I go into /usr/local/jboss-4.2.3.GA/bin and run run.sh it starts the server but when I go to the vm's IP:8080 in my browser I still get nothing. Any help would be appreciated also I don't know much about doing this so excuse my inexperience.
Init scripts should be owned and started by root.
The init script you use uses su (better would be to runuser) to change to the jboss user.
The jboss user itself does not have permission to do that.
The jboss user also does not have permission to write to /var/run etc.
So run sudo /etc/init.d/jboss start (you need to set up sudo first to allow this) or change to the root account and execute /etc/init.d/jboss start.
If it still fails check the logs at /usr/local/jboss-4.2.3.GA/server/default/log.
Hope this helps.

Resources