大网数据广告活动
服务器运维问答

Can't go back to root from postgres: forces to enter postgres password which it finds invalid

· 52CE 我爱测

I've installed postgres on Ubuntu and it switched me to postgres user. I've opened psql created a database and then decided to switch back to root. However, it doesn't allow me: sudo su - results in it asking me [sudo] password f…

问题原文

原帖链接 · parsecer · CC BY-SA 4.0

I've installed postgres on Ubuntu and it switched me to postgres user. I've opened psql created a database and then decided to switch back to root. However, it doesn't allow me:

sudo su - 

results in it asking me

[sudo] password for postgres:

which I tried entering only to get

Sorry, try again

Then I decided to try to change postgres password using this answer:

ALTER USER postgres WITH PASSWORD 'postgres';

It seemingly worked, but after trying to switch to root again, it still doesn't let me.

已采纳解答

原帖链接 · A.B · CC BY-SA 4.0

It appears you are confusing two things:

  • postgres the system user
  • postgres the SQL database user

The only relation between both is that at PostgreSQL installation, the database user postgres is authenticated with the peer authentication method: the database server checks that the system user requesting access to the database as database user postgres is also called postgres. Also, the database server itself runs as the system user postgres.

It's not possible from the database to alter the system. Giving a password on the database account will not alter the fact that the system user postgres has no sudo rights, and most certainly a disabled password, thus allowing only root to use it by default (but not the reverse).

So, if you want to become root, you cannot do this from the postgres system account, and that's a good thing: should ever the database server (its processes also running as system user postgres) be compromised, there will be no way to escalate to root access from it.

Just login again to the account you used to install postgreSQL: either directly the root account (usually not done on Ubuntu) or (usually done on Ubuntu) the user configured at installation of the system, with uid 1000, which on Ubuntu is allowed by default to do sudo su -.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-01-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。