STARTING METASPLOIT FRAMEWORK IN KALI LINUX
1. STARTING SERVICES & INITIALISING DATABASE
In keeping with the Kali Linux Network Services Policy, no network services, including database services, run on boot as a default, so there are a couple of steps that need to be taken in order to get Metasploit up and running with database support.
Kali Linux - Misc commands
Kali Linux - Generating Payloads & Shellcodes
Metasploit - Initial Setup
Metasploit - Basic Network Enumeration
Postgresql
Metasploit uses PostgreSQL as its database so it needs to be launched first. Starting postgresql on kali linux.

You can verify that PostgreSQL is running by checking the output of ss -ant and making sure that port 5432 is listening.
# ss -ant
​
With PostgreSQL up and running, we next need to create and initialize the msf database.
# msfdb init
​
Now that the PostgreSQL service is up and running and the database is initialized, you can launch msfconsole and verify database connectivity with the db_status command as shown below.

Note: If you get the following: [*] postgresql selected, no connection
Then carry out this
# locate database.yml [ usually located at '/opt/metasploit/config/database.yml' ]
# cat database.yml [ copy the password ]
# msfconsole
​
Assuming that you have default username & database named msf
msf > db_connect msf:password@127.0.0.1:5432/msf
msf > db_status
[*] postgresql connected to msf
​
2. CREATING WORKSPACE
The Metasploit database is great for tracking a Penetration Testing engagement, the biggest the engagement the more that the database can offer you. It tracks live hosts, pwned boxes and stolen loot – plus it timestamps actions too just in case you need to track what happened when. Before you get knee deep in the metasploit database you’ll need to get everything set up. If you’re using Kali then things should work out of the box only thing that is required creating is the workspace.
Creating Workspace
msf > workspace
msf > workspace -a new-name-of-workspace

Deleting Workspace
msf > workspace -d name-of-workspace-to-delete
​
​
Switching between Workspace
msf > workspace name-of-workspace