0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

踏み台サーバーを経由してAWS検証環境に接続する

0
Posted at

踏み台サーバーについて

踏み台サーバーとは、社内システムやプライベートネットワーク内のサーバーに対し、外部ネットワークからのアクセスを中継する目的で設置されるサーバーのことです。

手順

1. SSHキーの準備

# .sshディレクトリが存在しない場合は作成
mkdir -p ~/.ssh

# 秘密鍵を格納する
# WindowsのSSHキーをWSLにコピー
cp /mnt/c/Users/〇〇/.ssh/test-dev.pem ~/.ssh/test-dev.pem

# 確認
ls -l ~/.ssh/test-dev.pem

2. SSHトンネルの作成

検証環境への接続例:

# 基本文
ssh -i ~/path/to/your/ssh-key.pem user@bastion-host

ssh -i ~/.ssh/test-dev.pem \
    -L 3307:test-db.×××××××××.ap-northeast-1.rds.amazonaws.com:3306 \
    ec2-user@××.×××.××.××

パラメータ説明:

  • -i ~/.ssh/test-dev.pem: SSH秘密鍵のパス
  • -L 3307:test-db.×××××××××.ap-northeast-1.rds.amazonaws.com:3306: ローカルポート3307を踏み台経由でRDS:3306に転送
  • ec2-user@××.×××.××.××: 踏み台サーバーのユーザー名とIPアドレス

トラブルシューティング

エラー: "Address already in use"

ローカルポート(3307)が既に使用されています。別のポート番号を使用してください。

# 使用中のポートを確認
ss -tuln | grep 3307

# 別のポートを使用(例:3308)
ssh -i ~/.ssh/test-dev.pem \
    -L 3308:test-db.×××××××××.ap-northeast-1.rds.amazonaws.com:3306 \
    ec2-user@××.×××.××.××

エラー: "Connection refused"

  • 踏み台サーバーからRDSへの接続が許可されているか確認
  • 秘密鍵が間違っていないか確認

エラー: "Permission denied"

SSHキーのパーミッションを確認:

chmod 600 ~/.ssh/test-dev.pem

エラー: "Name or service not known"

.envファイルのTEST_DB_HOSTmysqlなどの解決できないホスト名になっていないか確認:

# 間違い
TEST_DB_HOST=mysql

# 正しい(SSHトンネル経由の場合)
TEST_DB_HOST=127.0.0.1

参考記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?