ssh tunnel for postgreSQL - php

I have two servers. For example1.com and example2.com
At example1.com server I have my php code and example2.com there is a postgreSQL database.
Now I want to connect postgreSQL through a tunnel in example1.com
I tried the following command at example1.com server.
ssh -L 5433:localhost:5432 user#example2.com
Then it will prompt for password and I enter the password and login to ssh, then I am trying to connect to database localhost:5433 post but I am getting 'password authentication failed'.
How do I connect to example1.com through ssh?

You need to check the pg_hba.conf on your PostgreSQL server. It probably requires password authentication for TCP/IP connections coming from localhost. So you either need to change that, or set a password for your database user and enter that.

Related

MySQL database IP address from rackspace or google cloud?

Ok here’s the deal. I setup MySQL database on Rackspace and I’m trying to connect to it. I am using the tutorial google maps to create store locator using MySQL. The line of the code in the tutorial asks for the host name and I’m giving the IP address of my server on Rackspace. I’m using what I think is the correct one but it’s not working. Any ideas?
Here's the google tutorial code:
// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
};
My code:
$connection=mysqli_connect ('THE IP ADDRESS OF MY RACKSPACE SERVER', 'MY USERNAME', 'MY PASSWORD');
Here's a link to the tutorial from google: https://developers.google.com/maps/solutions/store-locator/clothing-store-locator
I know I have the server IP correct and my username/password correct since I'm able to login via SSH from terminal with those credentials.
When I use mysql> \s to show the status it says Connection: Localhost via UNIX socket - does this mean it's local host? I need it hosted on IP to connect right?
I expect that your MySQL server is by default by your Linux distribution's packaging configured to listen either locally, or on the socket file only. You can update your DB config to listen on the public IP address of your server however obviously this can come with some security implications.
To do this edit the /etc/mysql/mysqld.conf file (this may be in a slightly different location depending on distribution being used) and the following line as such...
From
#bind-address = 127.0.0.1
To
bind-address = 0.0.0.0
Now restart your MySQL service using the systemctl or service command.
service mysql restart
Your MySQL server is now listening on ALL the host's IP addresses. If you want to limit it to just one you should enter that IP instead of 0.0.0.0. You should now be able to connect to your MySQL server remotely, however, you must have already configured your database user to be able to login from the webserver. If you haven't configured the user yet do something like this.
mysql
CREATE USER '<username>'#'<webserver ip address here>' INDENTIFIED BY '<password>';
GRANT ALL PRIVILEGES ON <database>.* TO '<username>'#'<webserver ip address>';
FLUSH PRIVILEGES;
You should now be able to login as this user and view / modify / insert etc... data to the database specified from the server IP address specified. You can test this from the web server using the MySQL client like this...
mysql -u <username> -h <db server ip> -p

User authentication for connecting to robomongo

I have a mongoDB server using v2.4.9. I need to connect to that server using robomongo in my localhost.
I have enabled auth=true in /etc/mongobd.conf and I have added the username and password in mongodb.php. When I login using robomongo to the remote server, it is connecting already through IP even though I have not prescribed anything in Authentication tab in robomongo. I want robomongo not to connect only through IP, but through both IP and username and password.
How can I do this?
have you created the user with specifications of role and databaseName etc. in robomongo Refer to this link->
https://docs.mongodb.com/manual/reference/method/db.createUser/

Why is connecting to laravel forge database giving me tunnel errors in mysql workbench?

