6

I am fairly new to Linux and I have question regarding users. When I use the useradd command I don't specify a password. I must use the passwd command afterwards. Does this mean that the user is disabled until it is done?

I installed Postgresql with the apt-get command. Do I have to create a postgres-user and change ownership of the installed postgresql files? Or is this taken care of by the apt-get?

I see that the owner of some of the files is already postgres. However, how do I run the server as postgres? I don't know the password. Trying to do su postgres fails because of authentication failure.

  • @chirp Entries in /etc/passwd, /etc/shadow etc. are separated by :. The second entry contains the password hash, so if it is something like !, NP, * or anything else that isn't a valid result of the hash function used by your system, you will not be able to login with any password, since no input on your part can result in a hash like !. – n.st Dec 1 '13 at 18:39
  • @n.st just when I wanted to correct my typo… deleted my comment… what n.st said is correct. Sorry for messing this up… – erch Dec 1 '13 at 18:48
3

When I use the useradd command I don't specify a password. [...] Does this mean that the user is disabled until it is done?

Yes, if you don't specify a password hash using useradd's option -p, password-based login to the newly created account will be locked until you set a password using passwd.

I installed Postgresql with the apt-get command. Do I have to create a postgres-user and change ownership of the installed postgresql files? Or is this taken care of by the apt-get?

The .deb packages apt-get downloads and allows you to install usually come with a script that takes care of all settings required by the program you are installing.

Trying to do su postgres fails because of authentication failure.

As Stefan already pointed out, run su postgres as root, e.g. by running sudo su postgres and entering your password.

3

I installed Postgresql with the apt-get command. Do I have to create a postgres-user and change ownership of the installed postgresql files?

No, you don't need to create postgre-user, postgresql package will automatically create the users that require.

You can check using : getent passwd postgres or just grep in /etc/passwd file


I see that the owner of some of the files is already postgres. However, how do I run the server as postgres? I don't know the password. Trying to do su postgres fails because of authentication failure.

  • You don't need to set password for system account
  • if postgres user already exists before installing package then useradd command will take care of that ( it will change uid below 500 for making it system user see man 5 adduser.conf for more info ).
  • in Debian based system the start-stop-daemon utility, which handles pid-files, changing the user, putting the daemon into background and much more, So postgresql will start by postgres user which is define in init scirpt or postgres cluster binary itself.

in RHEL based system you will see below line for starting postgresql with postgres user :

su -l postgres -c '/usr/local/pgsql/bin/pg_ctl start -s -l /var/postgresql/log -D /usr/local/pgsql/data'

1
stefan@laptop ~  $ su -
Password: 
laptop ~ # useradd example
laptop ~ # su example
example@laptop /root $ exit
laptop ~ # logout
stefan@laptop ~  $ su example
Password: 

The user can only be logged in as root without a password.

To log in as the postgre user try to su as root (if you have root).

So try a:

sudo su postgres

and that should work.

  • 1
    Or use sudo -i. Also they are not logged in as root, rather you're setting user (su) to this other user. You can mimic logging in as this user using su - example too. Using su example doesn't read all of their shell's configuration files from /home/example. – slm Dec 1 '13 at 18:13
  • Okey. So to be postgres I must have root access? – LuckyLuke Dec 1 '13 at 18:16
  • You need the ability to either become root, or sudo su - postreges. Admins generally don't like to give out root's password, sudo allows users to elevate their credentials w/o having to know root's password. – slm Dec 1 '13 at 19:00

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.