I've a database with credentials which is my website's database.
Is there a way from my local machine to access this database using IP, User and Password?
Using Ubuntu 18.04, phppgadmin and PostgreSQL.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Warning: this method not recommended if you don't have a static IP address because you would need to open up your database to the world, which is disabled by default as a security measure, better use the method below.
If you want to ignore my warning:
listen_addresses = '*' #or listen_addresses = 'your-static-ip'
pg_hba.conf add this to allow remote connections from any IP:
host all all 0.0.0.0/0 md5 #or host all all your-static-ip/32 md5
If you can connect to the server with
ssh, there is a better/safer method:
Create a local port forwarding tunnel first:
ssh -L 5432:127.0.0.1:5432 your-server.com #or ssh -L 5432:localhost:5432 your-server.com
This will forward a local port via
ssh to a port on your server. Then you can connect to that port using
localhost as host.
The provider that hosts the website will have restricted access to the database to requests coming from the web server. All other requests are ignored. Otherwise, they would be under a constant attack from hackers wanting to break into the database.
So the only programs that can access the database are those that run on your web server. Usually that means PHP programs, like those that your website is built from. Credentials to access the database will be stored in a config file. Additionally, as a service, hosting companies usually provide PHPMyAdmin (in the case of MySQL) or PHPPGAdmin (for PostgreSQL). With the latter, you need to provide database credentials yourself.