Question

I am new to linux and I am having a problem with permissions. Quite a long time ago I had created an AWS EC2 instance from scratch using step by step tutorials scattered over the web. I managed to upload an html website over there and linking the domain to it etc...

Now that after six months I am connecting again to the EC2 instance using MobaXTerm SSH or SFTP session, I can't get to upload new files or rename old files etc. I am using the regular ec2-user which from what I understand is quite a privileged user nearly as permissable as root.

I connect successfully with the old key that I had created and I can arrive to the desired directory. But I simply can't upload new files or replace old ones because I get a permission denied error. I don't know why and how to fix.

Last login: Fri Apr 25 13:18:26 2014 from 85.232.210.97

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2014.03-release-notes/
[ec2-user@ip-172-31-47-208 ~]$ cd ./var/www/html/
-bash: cd: ./var/www/html/: No such file or directory
[ec2-user@ip-172-31-47-208 ~]$ cd .
[ec2-user@ip-172-31-47-208 ~]$ cd ..
[ec2-user@ip-172-31-47-208 home]$ cd ..
[ec2-user@ip-172-31-47-208 /]$ cd var/www/html/
**[ec2-user@ip-172-31-47-208 html]$ mv index.html index_old.html
mv: cannot move ‘index.html’ to ‘index_old.html’: Permission denied**
[ec2-user@ip-172-31-47-208 html]$ ls -l
total 164
drwxrwxr-x  2 ec2-user ec2-user  4096 Mar 27 16:03 css
-rw-rw-r--  1 ec2-user ec2-user  5686 Mar 25 08:34 favicon.ico
drwxrwxr-x  2 ec2-user ec2-user  4096 Mar 27 16:04 font
drwxrwxr-x 14 ec2-user ec2-user  4096 Mar 27 16:18 images
**-rwxrwxrwx  1 ec2-user ec2-user 48675 Apr 25 13:41 index.html**
drwxrwxr-x  4 ec2-user ec2-user  4096 Mar 27 16:19 js
drwxrwxr-x  3 ec2-user ec2-user  4096 Mar 27 16:20 nbproject
drwxrwxrwx  2 ec2-user ec2-user  4096 Apr 25 13:30 old
drwxrwxr-x  3 ec2-user ec2-user  4096 Mar 27 16:20 php
-rw-rw-r--  1 ec2-user ec2-user 41041 Sep 17  2013 PIE.htc
drwxrwxr-x 24 ec2-user ec2-user  4096 Mar 27 16:22 skins
-rw-rw-r--  1 ec2-user ec2-user 30951 Mar 26 19:07 style.css
[ec2-user@ip-172-31-47-208 html]$

Can you guide me? What to check? Where to start and continue to dig to sort the issue?

I used WinSCP and SFTP also to manage file uploads easily but the permission issue remains unchanged.

Thank you

Was it helpful?

Solution

In order to add or remove files to/from a directory, you need to have write permission on the directory in question, which is /var/www/html in your case.
(I originally wrote just a comment, but thinking again there is only one reason why you see what you are seeing.)
Use ls -ld /var/www/html to have a look at the permissions on the directory itself. It should probably belong to root:ec2-user, which in turn means it should likely be chmod 775 (owner and group have read/write/execute permission, others may not write).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top