Context:
1 local PC
2 Remote PC IP:192.168.0.51
3 My SSH user name on remote PC is edwin
1 build a tunnel By ssh:
I will open a local TCP port 3333 for tunnelling mysql; The syntax of SSH is
ssh -L LOCAL_PORT:hostname:REMOTE_PORT USER_NAME@SERVER_NAME or IP_ADDRESS.
or with sshpass
sshpass -p 'YOUR_PASSWD' ssh -o StrictHostKeyChecking=no -L 3333:localhost:3306 USERNAME@REMORT_HOST -p 22
We're using localhost as the hostname because we are directly accessing the remote mysql server through ssh. You could also use this technique to port-forward through one ssh server to another server.
#ssh -L 3333:localhost:3306 edwin@192.168.0.51
2 Connect reomote mysql using mysql command
#mysql -u root -p -h 127.0.0.1 -P 3333
No comments:
Post a Comment