ssh config file for proxy jump
When using ssh, you may need to remember lots of things such as host names, the sequence of servers to log into if you use proxy. However, you may use ssh config file to make life easy.
Here is an example. The file should be put in .ssh folder and named config
Host middle-server
StrictHostKeyChecking ask
HostName 123.35.678.12
User frank
Host target-server-name
ProxyJump middle-server
StrictHostKeyChecking ask
HostName 99.88.77.32
After create this config file, you can connect to target server by typing
ssh target-server-name
//also can use pem file
ssh -i NOC.pem ec2-user@target-server-name
Here is another example. It uses public and private key to log into jumpbox
host mm-jumpbox
HostName 123.213.58.123
User ec2-user
IdentityFile /Users/mark/.ssh/id_rsa
Host target-server-name
ProxyJump mm-jumpbox
StrictHostKeyChecking ask
HostName 10.123.44.44
Also can use pem file to log into jumpbox
Host mm-jumpbox
HostName 55.22.33.44
User ec2-user
IdentityFile ~/.ssh/NOC.pem
//then
ssh mm-jumpbox
ssh config for port forward
Assume that jump box can connect to MySql server. However, your local can not connect to MySql server directly, but you can connect to jump box. You want to connect to MySql server from local. In this case, we can use port forward to solve the problem.
Here is config file:
# assume your jump box has ip 55.22.33.44
# assume MySql server has ip 10.10.44.43
Host mm-jumpbox
HostName 55.22.33.44
User ec2-user
IdentityFile ~/.ssh/NOC.pem
LocalForward 3308 10.10.44.43:3306
After you put the config into .ssh, you can
#step one
ssh mm-jumpbox
#step two, in another terminal. here 3308 match 3308 in config.
#Therefore called port forward
mysql -h 127.0.0.1 -P 3308 -u mysql-user-name --password='abdbbdbbd'
debug
#verbose mode.
ssh -v mm-jumpbox
Check if a EC2 instance can be used for jumpbox to do port forward to AWS RDS database.
The command uses netcat (nc) to check whether a TCP port is reachable.
- ssh into that EC2 instance
nc -zv moresby-sandbox.c21234567rxeh.us-west-1.rds.amazonaws.com 3306- check result
#result: can connect because we see:Connected to 10.12.210.311:3306 Ncat: Version 7.93 ( https://nmap.org/ncat ) Ncat: Connected to 10.12.210.311:3306. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds
No comments:
Post a Comment