can`t write to a file with root - root

Please help me to understand why I can`t write to a file
[root#192.168.1.11 ~]# echo "Hello World" >file.txt
-bash: 1.txt: Permission denied
[root#192.168.1.11 ~]# ls -lah file.txt
-rw-r--r-- 1 root root 7 May 8 14:57 file.txt
[root#192.168.1.11 ~]# id
uid=0(root) gid=0(root) groups=0(root)

Related

Install of openresty : nginx.pid not found

I try to install OpenResty 1.13.6.1 under CentOS 7. When I try to run openresty I get this error:
[root#flo ~]# openresty -s reload
nginx: [error] open() "/usr/local/openresty/nginx/logs/nginx.pid" failed (2: No such file or directory)
When I look at my logs, I only have 2 files:
[root#flo ~]# ll /usr/local/openresty/nginx/logs/
total 8
-rw-r--r--. 1 root root 0 1 mars 12:24 access.log
-rw-r--r--. 1 root root 4875 1 mars 16:03 error.log
I do not see how to find a solution.
///////////////////UPDATE//////////////////
I try to do this to folow the instructions of this page : https://openresty.org/en/getting-started.html
[root#flo ~]# PATH=/usr/local/openresty/nginx/sbin:$PATH
[root#flo ~]# export PATH
[root#flo ~]# nginx -p pwd/ -c conf/nginx.conf
And I have this error :
nginx: [alert] could not open error log file: open() "/root/logs/error.log" failed (2: No such file or directory)
2018/03/02 09:02:55 [emerg] 30824#0: open() "/root/conf/nginx.conf" failed (2: No such file or directory)
/////////////////UPDATE2//////////////:
[root#nexus-chat1 ~]# cd /root/
[root#nexus-chat1 ~]# ll
total 4
-rw-------. 1 root root 1512 1 mars 11:05 anaconda-ks.cfg
drwxr-xr-x. 3 root root 65 1 mars 11:36 openresty_compilation
Where do I need to create these folders ?
mkdir ~/work
cd ~/work
mkdir logs/ conf/
In /usr/local/openresty/ ?
Very likely nginx cannot open a log file because folder doesn't exists or permission issue.
You can see the reason within error.log file
openresty -s reload is used to tell nginx to reload the currently running instance. That's why it's complaining about the missing pid file.
Anyway, that's not the correct way to start openresty. Have a look at https://openresty.org/en/getting-started.html for instructions on how to get started.

Permission denied with sudo

in a buildroot environment I added one user to the group wheel. Now I can execute commands with the root's privileges using sudo.
It seems it works but when I try to export a pin on my RPi I always get Permission denied:
rpi:~$ sudo echo 4 > /sys/class/gpio/export
sh: can't create /sys/class/gpio/export: Permission denied
Here the contents of that directory:
rpi:~$ ls -l /sys/class/gpio/
total 0
--w------- 1 root root 4096 Jan 1 00:00 export
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
--w------- 1 root root 4096 Jan 1 00:00 unexport
Isn't enough to get the root's privilege with sudo to write in the export file? I'm afraid about the owner and groups. In fact if I type:
rpi:~$ sudo chmod a+w /sys/class/gpio/*
then I can successfully export the pin. But I don't know if this is the best way to do this.
When you run the command sudo echo 4 > /sys/class/gpio/export, it first executes sudo echo 4 which runs echo with elevated privileges (which is kind of pointless). Then the result is passed by the shell (not by echo) to a new command of /sys/class/gpio/export, which because it is a new command it isn't executed with elevated privileges.
There is a Unix.SE question here which explains this and the options.
In summary of that link you should be able to do something like:
sudo sh -c 'echo 4 > /sys/class/gpio/export'

Can't edit -rwxrwxrwx file on solaris

I created a file:
touch script.sh
changed it's permissions:
chmod 777 script.sh
which gave the following permissions:
-rwxrwxrwx 1 foouser staff 0 Aug 18 15:41 script.sh
... but when I attempt to edit in vi I get a permissions error:
"script.sh" File is read only
Why is this?
After some digging I figured out that someone had set:
alias vi=view
So doing unalias vi fixed the problem...

Exception handling app/logs/dev.log

The stream or file "/home/nick/projects/Symfony/app/logs/dev.log" could not
be opened: failed to open stream: Permission denied
I get it in symfony.
I know that I can go to app/logs and delete dev.log but this is happening to often and is annoying to delete it again and againand again.
Is there any way to make it just disapear?
LE: I guess, that I got the reply.
I run the comands prefixed with sudo.
Eg: sudo php app/console generate:bundle --namespace=Acme/StoreBundle will work like a charm.
nick#ptb:~/projects/Symfony$ ls -al app/logs
total 76
drwxrwxrwx+ 2 nick nick 4096 nov 24 15:16 .
drwxr-xr-x 6 nick nick 4096 nov 24 15:28 ..
-rw-rw-r--+ 1 www-data www-data 59583 nov 24 16:25 dev.log
-rw-rw-r--+ 1 nick nick 0 oct 6 15:55 .gitkeep
I think that you create directory app/logs as sudo (root), so symfony doesn't have permissions to write into the file dev.log. Manually remove directory app/logs (and all contents), create it as normal user and setup up permissions, like they are described in the official documentation http://symfony.com/doc/current/book/installation.html.
Something like:
$ sudo rm -rf app/logs
$ mkdir app/logs
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Or use any other option which is described in official documentation.
If this not works then please paste us result of command:
$ ls -al app/logs
In my case, I used CentOS 7 and I solved it by set SELINUX=disabled as follow.
- sudo nano /etc/selinux/config
- Edit the file by set SELINUX=disabled
- Restart again then it worked !
I tested and tried many method included chmod, chwon, setfacl, etc but it cannot solve the problem until I tried above solution and it worked!
You should have a look at this http://symfony.com/doc/current/book/installation.html#configuration-and-setup.
UPD
Sometimes the solutions using ACL won't work, in this case try the forth option 4. Use the same user for the CLI and the web server
Use commands prefixed with sudo. I also got this error when I tried to run the server. Then I used 'sudo' and the error disappeared.
$ sudo php bin/console server:run

How to check permissions of a specific directory?

I know that using ls -l "directory/directory/filename" tells me the permissions of a file. How do I do the same on a directory?
I could obviously use ls -l on the directory higher in the hierarchy and then just scroll till I find it but it's such a pain. If I use ls -l on the actual directory, it gives the permissions/information of the files inside of it, and not of the actual directory.
I tried this in the terminal of both Mac OS X 10.5 and Linux (Ubuntu Gutsy Gibbon), and it's the same result. Is there some sort of flag I should be using?
Here is the short answer:
$ ls -ld directory
Here's what it does:
-d, --directory
list directory entries instead of contents, and do not dereference symbolic links
You might be interested in manpages. That's where all people in here get their nice answers from.
refer to online man pages
You can also use the stat command if you want detailed information on a file/directory. (I precise this as you say you are learning ^^)
$ ls -ld directory
ls is the list command.
- indicates the beginning of the command options.
l asks for a long list which includes the permissions.
d indicates that the list should concern the named directory itself; not its contents. If no directory name is given, the list output will pertain to the current directory.
In GNU/Linux, try to use ls, namei, getfacl, stat.
For Dir
[flying#lempstacker ~]$ ls -ldh /tmp
drwxrwxrwt. 23 root root 4.0K Nov 8 15:41 /tmp
[flying#lempstacker ~]$ namei -l /tmp
f: /tmp
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
[flying#lempstacker ~]$ getfacl /tmp
getfacl: Removing leading '/' from absolute path names
# file: tmp
# owner: root
# group: root
# flags: --t
user::rwx
group::rwx
other::rwx
[flying#lempstacker ~]$
or
[flying#lempstacker ~]$ stat -c "%a" /tmp
1777
[flying#lempstacker ~]$ stat -c "%n %a" /tmp
/tmp 1777
[flying#lempstacker ~]$ stat -c "%A" /tmp
drwxrwxrwt
[flying#lempstacker ~]$ stat -c "%n %A" /tmp
/tmp drwxrwxrwt
[flying#lempstacker ~]$
For file
[flying#lempstacker ~]$ ls -lh /tmp/anaconda.log
-rw-r--r-- 1 root root 0 Nov 8 08:31 /tmp/anaconda.log
[flying#lempstacker ~]$ namei -l /tmp/anaconda.log
f: /tmp/anaconda.log
dr-xr-xr-x root root /
drwxrwxrwt root root tmp
-rw-r--r-- root root anaconda.log
[flying#lempstacker ~]$ getfacl /tmp/anaconda.log
getfacl: Removing leading '/' from absolute path names
# file: tmp/anaconda.log
# owner: root
# group: root
user::rw-
group::r--
other::r--
[flying#lempstacker ~]$
or
[flying#lempstacker ~]$ stat -c "%a" /tmp/anaconda.log
644
[flying#lempstacker ~]$ stat -c "%n %a" /tmp/anaconda.log
/tmp/anaconda.log 644
[flying#lempstacker ~]$ stat -c "%A" /tmp/anaconda.log
-rw-r--r--
[flying#lempstacker ~]$ stat -c "%n %A" /tmp/anaconda.log
/tmp/anaconda.log -rw-r--r--
[flying#lempstacker ~]$
There is also
getfacl /directory/directory/
which includes ACL
A good introduction on Linux ACL here
This displays files with its permisions
stat -c '%a - %n' directory/*
In addition to the above posts, i'd like to point out that "man ls" will give you a nice manual about the "ls" ( List " command.
Also, using ls -la myFile will list & show all the facts about that file.
On OS X you can use:
ls -lead
The e option shows ACLs. And ACLs are very important to knowing what the exact permissions on your system are.
ls -lstr
This shows the normal ls view with permissions and user:group as well
To check the permission configuration of a file, use the command:
ls –l [file_name]
To check the permission configuration of a directory, use the command:
ls –l [Directory-name]

Resources