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'
No comments:
Post a Comment