내 port와 DB 등 외부 서비스의 port 를 연결
sshpass 설치
sudo apt-get install sshpass
ssh 명령어 환경변수 추가
~/.bashrc 또는 ~/.zshrc 파일에 환경 변수 추가
alias sshpg='sshpass -p '\''[password]'\'' ssh -o StrictHostKeyChecking=no -L [localport]:[remote host name]:[remoteport] root(계정)@[ssh 터널 호스트 주소]'
bashrc 적용
source ~/.bashrc
설정한 명령어로 실행
sshpg
ssh -i dpgtb.pem -L 5432:10.0.10.8:5432 ubuntu@10.0.1.36
[localport]:[DB IP(bastion에서 접속하는)]:[remoteport][bastion 계정]@[bastion 터널 ip]'
# - Connection Settings -
listen_addresses = '*'host all all 10.0.1.36/32 scram-sha-256 Address 부분에 bastion 주소를 넣어줬음 -> 변경파일 위치는 내 경우에 /data/postgres/data/ 였다 (다를 수 있음)
sudo systemctl list-units --type=service | grep postgresql
sudo systemctl restart postgresql-13.service
list 를 검색하고 그 결과를 restart 뒤에 그대로 넣어야 함
telnet localhost 5432
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
요렇게 뜨면 잘 연결된거임