6

I don't have too much experiences with servers but I've tried to do something ;) I have my WP webpage on amazon EC2 and I wanted to edit some settings in php.ini through filezilla (sftp) But I had to set permissions to my user:

sudo chown -R ec2-user:ec2-user /etc

But now I can't even restart apache or set back permissions to root If i try to do something like this:

sudo chown -R root:root /etc

or

sudo systemctl restart apache2.service

I see this information: "sudo: /etc/sudo.conf is owned by uid 500, should be 0 sudo: /etc/sudoers is owned by uid 500, should be 0 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin"

What can I do?

Marcin Kusuah
  • 119
  • 1
  • 1
  • 7

6 Answers6

3

You should never do sudo chown -R ec2-user:ec2-user /etc. You have modified the permission settings of your entire /etc directory.

/etc is a very important folder for your operating system that's why you're getting the error.

launch a new instance and backup your source code from your previous instance and re-upload the code. let me know if you have any issues.

I'm not understanding why you can't modify your php.ini file? You need to ssh into the server and edit the file. If you can't do that, you need to move the file to the ftp folder where it's permissible, modify the file and put the file back to it's original location and restart apache.

Furthermore, I recommend you use Ubuntu for your Wordpress server rather than using Centos or Amazon Flavour of Linux.

unixmiah
  • 3,081
  • 1
  • 12
  • 26
3

log into putty as ec2-user

sudo su

[root@ip-yoursite- home]

now for php 5.0 sudo vim /etc/php.ini

for php 7.0 use sudo vim /etc/php-7.0.ini

press i and now search for upload_max_filesize =100M , post_max_size=100M (change as per your requirement)

press esc ,now save and exit use this command:wq

restart your apache server sudo service httpd restart

sumu kuma
  • 41
  • 1
  • 1
    Why press i before searching? Surely they should press /upload_max to search. Also how does this fix the permissions that they broke? – Alexx Roche Oct 13 '17 at 06:19
0

There are two options.

  1. Create a new instance on Amazon. Check the file permissions on the new machine.

cd /etc
ls -lrt

This should give result like this

-rw-r--r--  1 root root      2064 Nov 24  2006 netscsid.conf
-rw-r--r--  1 root root      1343 Jan 10  2007 wodim.conf
-rw-r--r--  1 root root       624 Aug  8  2007 mtools.conf
-rw-r--r--  1 root root      2570 Aug  5  2010 locale.alias
-rw-r--r--  1 root root       356 Jan  2  2012 bindresvport.blacklist
-rw-r--r--  1 root root       349 Jun 26  2012 zsh_command_not_found

Set the same permission on old EC2 instance one by one.

Example

chown -R root:root netscsid.conf

  1. You could create a new setup.

PS: for future, You could use this command for changes in php.ini file rather than changing owner or permission.

sudo vim /etc/php5/apache2/php.ini
R Yadav
  • 1
  • 3
  • 1
    `sudo nano /etc/php5/apache2/php.ini` is probably nicer advice for a complete newbie to server admin, given that questions like http://stackoverflow.com/questions/11828270/how-to-exit-the-vim-editor exist. – ceejayoz Jul 11 '16 at 18:40
0

The short answer is that chown -R is recursive and there are lots of utilities and other files and programs required for various operations, including sudo and su. Root is a special user with uid 0, and that user has greater permissions, and the ability to perform certain operations, that ec2-user cannot. This means that undoing what you have done is not simple or straightforward.

This is why the answers provided so far focus on a reinstallation of the operating system, which is what I would also recommend. It is likely faster.

Another part of this answer is to not try and sftp into the server to change core files. It would require having an sftp login land at the root (or /etc) directory, and that is not a common configuration.

Instead, use sftp or scp to copy changed files to a user directory, and them move them from a command prompt (ssh/bash shell). For simple textfile editing, it is easier to use a command line text editor such as nano which is more user friendly than some of the older editors.

As well, the file itself does not nor should it have its permissions changed, rather, once logged in, use sudo or su to perform the operations. Example:

ssh ec2-user@host.domain.tld 
sudo su 
nano /etc/php.ini
jeffmcneill
  • 2,052
  • 1
  • 30
  • 26
0

Imagine that you have a series of boxes, each with two numbers inside. These numbers are mostly 0:0 but could be any whole numbers up to 2^31-2.

The numbers are independent, so 0:0 and 0:42 are both possible. Your -R flag recursively changes all of these numbers in all of the boxes to the same pair.

This loses information. (Without a backup) there is no easy way to know what the numbers in the boxes were before you ran the command.

If you have a matching, (or very similar) server you might be able to restore most of the permissions using rsync, or use a script to record the uid:gid of each file on the working server into a log file and then use that to correct the permissions on the broken server.

ls -n 

will show you the numerical values for uid and gid (3rd and 4th column on my linux servers.)

Alexx Roche
  • 3,151
  • 1
  • 33
  • 39
-3

No need to change ownership of the folder that contains the php.ini file.

Aim: Grant permission to user 'ec2-user' so that FileZilla can write to /etc folder which contains the php.ini file.

Doing this we can rename the original php.ini file and replace the php.ini file with a modified copy.

Steps:

  1. Login to ec2 instance via 'Putty'
  2. Navigate to the folder that has the php.ini file example:

    cd ../

  3. Use:

    ls -l

    to list files nd folders with their permissions

  4. Look for the line that shows the folder that contains the php.ini file somthinng like this:

    drwxr-xr-x 80 root root 4096 Jul 11 08:15 etc

  5. Change permissions of this folder:

    sudo chmod 777 etc

    (NOTE:Change it back to the original permissions later)

  6. Use:

    ls -l

    to see the change

  7. Restart Apache:

    sudo service httpd restart

Now FileZilla will have permission to that folder, rename the origial php.ini file to revert back in future replace the php.ini file with a modifided copy

Check ur site(a page which has errors) after a minute, the errors will be displayed.

Ryan Augustine
  • 1,455
  • 17
  • 14