Solved sudo -u

Here's an example where you have to run a command with another user:

su -l postgres -c "/usr/local/bin/initdb --encoding=utf-8 --lc-collate=C -D /var/db/postgres/data11 "
su -l postgres -c "pg_upgrade -b /tmp/pg-upgrade/usr/local/bin/ -d /var/db/postgres/data10/ -B /usr/local/bin/ -D /var/db/postgres/data11/ "
su -l postgres -c "/var/db/postgres/analyze_new_cluster.sh"
 
Option 1: When in Rome, do like the Romans. The default too for changing to another user in *BSD is su, not sudo. VladiBG showed one way to do it.

Option 2: Install the sudo package, and use it.

Option 3: Sudo is difficult to configure, the configuration language/file is baroque, and because of that it is often a security hole (not that it is inherently broken, only that it is easy to mis-use). Consider using doas instead of sudo, as it is much simpler.
 
Here's an example where you have to run a command with another user:
It's good idea and I testet with
su -l p2p -c "touch /tmp/ssss"
then ls -l /tmp/ssss is:

# ls -l /tmp/ssss
-rw-r--r-- 1 p2p wheel 0 Feb 23 15:49 /tmp/ssss

Why wheel? I have p2p group.
 
Back
Top