2

I've been working with a Google Cloud debian VM and had no problem at all doing super user tasks using sudo (sudo was not asking for password).

Today I connected via SSH as usual and when I try to sudo something it started asking for password:

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for -----:

According to the documentation it should not ask for password as is already SSL Key authenticated connection.

Esteban Panelli
  • 178
  • 2
  • 10

4 Answers4

6

Today I had the same problem with CentOS 8.x VM. After some testing I found a more simple solution. The group "google-sudoers" is allowed to sudo in /etc/sudoers.d/google_sudoers file, so, to fix the problem and make it permanent add your user to "google-sudoers" group with the next steps:

  1. SSH to your VM from GCP's web console
  2. Run sudo usermod -a -G google-sudoers USER to add your USER to google-sudoers group
  3. Close your current SSH session and open a new one
  4. Test that everything works ok

You should be able to run sudo commands or gain root again.

Angel Leon
  • 101
  • 2
  • 5
1

To avoid this, one solution is open the ssh terminal on the web browser from GCP console. You can give a try on this. This is because of SSH key related configuration on Google Clound Engine

Nizamudheen At
  • 334
  • 2
  • 9
0

I have solved this issue by myself. I post the steps i've followed for anyone who has a similar problem:

  1. Deleted the VM instance preserving the disk.
  2. Created new VM instance for recovering pruposes.
  3. Attached the old VM disk to the new instance
  4. Mounted into /mnt/

    # mount /dev/sdb1 /mnt/
    
  5. Change root to mounted partition

    # chroot /mnt/
    
  6. Now edit the sudoers file and the user password and group as needed
  7. Unmount the disk

    # umount /dev/sdb1
    
  8. deattach the disk, delete the recovery instance, and recreate the old VM with the same disk
Esteban Panelli
  • 178
  • 2
  • 10
  • I don't understand, I have the same problem, and I have created recovery instance like you describe, and mount the disk ... but what needs to be changed in sudoers file? Everything looks fine – Anders Emil Oct 18 '18 at 06:37
  • you should have a line like this in sudoers: your-username ALL=(ALL:ALL) NOPASSWD:ALL – Esteban Panelli Oct 18 '18 at 23:00
0

I encountered this problem right now, under the same circumstances you did (suddenly asking about the password) but I just logged out (closed the ssh session) and logged back in and it worked.

Cosmin Ioniță
  • 3,598
  • 4
  • 23
  • 48