3

I'm running an Ubuntu 12.04 LTS partition and I've recently have had issues logging in.

From the GUI login screen, when I enter my username and password, it takes me right back to the login screen. This is different from when I enter my username and password incorrectly.

So I entered alt+ctrl+F1 to access the terminal and I signed in. It then reads:

-bash: /etc/profile Permission denied

From what I've tested, the only commands that I can run from terminal are basic terminal commands like ls and pwd. I tried changing my access to /etc:

sudo chmod 755 /etc

I get the errors:

sudo: unable to open /etc/sudoers: Permission denied

sudo: no valid sudoers sources found, quitting

sudo: unable to initialize policy plugin

If I run it without sudo I get a permission denied. If someone knows how to get around this issue that would be great

Alvar
  • 17,058
Anu Vedantham
  • 31
  • 1
  • 1
  • 2
  • do you have root password? – kamil Mar 03 '14 at 17:58
  • Please don't use quote to highlight code samples. Use the code tag instead. Thanks – Alvar Mar 03 '14 at 18:15
  • @Anu what's the output of ls -l /etc/profile and ls -l /etc/sudoers ? – rusty Mar 03 '14 at 18:19
  • Are you sure you did the command there and not sudo chmod -R 755...? In that case it will be more or less impossible to recover... because /etc is 755 in my machine, so nothing should have happened. See for example http://unix.stackexchange.com/questions/61997/recovering-from-chmod-r-777-in-ubuntu (there is a question specific here, but the search box is unable to help me... found: http://askubuntu.com/questions/43621/what-if-i-accidently-run-command-chmod) – Rmano Mar 03 '14 at 19:18
  • @rusty my permissions to etc is drw-rw---- and I get permission denied when I try to run the two commands you mentioned – Anu Vedantham Mar 20 '14 at 00:56
  • @Rmano I don't think it ever tries to run the command because the errors I get when I try to use sudo – Anu Vedantham Mar 20 '14 at 04:44

3 Answers3

3

Setting permission to /etc:

Since the permission of your /etc directory is drw-rw----, you will not be able to drop down to root privilege to set the right permissions. So you'll have to get a Live Ubuntu media with which you can boot and correct the problems.

  1. Boot to a live session, open a terminal and mount the target root partition:

    sudo -i
    mount /dev/sdXY /mnt
    

    (replace sdXY with that of target device, the device for /; assuming you don't have a separate partition for /etc.)

  2. Make permission changes:

    chmod 755 /mnt/etc
    

    (assuming the permissions for the contents in /etc is okay.)

    reboot
    

P.S. I tried to replicate this by running sudo chmod 644 /etc and was able to recover with the steps stated above. However, I encountered additional issues with Unity plugins. The following AU Q&A helped to solve some:

rusty
  • 16,327
  • My permissions in root for /etc/profile is -rw-r--r-- and for /etc/sudoers is -r--r-----. However when I log in normally, drw-rw---- are the permissions I have to /etc/ – Anu Vedantham Mar 20 '14 at 04:40
  • 1
    drw-rw---- for /etc is not right, it should be drwxr-xr-x and owned by root user and group.. The execute permission for any directory is important to allow the authorized to access the directory and its contents. So, changing the permission with sudo chmod 755 /etc (assuming the permission of its contents are good) should do the job for you. You'd have to use a live Ubuntu media for this.. – rusty Mar 20 '14 at 06:50
0

If you have a root password, you can use su to become root and then fix the permissions of the files. They should be as follows:

-rw-r--r-- 1 root root 665 Feb 20 03:43 /etc/profile

and

-r--r----- 1 root root 745 Feb 10 20:16 /etc/sudoers

After setting the permissions, you should reboot.

Donarsson
  • 2,709
  • 21
  • 31
0

I think you have messed with /etc/sudoers or some other sensitive file and been locked out of sudo.

But you can use pkexec command to fix it.

See here and here for more deatil about file permission and /etc/sudoers.

g_p
  • 18,504