Skip to content

Instantly share code, notes, and snippets.

@ginokent
Last active December 4, 2018 05:53
Show Gist options
  • Save ginokent/0b256b5a19e86b32a4f1aff314fae29f to your computer and use it in GitHub Desktop.
Save ginokent/0b256b5a19e86b32a4f1aff314fae29f to your computer and use it in GitHub Desktop.
踏み台サーバとアプリケーションサーバを経由してMySQLサーバのポートをlocalhostにフォワーディング

踏み台サーバとアプリケーションサーバを経由してMySQLサーバのポートをlocalhostにフォワーディング(バックグラウンド実行)

ssh -fN -i ~/.ssh/id_rsa -o "ProxyCommand ssh -p ${BASTION_PORT} ${BASTION_USER}@${BASTION_HOST} -W %h:%p" -L 127.0.0.1:3306:${MYSQL_HOST}:3306 ${APP_USER}@${APP_HOST}

MySQLに接続

mysql -h127.0.0.1

フォワード停止時は、当該プロセスをkill

# 確認
ps -e -o pid,command | grep [s]sh.*-fN.*-L

# kill
kill -SIGTERM ${当該プロセス}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment