User permissions for creating PostgreSQL DB
It appears you have a database user named kuser
, but there is no system user with that name. This is why you're able to get a postgres prompt, but sudo fails.
That user isn't able to create a database because the account doesn't have the createdb
permission.
You can either grant that permission to the user using the postgres
account (the default management account on Ubuntu):
sudo -u postgres psql -c 'alter user kuser with createdb' postgres
Or just use that management account to create the database and specify that it is owned by the kuser
account:
sudo -u postgres createdb -O kuser kdb
If that user isn't going to be creating other databases I'd advise using the latter option, better to limit the privileges that are granted to the account.