Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get password for sudo

I'm trying to use the command sudo -i -u postgres for PostgreSQL, and the Google Compute Engine VM is asking me for my password for my account (not root).

As I never issued a password, and I always login to my server via SSH key, I'm not sure what the password is, how I can reset it, or where it can be found.

Please tell me where I can get my password?

like image 401
Allen Avatar asked Feb 09 '15 02:02

Allen


People also ask

How do I find my sudo password?

There is no default password for sudo . The password that is being asked, is the same password that you set when you installed Ubuntu - the one you use to login. Save this answer. Save this answer.

What is sudo root password?

So sudo passwd root tells the system to change the root password, and to do it as though you were root. The root user is allowed to change the root user's password, so the password changes.


2 Answers

To become another non-root user on a GCE VM, first become root via password-less sudo (since that's how sudo is configured on GCE VM images):

sudo su -

and then switch to the user you want to become or run a command as another use, e.g., in your case, that's:

sudo -i -u postgres
like image 117
Misha Brukman Avatar answered Oct 13 '22 16:10

Misha Brukman


Per https://cloud.google.com/compute/docs/instances ,

The instance creator and any users that were added using the metadata sshKeys value are automatically administrators to the account, with the ability to run sudo without requiring a password.

So you don't need that non-existent password -- you need to be "added using the metadata sshKeys value"! The canonic way to do that, and I quote from that same page:

$ echo user1:$(cat ~/.ssh/key1.pub) > /tmp/a
$ echo user2:$(cat ~/.ssh/key2.pub) >> /tmp/a
$ gcloud compute project-info add-metadata --metadata-from-file sshKeys=/tmp/a

or you can use the Google Developers Console for similar purposes, see https://cloud.google.com/compute/docs/console#sshkeys if you'd prefer that.

like image 45
Alex Martelli Avatar answered Oct 13 '22 17:10

Alex Martelli