Forked from kshailen/Connecting_postgress_RDS_from_local_via_bastion.md
Created
July 23, 2021 01:05
-
-
Save simo97/5e1b6e1bdb2f7e5358aeca75a456e7c5 to your computer and use it in GitHub Desktop.
Revisions
-
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,6 +62,7 @@ Home screen will as below Click on server and the click on add servers:  You should put ```localhost``` in ```hostname/address``` ```local port(8886)``` in ```port``` and put username and password accordingly. After this click on save. -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,6 +60,7 @@ Home screen will as below  Click on server and the click on add servers:  You should put ```localhost``` in ```hostname/address``` ```local port(8886)``` in ```port``` and put username and password accordingly. After this click on save. -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,3 +59,9 @@ Steps are as follows: Home screen will as below  Click on server and the click on add servers:  You should put ```localhost``` in ```hostname/address``` ```local port(8886)``` in ```port``` and put username and password accordingly. After this click on save. -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,3 +57,5 @@ Steps are as follows: 2. Make connection: Make sure while making connection you should use loaclhost as server address and port on which tunnel was made(in this case 8886) Home screen will as below  -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ How can you easily access and manage your secured data?  There are two basic ways to acees it. 1. Access postgres RDS from bastion host. There are following requirements for this. * postgre RDS instance should open 5432 for ingress from bastion/jump server * pgsql client should be installed on bastion host @@ -17,7 +17,7 @@ There are following requirements for this. ``` To install pgsql client you should following this page [Install PostgreSQL Client](https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/) 2. You can also access postgress sql from your local (Mac). For this you should create tunnel from you local to rds instance via bastion host. ``` Suppose: @@ -53,7 +53,7 @@ $psql -h localhost -p 8886 -U <username> Using pgAdmin: Steps are as follows: 1. Open pgAdmin 2. Make connection: Make sure while making connection you should use loaclhost as server address and port on which tunnel was made(in this case 8886) Home screen will as below -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,6 +53,7 @@ $psql -h localhost -p 8886 -U <username> Using pgAdmin: Steps are as follows: 1 Open pgAdmin 2 Make connection: Make sure while making connection you should use loaclhost as server address and port on which tunnel was made(in this case 8886) Home screen will as below -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,4 +56,3 @@ Steps are as follows: 1.Open pgAdmin 2. Make connection: Make sure while making connection you should use loaclhost as server address and port on which tunnel was made(in this case 8886) Home screen will as below -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,8 +35,6 @@ NL — N will not open a session with the server. It will set up the tunnel. How to check if tunnel is established or not. ```bash netstat -ntaP tcp | grep -i LISTEN | grep portnumber ``` It will give output like below. ``` @@ -45,3 +43,17 @@ tcp4 0 0 127.0.0.1.8886 *.* LISTEN tcp6 0 0 ::1.8886 *.* LISTEN 0 0 ``` Once tunnel is eatablished, You can either use pgsql command line client or you can [download pgAdmin](https://www.pgadmin.org/download/). Using pgsql command line client on mac: ```bash $psql -h localhost -p 8886 -U <username> ``` Using pgAdmin: Steps are as follows: 1.Open pgAdmin 2. Make connection: Make sure while making connection you should use loaclhost as server address and port on which tunnel was made(in this case 8886) Home screen will as below  -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,4 +30,18 @@ ssh -i "bastion_key.pem" -NL 8886:postgress.cpypigm0kth7.us-east-1.rds.amazonaws ``` Here 8886 is port for you loacl host. 5432 is port of postgress on rds. NL — N will not open a session with the server. It will set up the tunnel. L will set up the port forwarding. -v : Is optional. With this you will print the ssh log on your terminal. How to check if tunnel is established or not. ```bash netstat -ntaP tcp | grep -i LISTEN | grep portnumber or alternatively you can try telnet telnet localhost portnumber ``` It will give output like below. ``` shailendras-mbp:~ shaikuma$ netstat -ntaP tcp | grep -i LISTEN | grep 8886 tcp4 0 0 127.0.0.1.8886 *.* LISTEN 0 0 tcp6 0 0 ::1.8886 *.* LISTEN 0 0 ``` -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,5 +26,8 @@ There are following requirements for this. ``` Command to make tunnel: ```bash ssh -i "bastion_key.pem" -NL 8886:postgress.cpypigm0kth7.us-east-1.rds.amazonaws.com:5432 [email protected] -v ``` Here 8886 is port for you loacl host. 5432 is port of postgress on rds. NL — N will not open a session with the server. It will set up the tunnel. L will set up the port forwarding. -v : Is optional. With this you will print the ssh log on your terminal. -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,3 +16,15 @@ There are following requirements for this. $psql -h <host> -p <port> -U <username> -W <password> ``` To install pgsql client you should following this page [Install PostgreSQL Client](https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/) 2. You can also access postgress sql from your local (Mac). For this you should create tunnel from you local to rds instance via bastion host. ``` Suppose: Bastion host IP is 132.5.10.11 and user is ec2-user and key_name is bastion_key.pem Your postgress RDS instance fqdn is postgress.cpypigm0kth7.us-east-1.rds.amazonaws.com ``` Command to make tunnel: ```bash ssh -i "bastion_key.pem" -NL 4444:postgress.cpypigm0kth7.us-east-1.rds.amazonaws.com:5432 [email protected] -v ``` -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,9 @@ How can you easily access and manage your secured data? There are two basic ways to acees it. 1. Access postgres RDS from bastion host. There are following requirements for this. * postgre RDS instance should open 5432 for ingress from bastion/jump server * pgsql client should be installed on bastion host Run following command to connect: ```bash $psql -h <host> -p <port> -U <username> -W <password> -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,8 @@ How can you easily access and manage your secured data? There are two basic ways to acees it. 1. Access postgres RDS from bastion host. There are following requirements for this. ```* postgre RDS instance should open 5432 for ingress from bastion/jump server ```* pgsql client should be installed on bastion host Run following command to connect: ```bash $psql -h <host> -p <port> -U <username> -W <password> -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,8 +8,8 @@ How can you easily access and manage your secured data? There are two basic ways to acees it. 1. Access postgres RDS from bastion host. There are following requirements for this. *. postgre RDS instance should open 5432 for ingress from bastion/jump server *. pgsql client should be installed on bastion host Run following command to connect: ```bash $psql -h <host> -p <port> -U <username> -W <password> -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 15 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,17 @@ When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management. How can you easily access and manage your secured data?  There are two basic ways to acees it. 1. Access postgres RDS from bastion host. There are following requirements for this. a). postgre RDS instance should open 5432 for ingress from bastion/jump server b). pgsql client should be installed on bastion host Run following command to connect: ```bash $psql -h <host> -p <port> -U <username> -W <password> ``` To install pgsql client you should following this page [Install PostgreSQL Client](https://www.compose.com/articles/postgresql-tips-installing-the-postgresql-client/) -
kshailen revised this gist
Jul 16, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,4 @@ When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management. How can you easily access and manage your secured data? This question came up several time from my colleagues, so let’s write down the process step by step, for future use.  -
kshailen created this gist
Jul 16, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ When it comes to databases and AWS VPC, best practice is to place your database in private subnet. By definition, private subnet in AWS is not reachable from the Internet because no Internet gateway is attached to private subnet. This is the way you protect your data. This kind of configuration is good for security but bad for data management. How can you easily access and manage your secured data? This question came up several time from my colleagues, so let’s write down the process step by step, for future use.