I am pretty sure this is a simple fix I think but I've been trying to setup a forge server and access the database.
My issue is when I add the credentials emailed to me by forge I get an ssh tunnel error.
My configuration settings are all there like IP,Hostname, passwords id_rsa.pub key but it will not connect at all.
Here is the email I got with the correct details from Forge:
Name: rs-staging
IP Address: ***.**.***.**
Username: forge
Sudo Password: ******************
Database Username: forge
Database Password: ******************
All details entered are correct but the error I get it this:
Could not connect the SSH Tunnel
Failed to Connect to MySQL at ***.*.*.*:3306 through SSH tunnel at ***.**.***.**:22 with user forge
Can anyone elaborate on why tunneling might not work via MySql Workbench?
Thanks!
Remote connections to forge servers require that you use the SSH option through MySQL Workbench when attempting to access a database.
In order to do so, Change the "Connection Method" to Standard TCP/IP over SSH.
Then provide the following information:
SSH Hostname: your_ip:your_ssh_port
SSH Username: forge
SSH Password: skip this, use the Key file in the next section:
SSH Key File: Locate your id_rsa.pub (or other key file) on your local machine. This is the same key file that you added to SSH Keys through Laravel Forge when you setup and provisioned the server.
Then fill out the rest of the information accordingly. This should allow you to tunnel in correctly with the proper SSH Key file and access the database remotely without modifying the mysql server settings to allow remote connections, or adding users who need a specific IP to tunnel in.

Connecting Local Host to online sql database

I have an online reservation booking system (php script) that uses a mySQL database. Part of the script is a back end admin panel for offline reservations.
Is it possible to run a service like XAMPP using local host to access the remote database.
You can connect to remote database by having remote host, db username, db password.
Host name = (use the db server IP address)
Database name = (cpanelUsername_databaseName)
Database username = (cpanelUsername_databaseUsername)
Database password = (*)
MySQL Connection Port = 3306 (check your)
If you are using cPanel then you need to allow your local IP for DB access first.
Login to cpanel, on the main menu of CPanel,
Jump down to "Databases" and select "Remote MySQL"
Now add your IP address, or IP range with a wildcard such as 12.34.%
Good Luck
Yes. You need login credentials for the remote database as well as it's port and server address (hostname or IP), as you'd expect. The remote host also needs to have permissions granted for that particular user to access the database remotely, which users will not have by default.
Yes it is. Just the way you connect your local database, you can connect to a remote database with valid credentials. Then only thing changes is the hostname parameter.
for an example if your database is hosted on dreamhost, they have hostnames like..mysql.yourdomain.com. Create a database on your remote server and connect to it as
<?php
mysql_connect('mysql.yourdomain.com','username','password');

Mysql - connect to remote server using IP address

I am using PHP and MySQL to make a database connection, the only change is that I am trying to access my remote server from my local computer using my server IP address.
mysql_connect("x.xx.xx.x","username","password") or die(mysql_error());
and the error I am getting is Unable to connect to the given host. The user has all privileges and rights.
Most default installs of MySQL only listen to the local machine.
Look for the bind-address setting in my.cnf on the server, and make sure it's listening on the IP address you're targetting. You may also need to ensure skip-networking isn't switched on!
Alternatively (and less securely!) the following will set it up to listen on all addresses - local and remote:
bind-address = 0.0.0.0
Before you try using PHP todo this. Open up your terminal or console and type the following:
$ mysql -u username -h x.xx.xx.x -p
then enter your password
Or on windows then type:
\path\to\mysql.exe -u username -h x.xx.xx.x -p
then enter your password
This will give you a more detailed response as to the authentication issue that's coming up. And you can be 100% sure that your remote login from your IP address works. If it works fine then its something in your PHP code that you're missing.
Try to add a user (USER-NAME) allowed to connect from the IP:
mysql> GRANT ALL PRIVILEGES ON *.* TO USER-NAME#IP IDENTIFIED BY "PASSWORD";
USER-NAME is the username that you would like to create (like 'widor')
IP is the public IP address of your remote connection (like '195.x.y.z')
Of course, limit the privileges you want to grant (ALL PRIVILEGES is probably not your choice)
1) Check which interface MySQL listen for connections, local (localhost, 127.0.0.1) or remote (0.0.0.0 or IP address). It's in my.cnf. http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html
2) Check does your user have corresponding privileges. User that logs in from localhost can have different priveleges from remote one. For example 'user'#'localhost' and 'user'#'%'

Categories