Using metasploit with postgres from an unprivileged user

The msfdb init databse in the ~/.msf4/db directory, the default postgres config create a socket file in the /run/postgesql or /var/run/postgresql directory, an unprivilegied user does not have wtite to this location.

Solution 0:

Uncomment the line unix_socket_directories = '/tmp' in the configuration file template /usr/share/postgresql/postgresql.conf.sample and run msfdb init again

sudo sed -ei "s/^#unix_socket_directories.*/unix_socket_directories = '\/tmp'/g" /usr/share/postgresql/postgresql.conf.sample 
PGHOST="/tmp" msfdb init --component=database2

and create alias for the run msfconsole

alias msfstart='PGHOST="/tmp" msfdb start --component=database && msfconsole'
alias msfstop='msfdb stop'

After update PostgreSQL package, may have to be repeated.

Далее