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?

ローカル環境からEC2インスタンスへの接続

Last updated at Posted at 2025-05-14

環境

  • AWS CLIインストール済み
  • ローカルPC:Ubuntu 24.04(WSL2環境)
  • 接続先:EC2
    • OS: Amazon Linux 2023
    • セキュリティグループにSSH(ポート22、アクセス元:自分のIP)許可済み

ローカル環境でキーペアの権限変更

  1. 作成したキーペアsample-ec2をUbuntuのホームディレクトリにある.sshディレクトリに移動させます
  2. .sshディレクトリに移動し、作成したキーペアのsample-ec2の権限を400に変更します
    cd .ssh
    chmod 400 sample-ec2.pem
    
  3. 権限を変更できたか確認します
    ls -la
    
    -r--------と表示されましたら、成功です

ローカルからEC2インスタンスへ接続

  1. EC2のインスタンスの中からsample-ec2をクリック
  2. 右上の接続ボタンをクリックすると、SSHクライアントが表示されます
  3. 一番下のコマンドをコピー(例:ssh -i "sample-ec2.pem" ec2-user@〇.〇.〇.〇)
  4. WSL2で以下を入力
# ホームディレクトリの.sshに移動
cd .ssh
# EC2インスタンスへSSHで接続
ssh -i "sample-ec2.pem" ec2-user@〇.〇.〇.〇

# yesと返答
Are you sure you want to continue connecting (yes/no/[fingerprint])?  yes

dnfを最新の状態へアップデート

$ sudo dnf update -y
Last metadata expiration check: 9:57:17 ago on Sun May  4 00:30:59 2025.
Dependencies resolved.
Nothing to do.
Complete!

まとめ

ローカルPCのWSL2上でキーペアの権限を適切に設定し、EC2インスタンスへSSH接続を成功させました。接続後は、EC2上のパッケージ管理ツールdnfを最新状態にアップデート済みです。

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?