🔑

【備忘】ローカルPCからAWSのインスタンスにSSH鍵を配布する手順

に公開

はじめに

タイトルの通りです。AWSのインスタンスにローカルPCからSSH鍵を配布する手順を記載します。
※本記事は以下の記事の一部を抜粋、改稿して個人的な備忘として残すために投稿しています。
https://zenn.dev/yu_shi/articles/5a97909a011f35

使用端末

  • Macbook Air M1,2020
  • チップ Apple M1
  • メモリ 8GB
  • OS macOS Sonoma バージョン14.6.1

実施手順

1.SSHターミナル上から踏み台インスタンスに.pemファイルを配布します。
配布にはscpコマンドを使用します。

 % scp -i test.pem test.pem ec2-user@xx.xx.xx.xx:/home/ec2-user/

The authenticity of host 'xx.xx.xx.xx (xx.xx.xx.xx)' can't be established.
ED25519 key fingerprint is SHA256:BprX0CJQvzUe8cEWlqONCPqXAjG2vqarbgRDF4pwRrw.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:13: ec2-xx-xx-xx-xx.ap-northeast-1.compute.amazonaws.com
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'xx.xx.xx.xx' (ED25519) to the list of known hosts.
test.pem

2.配布されていることを踏み台サーバーにSSHで接続し確認します。

$ ls -l
total 4
-r--------. 1 ec2-user ec2-user 1678 Dec 27 05:28 test.pem

以上

Discussion