what rights/permissions does a file need to be viewed in a webbroswer - linux

Probably a basic questuion, but, I get the following when I visit a webpage I am working on, so the image is not displayed in the browser.
animacionloading.gif:1 GET http://172.21.200.37/username/dir1/animacionloading.gif 403 (Forbidden)
This is the premissions on the file:
$ls -l dir1/
total 432
-rwx------ 1 username username 359032 Apr 29 08:15 animacionloading.gif
Now I can do a chmod 777 animacionloading.gif which gives me these permissions -rwxrwxrwx 1 username username 359032 Apr 29 08:15 animacionloading.gif
and then I can view the image in the the browser.
My question is what is the minimum rights the file needs to be viewed in the browser?
I have some understanding of the following terms, but just not in this case. Would All Users be anyone that visits the webpage? And would they only need read permissions?
u - Owner
g - Group
o or a - All Users
r - Read
w - Write
x - Execute
EDIT1 for my ref, the following will allow the files be seen in the browser.
$ chmod 004 LoadingBasketContents.gif loop.gif
-------r-- 1 username username 45592 Apr 29 09:05 LoadingBasketContents.gif
-------r-- 1 username username 25465 Apr 29 09:05 loop.gif

Related

file owner can not change ownership in Linux

In Linux, I am the owner of a file, then I tried to change owner to another account, failed. Operation not permitted. Do you know why ? I am the user 'BBB'. Thanks
-bash-4.1$ ls -al
drwxrwxrwx 2 AAA games 4096 Nov 23 14:39 .
drwxr-xr-x 3 AAA games 4096 Nov 23 14:36 ..
-rw-r--r-- 1 BBB esmgroup 16798 Nov 23 14:38 XXX-1.0-SNAPSHOT.jar
-bash-4.1$ chown AAA:games ./*.jar
chown: changing ownership of `./XXX-1.0-SNAPSHOT.jar': Operation not permitted
Only root can change the owner on the file. That's final.
You can do that by login to root using su or use sudo before your command.
More information here: https://unix.stackexchange.com/questions/27350/why-cant-a-normal-user-chown-a-file
You can change the file's group if you're in more than one group.
You should login to root account to be granted to change ownership to any user
You can type sudo before the command and then login to your root user

apache permission error

I have centos in VMware and hosted a web application.
This is the url I try to access my page. There is also another demo page "demo.php" that I create for test. its fine can access and prints contents: "its ok." but when I try to my app page which in same directory the browser says:
Forbidden
You don't have permission to access /WP/View/Home/localobjects.php on this server.
http://192.168.118.129/WP/View/Home/localobjects.php
How can I fix this?
Files Permissions in directory.
-rw-r--rwx. 1 root root 272 Apr 2 00:49 activedirectoryusers.php
-rw-r--rwx. 1 root root 236 Apr 17 01:22 configuration.php
-rw-r--rwx. 1 root root 324 Mar 30 00:59 dashboard.php
-rw-r--r--. 1 root root 107 Apr 15 08:28 deneme.php
drwxr-xrwx. 2 root root 4096 Apr 17 01:22 Ipageimplementations
-rw-r--rwx. 1 root root 257 Apr 17 00:52 localobjects.php
-rw-r--rwx. 1 root root 224 Mar 28 18:41 policy.php
-rw-r--rwx. 1 root root 257 Apr 13 01:58 timeintervals.php
Here is a cheatsheet…
Directories must have the permissions "drwxr-xr-x".
You set them with chmod 755 [directory name].
Files must have the permissions "-rw-r--r--".
You set them with chmod 644 *php for all the php files in a folder. If you have other files which must be seen on the web (.css, etc.) chmod them accordingly.
To get the "magic numbers" you have three digits:
the first one is for the owner
the second one is for the owner's group
the third is for the rest of the world
Numbers are the sum of:
4: readable
2: writeable
1: executable
In doubt, make a directory at a time: if you give wrong permissions (not executable, like files) to a folder you can't browse it.

ftp to show files with owner on linux

We used to get directory content listed with the owner name from HP-UX system using FTP client , recently the system was migrated to Suse-Linux. Now when we FTP to this machine, directory list does not show the owner name of the files.
How would one enable listing directory with owner name in Linux ?
Well in ftp (and most shells anyway), you have the ls command. This prints the list of files.
**Example session** (cutted out some messages):
$ ftp ftp.ed.ac.uk
Connected to luther.is.ed.ac.uk.
220-
Login using the username 'anonymous' and use your email address as password.
ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
lrwxrwxrwx 1 root root 8 Feb 26 2014 INSTRUCTIONS-FOR-USING-THIS-SERVICE -> .message
drwx-wx-wx 3 root root 4096 Feb 17 14:57 edupload
drwx-wx-wx 3 root root 131072 Feb 17 20:20 incoming
drwxr-xr-x 45 root root 4096 Feb 19 2014 pub
226 Transfer complete
ftp>
The table shows:
drwxdrwxdrwx: d stands for directory, and then rwx for read-write-execute for (in sequential order), the owner, the group and all people with login access;
the name of the owner (root);
the name of the group of the owner (root);
file size;
modification date; and
filename.

755 folder in document root not readable by apache

Story: I deleted a directory LogViewer from the document root that was browseable and working perfectly. Later I decided to add it back but now apache wont show it.
drwxr-xr-x. 12 user group 4096 Jun 19 15:16 272
drwxr-xr-x. 12 user group 4096 Jun 19 15:17 273
drwxr-xr-x. 3 user group 4096 Jun 20 08:06 LogViewer
The 272 and 273 directories are browsable and work.
Output of ls -lZ:
drwxr-xr-x. user group system_u:object_r:httpd_sys_content_t:s0 272
drwxr-xr-x. user group system_u:object_r:httpd_sys_content_t:s0 273
drwxr-xr-x. user group unconfined_u:object_r:user_home_t:s0 LogViewer
What I've Tried:
I have restarted apache multiple times. I've stopped it, and started it. I've refreshed the browser, I've cleared cookies and all temp files.
My Question: Wtf?
As per: SELinux doc
To make a folder viewable from a special user public HTML folder, it
needs to have a type that httpd has permissions to read, presuming the
Apache HTTP Server is configured for UserDir and the Boolean value
httpd_enable_homedirs is enabled.
Try this command:
chcon -R -t httpd_user_content_t LogViewer

could not create directory /home/hadoop/.ssh : permission denied?

I am configuring hadoop on Ubuntu os. I need to create RSA key pair to allow hadoop to interact with its nodes, so i running this command:
hadoop#ubuntu:~$ ssh-keygen -t rsa -P ""
then I get this:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):
Could not create directory '/home/hadoop/.ssh': permission denied.
Enter passphrase (empty for no passphrase ):
Enter same passphrase again:
open /home/hadoop/.ssh/id_rsa failed: No such file or directory.
Saving the key failed: /home/hadoop/.ssh/id_rsa.
Forgot to create .ssh dir in your home?
Try that:
mkdir -p ~/.ssh
then re-run ssh-keygen.
Also possibly you doing ssh-keys creation from wrong user.. You started that shell using sudo?
Try to set HOME dir manually or enter right path in prompt.
check your home directory name and permissions
echo $HOME
cd ~ ; ls -l
ls -l .ssh
ls -lR .ssh
if above output is OK and you have correct permissions, perhaps your quota is full
try with "sudo" and see what happens...
Seems like current user doesn't own the contents under home directory.
Gain the ownership as shown as below:
admin#mydb22-02:~$ sudo chown admin.admin /home/admin/
admin#mydb22-02:~$ ls -la
total 32
drwxr-xr-x 2 admin admin 4096 Nov 3 23:29 .
drwxr-xr-x 3 admin admin 4096 Dec 23 2012 ..
-rw------- 1 admin admin 191 Feb 13 2013 .bash_history
-rw-r--r-- 1 admin admin 220 Apr 3 2012 .bash_logout
-rw-r--r-- 1 admin admin 3486 Apr 3 2012 .bashrc
-rw-r--r-- 1 admin admin 675 Apr 3 2012 .profile
-rw-r--r-- 1 admin admin 0 Nov 3 23:29 .sudo_as_admin_successful
-rw------- 1 admin admin 4221 Nov 3 20:31 .viminfo
generating keys would work now as .ssh directory will now be created and owned by current user after generating the assymetric keys
I have spent arround 1 hr on this and finally got the solution. It is due to permission problem. You have to use chown for your 'hadoop user'.
1. First make hadoop directory.
cd /home
mkdir hadoop
then check 'ls -l'. it gives result like :
drwxr-xr-x 2 hadoop hadoop 4096 Aug 22 22:17 hadoop
2. sudo chown hadoop.hadoop /home/hadoop/
3. Then run remaining command for key generater.

Resources