7

I am using Cloud9 for Rails development and it uses an Ubuntu environment. In the documentation about using the PostgreSQL database, it says:

Connect to the service:

$ sudo sudo -u postgres psql 

What is the meaning of typing sudo twice?

https://docs.c9.io/setting_up_postgresql.html

  • 1
    Possibly the user is allowed to run the sudo command as root, but not the psql command as postgres. – Stéphane Chazelas Jan 23 '15 at 16:41
  • @WarrenYoung Looking at the document it seems intentional that the user can get to root without a fight. The original user is probably considered an administrative account and so it was probably given user ALL=(ALL) NOPASSWD: ALL – Bratchley Jan 23 '15 at 16:57
  • Of course, not prompting for the root password for an account that has ssh rights is probably a concern. – Bratchley Jan 23 '15 at 16:58
  • I opened an issue (and made a hash of the pull request). Let's see if they fix it. – muru Jan 23 '15 at 17:19
  • And it has been fixed. – muru Jan 27 '15 at 18:06
8

sudo -u postgres allows you to impersonate the postgres user when running the command. Your user probably doesn't have that privilege, but root's does.

So the first sudo gives you root's privileges and the second sudo allows you (as root) to sudo -u to postgres allowing the command to be run as the postgres user.

  • +1: This could well explain the second sudo. – Warren Young Jan 23 '15 at 17:42
0

They have probably have only given your account sudo rights to the root account and so they think they need it to sudo over to the postgres user in order to get there.

Considering how many people right their rules, you might run sudo -l as the regular user to see if they gave you to access to all users or locked you down to root for some reason. I'm willing to be it's the former in which case you can leave off the first sudo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.