Permission denied in Amazon EC2 while accessing Tomcat 7 folder

8,079

Instead of trying to access the logs as root user, it may be simpler to change the permissions on the server to grant access to the ec2-user. This can usually be done with the commands chown and chmod, but the exact steps depend on the way your server is set up. If you need help to do that, you can post the output of the following commands and I'll try to help:

sudo ls -ld /var/log/tomcat7
id

Edit: Ok based on your output bellow, what you could do is change the group of the log directory to tomcat (instead of root) and then add the ec2-user to the tomcat group:

sudo chown -R tomcat:tomcat /var/log/tomcat7
sudo usermod -G ec2-user,wheel,tomcat ec2-user

Then you must log out and log back in for the new group membership to apply.

Share:
8,079

Related videos on Youtube

Gaurav Agarwal
Author by

Gaurav Agarwal

Updated on September 18, 2022

Comments

  • Gaurav Agarwal
    Gaurav Agarwal almost 2 years

    I am trying to copy a log file from an Amazon EC2 instance to my local machine (Windows 7). I am using WinSCP438, which is able to connect to the remote (Amazon EC2) server instance. I am trying to access the instance as the "root" user in WinSCP using the method described here, but I am getting an error shown in the below image:

    Error listing directory '/var/log/tomcat7'. /Command 'cd /var/log/tomcat7' failed with return code 1: Permission denied

    Why I am getting this error, and how do I copy the file from remote server (Amazon EC2) to my local machine?


    Update: Output of commands, as requested:

    $ sudo ls -ld /var/log/tomcat7
    drwxrwx--- 2 tomcat root   4096 Jul 4 12:01 /var/log/tomcat7
    $ id
    uid=222(ec2-user) gid=500(ec2-user) groups=500(ec2-user), 10(wheel)
    
  • Gaurav Agarwal
    Gaurav Agarwal almost 12 years
    sudo ls -ld /var/log/tomcat7 -> drwxrwx--- 2 tomcat root 4096 Jul 4 12:01 /var/log/tomcat7 id -> uid=222(ec2-user) gid=500(ec2-user) gropus=500(ec2-user), 10(wheel)