Caveat: the question suggests you're using a personal server. If not, and you aren't the main admin, do NOT assume root user's shell unless so instructed by the main admin
sudoers: 'wheel group' settings
%wheel ALL=(ALL) NOPASSWD: ALL
So your user123 user is in the 'wheel group' and your sudoers file grants unfettered access across ALL
domains as (ALL)
users with no password required for ALL
commands, to members of the wheel group.
We know you have a working login so your options aren't limited. Knowing the password for postgres or even root, isn't required. You can simply:
$ sudo -iu postgres
su, sudo, sudoers confusion
- su = substitute user
- sudo = exec command as another user
The reason you can't 'substitute user' with su
or su -
as shown in the question is because the sudoers file has no effect on the su
command.
The su
command without arguments or just the dash defaults to root, so you get prompted for the root user password. This is expected behaviour: As the name sudoers implies, the sudoers file grants privilege to the sudo
command only.
root shell, lost password
As it appears you've forgotten the root password. You can get the root shell using:
$ sudo -i
Leaving you back in control at: [root@local ~]#
sudo
but you are actually usingsu
. Different commands.sudoers
file and thesu
command.